Skip to main content

Unified db connector system with normalized error handling across multiple databases.

Project description

pymnemon

Unified SQLAlchemy connector with normalized error handling across multiple databases.

Note: The PyPI package name is pymnemon, but the import name is mnemon.

Install

pip install pymnemon

Quickstart

from mnemon import SchemaDBConnection

config = {
    "database_type": "postgresql",
    "auth_method": "password",
    "connection": {
        "user": "dbuser",
        "password": "dbpass",
        "host": "localhost",
        "port": 5432,
        "database": "analytics",
        # optional
        # "sslmode": "require",
    },
}

with SchemaDBConnection(config) as db:
    ok, engine, error = db.safe_connect()
    if not ok:
        print(error)
    else:
        rows = db.execute_query("SELECT 1 AS ok")
        print(rows)

Configuration

SchemaDBConnection expects a config dict with this shape:

{
  "database_type": "<supported database>",
  "auth_method": "<supported auth method>",
  "connection": { ... database-specific fields ... }
}

Supported databases and auth methods:

  • postgresql: password, scram, ssl_verify, ssl_cert
  • mysql: password, ssl_verify, ssl_cert
  • mariadb: password, ssl_verify, ssl_cert
  • clickhouse: password, ssl_verify, ssl_cert
  • sqlserver: password
  • trino: none, password, jwt, certificate
  • sparksql: none, password, ldap
  • vertica: password, ldap, ssl_verify
  • oracle: password, wallet
  • teradata: password, ldap
  • db2: password, ldap
  • snowflake: password, key_pair
  • bigquery: service_account
  • redshift: password, iam_role
  • duckdb: local_file, motherduck
  • databricks: token, oauth_m2m
  • athena: iam_credentials

Example configs

PostgreSQL (password):

{
  "database_type": "postgresql",
  "auth_method": "password",
  "connection": {
    "user": "dbuser",
    "password": "dbpass",
    "host": "localhost",
    "port": 5432,
    "database": "analytics"
  }
}

Snowflake (key pair):

{
  "database_type": "snowflake",
  "auth_method": "key_pair",
  "connection": {
    "account": "xy12345.us-east-1",
    "user": "DBUSER",
    "warehouse": "COMPUTE_WH",
    "database": "ANALYTICS",
    "schema": "PUBLIC",
    "private_key": {"content": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----"},
    "private_key_passphrase": "optional"
  }
}

BigQuery (service account):

{
  "database_type": "bigquery",
  "auth_method": "service_account",
  "connection": {
    "project": "my-gcp-project",
    "dataset": "analytics",
    "location": "US",
    "credentials_json": {"content": "{... service account json ...}"}
  }
}

Databricks (PAT):

{
  "database_type": "databricks",
  "auth_method": "token",
  "connection": {
    "host": "adb-1234567890.12.azuredatabricks.net",
    "http_path": "/sql/1.0/warehouses/abcd1234",
    "access_token": "dapi..."
  }
}

Error handling

safe_connect() returns (success, engine, error) where error is a normalized JSON payload with:

{
  "success": false,
  "error": {
    "category": "auth_failed",
    "message": "Authentication failed. Please check your credentials.",
    "next_steps": ["Verify username and password"],
    "field_hint": "user or password",
    "details": "... original error ..."
  }
}

Notes on dependencies

Some drivers require system dependencies or extra setup:

  • pyodbc for SQL Server requires an ODBC driver (e.g., ODBC Driver 18).
  • oracledb may require Oracle client configuration depending on mode.
  • PyAthena[SQLAlchemy] is used for Athena SQLAlchemy dialect support.

License

MIT

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

pymnemon-0.1.1.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

pymnemon-0.1.1-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file pymnemon-0.1.1.tar.gz.

File metadata

  • Download URL: pymnemon-0.1.1.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for pymnemon-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f2b80b8cf6a7f2beba1863564c286891dd1e2fbabce5b45eb001b3f58f2cca2b
MD5 c5e9f0bce843afb45834811bb60f3e31
BLAKE2b-256 28be85834494ca1662f8f426ad29f2ae2c95e02b063eb0f83c6950b6515fe19a

See more details on using hashes here.

File details

Details for the file pymnemon-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pymnemon-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.3

File hashes

Hashes for pymnemon-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f73ef0d662ab802fcb7f239bdc0893838b2462ba866954f6c9bdcd50fb367d34
MD5 b3be7b1f845239924845c6d1399a5347
BLAKE2b-256 9dafef040cf7512096e3d977d36bcd13bb1c5ff42d9ffa3b57a88f74132570e2

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