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.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyApp_SQLAlchemy-1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pyApp-SQLAlchemy-1.0.tar.gz.

File metadata

  • Download URL: pyApp-SQLAlchemy-1.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for pyApp-SQLAlchemy-1.0.tar.gz
Algorithm Hash digest
SHA256 94aed538bb98ed88c95e35b2fe00c542b6cd955fd6a4ae168a697e78ba97681d
MD5 16f482ce5c1e96b8da3a3153455e3233
BLAKE2b-256 f8a24c24318af349083128d3740c182ebe7ac2e944baf8099a23d24dd79b50a7

See more details on using hashes here.

File details

Details for the file pyApp_SQLAlchemy-1.0-py3-none-any.whl.

File metadata

  • Download URL: pyApp_SQLAlchemy-1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.7

File hashes

Hashes for pyApp_SQLAlchemy-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c46f542e86e8723e34a1a8cdfa62355c3d272d1e4f872a6e3e6b4486484ca403
MD5 81145b494e0e55023a8d4885f6fcdfb8
BLAKE2b-256 36f4961da67fd848dc34f876d7c2cce05bde042933f0032e333c203e8080d1fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page