What you need to achieve is well described in the pylon documentation: Defining ORM tables and classes :
The model consists of two files: __init__.py and meta.py. __init__.py contains table definitions and ORM classes, as well as the init_model () function, which must be called when the application starts. meta.py is just a container for SQLAlchemys household objects (session, metadata, and engine) that not all applications will use.
An example of __init__.py shown in the link, while meta.py looks something like this:
from sqlalchemy import MetaData from sqlalchemy.orm import scoped_session, sessionmaker __all__ = ['Session', 'engine', 'metadata'] engine = None Session = scoped_session(sessionmaker()) metadata = MetaData()
You can consider this module as a singleton implementation if you want, because it will do the job (load and have one instance in more Pythonic) for you when you first load the module.
source share