Skip to main content

A package that connects to one or more PostgreSQL databases and allows you to retrieve a database connection when required. Depends on psycopg2-binary.

Project description

pgsql-connection-handler

A package that connects to one or more PostgreSQL databases and allows you to retrieve a database connection when required. Depends on psycopg2-binary.

Quickstart

  1. Install the package:

    pip install pgsql-connection-handler
    
  2. Use the package:

    from pg_connection_handler import databases, connect_databases
    
    DATABASES = {
        'default': {
            'dbname': 'mydatabase',
            'user': 'guido',
            'password': 'SuperS3cr!t',
            'host': 'localhost',
            'port': '5432',
            'sslmode': 'disable',
            'application_name': 'myapp',
        },
        'another_db': {
            'dbname': 'mydatabase',
            'user': 'guido',
            'password': 'SuperS3cr!t',
            'host': 'localhost',
            'port': '5432',
            'sslmode': 'disable',
            'application_name': 'myapp',
        },
    }
    connect_databases(DATABASES)
    
    db_connection = databases.get_connection()
    
    # Or get the connection based on the alias used in DATABASES
    db_connection = databases.get_connection('db_alias')
    
    # Or get the database object
    db = databases.get()
    db_connection = db.conn
    

Compatiblity

  • Compatible with Python 3.8 and above.

Versioning

This project follows semantic versioning (SemVer).

License, code of conduct and requirements

Check the root of the repo for these files.

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

pgsql-connection-handler-1.0.0b0.tar.gz (16.6 kB view hashes)

Uploaded Source

Built Distribution

pgsql_connection_handler-1.0.0b0-py3-none-any.whl (17.6 kB view hashes)

Uploaded Python 3

Supported by

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