pyams_alchemy package ⊞

PyAMS SQLAlchemy integration

pyams_alchemy package is a small package which can be used to make SQLAlchemy integration more simple.

The main goal of pyams_alchemy package is to define the pyams_alchemy.engine.AlchemyEngineUtility class: this class can be stored persistently into PyAMS local site manager (see Site Manager guide) to store settings of an SQLAlchemy engine; on user request, the pyams_alchemy.engine.get_user_session() function can be used to get access to a new SQLAlchemy engine session matching these settings which will to be bound to current Pyramid’s transaction.

Dynamic schema names

Some times you may have to be able to setup, for a given table, a schema name which is not static but can be dynamic through a configuration option.

This can be done easily with the help of the pyams_alchemy.mixin.DynamicSchemaMixin which you can inherit from in any SQLAlchemy table subclass.

When this is done, the schema name can be defined into Pyramid’s configuration file into a setting which is called pyams_alchemy:{module_name}.{class_name}.schema; for example like in pyams_alchemy:pyams_content.package.TableName.schema. If not specified, the table’s schema name can be defined in a classic __schema__ table’s attribute.

pyams_alchemy.includeme(config)[source]

Pyramid include

pyams_alchemy.engine

pyams_alchemy.loader

pyams_alchemy.metaconfigure

pyams_alchemy.metadirectives

interface pyams_alchemy.metadirectives.IEngineDirective[source]

Define a new SQLAlchemy engine

name

Engine name

Empty if this engine is the default engine.

Implementation:zope.schema.TextLine
Read Only:False
Required:False
Default Value:‘’
Allowed Type:str
dsn

Database URL

RFC-1738 compliant URL for the database connection

Implementation:zope.schema.TextLine
Read Only:False
Required:True
Default Value:None
Allowed Type:str
echo

Echo SQL statements

Implementation:zope.schema.Bool
Read Only:False
Required:False
Default Value:False
Allowed Type:bool
use_pool

Use connections pool?

If ‘no’, collections pooling will be disabled

Implementation:zope.schema.Bool
Read Only:False
Required:True
Default Value:True
Allowed Type:bool
pool_size

Pool size

SQLAlchemy connections pool size

Implementation:zope.schema.Int
Read Only:False
Required:False
Default Value:25
Allowed Type:int
pool_recycle

Pool recycle time

SQLAlchemy connection recycle time (-1 for none)

Implementation:zope.schema.Int
Read Only:False
Required:False
Default Value:-1
Allowed Type:int
echo_pool

Echo pool?

Log all pool checkouts/checkins to system logger?

Implementation:zope.schema.Bool
Read Only:False
Required:True
Default Value:False
Allowed Type:bool
encoding

Encoding

Implementation:zope.schema.Choice
Read Only:False
Required:True
Default Value:‘utf-8’
convert_unicode

Convert Unicode

Implementation:zope.schema.Bool
Read Only:False
Required:True
Default Value:False
Allowed Type:bool

pyams_alchemy.mixin

class pyams_alchemy.mixin.DynamicSchemaMixin[source]

Bases: object

Dynamic schema mixin class

This class is used to set an entity schema name in Pyramid settings

classmethod get_schema()[source]
classmethod get_schema_settings_name()[source]