Skip to main content

Database(s) connector and manager

Project description

database-connector-kit

This python module handles any type of databases connection(s) using a yaml configuration file.

It is a fork coming from fastapi-framework-mvc and flask-framework-mvc.

Created for better package management in between both projects.

Can be loaded standalone outside its original projects.

[!NOTE] If using side by side with either fastapi-framework-mvc or flask-framework-mvc, it will load Environment from one of this framework accordingly to the one you installed int your python env or python root libs.

Default database with builtin driver in sqlalchemy

...
DATABASES: 
  default: mysql
  mysql: 
    driver: mysql+pymysql
    user: "replace this with your database user"
    password: "replace this with your database user's password"
    database: "replace this with your database name"
    address: "replace this with your hostname"
    models: "mysql (python module that require to be put under models.persistent module, non blocking if module doesn't exist)"
    readonly: false
...

Default database with non builtin driver in sqlalchemy

...
DATABASES:
  informix:
    driver: informix
    user: "replace this with your database user"
    password: "replace this with your database user's password"
    database: "replace this with your database name"
    address: "replace this with your hostname"
    models: "informix (python module that require to be put under models.persistent module, non blocking if module doesn't exist)"
    params:
      SERVER: "replace with your server name"
      CLIENT_LOCALE: "replace with your client locale"
      DB_LOCALE: "replace with your server locale"
    dialects:
      informix: 
        module: IfxAlchemy.IfxPy
        class: IfxDialect_IfxPy
      informix.IfxPy: 
        module: IfxAlchemy.IfxPy
        class: IfxDialect_IfxPy
      informix.pyodbc: 
        module: IfxAlchemy.pyodbc
        class: IfxDialect_pyodbc
    readonly: false
...

or:

...
DATABASES:
  bigquery:
    driver: bigquery
    user: "replace this with your database user"
    password: "replace this with your database user's password"
    database: "replace this with your database name"
    address: "replace this with your hostname"
    models: "bigquery (python module that require to be put under models.persistent module)"
    readonly: false
    engine:
      location: US
      
...

dialects, params and engine are non mandatory within the yaml config file.

dialects are for registering database dialects base what the python database lib provides.

params are for putting additional params within the database url link used when sqlalchemy create_engine function is called

engine is all other arguments that can be given to the sqlalchemy create_engine function

Loading configuration

In order to load it you need to create a yaml configuration file with entries as described on sections bellow. This yaml configuration files can have environment variable within encapsuled in ${ENVIRONMENT_NAME} syntax.

import os
from database_connector_kit.config import Environment
Environment.load('config.yml')

Usage

After loading the configuration file, you can create the database's connection(s) by:

from database_connector_kit import Driver
Driver.register_engines()
Driver.init()

There is a safe decorator that enable some sqlalchemy errors to be dealt with and retry reprocessing the function that handles database operations. In order to use it, use de following example:

from database_connector_kit import safe

@safe
def func():
    """
    Function that update, select, insert ot even delete contents from the database
    """
    pass

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

database_connector_kit-1.0.1.tar.gz (46.7 kB view details)

Uploaded Source

Built Distribution

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

database_connector_kit-1.0.1-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file database_connector_kit-1.0.1.tar.gz.

File metadata

  • Download URL: database_connector_kit-1.0.1.tar.gz
  • Upload date:
  • Size: 46.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for database_connector_kit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f9992f44bd7a24d9a56c008c685e47b51075331637edd75336fbd777e7e16601
MD5 5ac6a701f385d252a18f3181ca9864ee
BLAKE2b-256 91e5931c9dea0e391395da7a96871c18805ecec047685119d1616d42ad096216

See more details on using hashes here.

File details

Details for the file database_connector_kit-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for database_connector_kit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dabbb863051e6c00fe52103245538941f07effc3868a0baa4e249c9850649482
MD5 0307843dea7479087e978b6947dcd425
BLAKE2b-256 d9ce5cc480d38948602cdb09f83d47080670d152247ed0c3f7988a7571119d24

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