SQLAlchemy Extension for PyApp
Project description
Let us handle the boring stuff!
This extension provides a Connection and Session factory for SQLAlchemy to allow database connections to be configured via pyApp settings.
Engine instances are created from a singleton factory to ensure that connection pooling is utilised.
The extension also provides checks to confirm the settings are correct and that the application is able to connect to the database host.
Installation
Install using pip:
pip install pae.sqlalchemy
Install using pipenv:
pipenv install pae.sqlalchemy
Add pae.sqlalchemy into the EXT list in your applications default_settings.py.
Add the DATABASE_ENGINES block into your runtime settings file:
DATABASE_ENGINES = { "default": { "url": "postgres://user:pass@host:port/database", }, }
Usage
The following example creates both Connection and Session instances:
from pae.sql_alchemy import get_connection, get_session # Get connection from default connection pool cnn = get_connection() # Get connection from an alternate pool session = get_session("Alternate")
API
pae.sqlalchemy.get_engine(default: str = None) -> Engine
Get named Engine instance (singleton)
pae.sqlalchemy.get_connection(default: str = None) -> Connection
Get named Connection instance.
pae.sqlalchemy.get_raw_connection(default: str = None)
Get named raw connection, this is the underlying Python DBAPI object.
pae.sqlalchemy.get_session(default: str = None) -> Session
Get named Session instance.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pyApp_SQLAlchemy-1.0b1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52fe6c55d56510c6bc1168c55614f874c4b1047facf130acd0b89d2fb1126aaf |
|
MD5 | 0246d3c29e836de1be9778016230a2ab |
|
BLAKE2b-256 | 1c3a9c6b5c747ff27de5dd4c4f2b331cb6ab8d06467e817a453b9a0a8002bfb0 |