Skip to main content

SQLAlchemy Extension for PyApp

Project description

Let us handle the boring stuff!

https://img.shields.io/badge/code%20style-black-000000.svg Maintainability

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 pyapp-sqlalchemy

Install using pipenv:

pipenv install pyapp-sqlalchemy

Add pyapp_ext.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 pyapp_ext.sqlalchemy 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

pyapp_ext.sqlalchemy.get_engine(default: str = None) -> Engine

Get named Engine instance (singleton)

pyapp_ext.sqlalchemy.get_connection(default: str = None) -> Connection

Get named Connection instance.

pyapp_ext.sqlalchemy.get_raw_connection(default: str = None)

Get named raw connection, this is the underlying Python DBAPI object.

pyapp_ext.sqlalchemy.get_session(default: str = None) -> Session

Get named Session instance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyApp-SQLAlchemy-1.0.1.tar.gz (4.0 kB view hashes)

Uploaded source

Built Distribution

pyApp_SQLAlchemy-1.0.1-py3-none-any.whl (8.6 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page