Skip to main content

A unified database connector SDK for Python

Project description

๐Ÿ—„๏ธ Universal DB SDK

A lightweight, plug-and-play Python SDK for connecting to multiple databases (MySQL, PostgreSQL, MongoDB, Redis) through a single unified interface.


๐Ÿ“ฆ Installation

pip install db-sdk

Install only the drivers you need:

pip install mysql-connector-python   # MySQL
pip install psycopg2-binary          # PostgreSQL
pip install pymongo                  # MongoDB
pip install redis                    # Redis

โœจ Features

  • One interface for MySQL, PostgreSQL, MongoDB, and Redis
  • No boilerplate โ€” one function call returns a live connection
  • Easy to extend โ€” add a new database in minutes
  • Clean error handling โ€” typed exceptions for every failure mode
  • Zero framework dependency โ€” works with FastAPI, Django, Flask, or plain Python

๐Ÿš€ Quick Start

from db_sdk.core.factory import ConnectionFactory

conn = ConnectionFactory.create_connection("mysql", {
    "host": "localhost",
    "user": "root",
    "password": "yourpassword",
    "database": "mydb",
    "port": 3306
})

That's it. conn is a live, ready-to-use connection object.


๐Ÿ”Œ Supported Databases

Database Type string Driver used
MySQL "mysql" mysql-connector-python
PostgreSQL "postgres" psycopg2
MongoDB "mongodb" pymongo
Redis "redis" redis

โš™๏ธ Configuration Reference

MySQL

conn = ConnectionFactory.create_connection("mysql", {
    "host":     "localhost",
    "user":     "root",
    "password": "yourpassword",
    "database": "mydb",
    "port":     3306          # optional, defaults to 3306
})

PostgreSQL

conn = ConnectionFactory.create_connection("postgres", {
    "host":     "localhost",
    "user":     "postgres",
    "password": "yourpassword",
    "database": "mydb",
    "port":     5432          # optional, defaults to 5432
})

MongoDB

conn = ConnectionFactory.create_connection("mongodb", {
    "uri": "mongodb://user:password@localhost:27017/mydb"
})

MongoDB uses a URI string instead of separate fields. Format: mongodb://user:password@host:port/database

Redis

conn = ConnectionFactory.create_connection("redis", {
    "host": "localhost",
    "port": 6379             # optional, defaults to 6379
})

๐Ÿ—๏ธ Project Structure

db_sdk/
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ settings.py
โ”œโ”€โ”€ core/
โ”‚   โ”œโ”€โ”€ base_connector.py    # Abstract base all connectors inherit from
โ”‚   โ”œโ”€โ”€ exceptions.py        # All SDK exception types
โ”‚   โ””โ”€โ”€ factory.py           # ConnectionFactory โ€” the main entry point
โ””โ”€โ”€ connectors/
    โ”œโ”€โ”€ mysql.py             # MySQL connector
    โ”œโ”€โ”€ postgres.py          # PostgreSQL connector
    โ”œโ”€โ”€ mongodb.py           # MongoDB connector
    โ””โ”€โ”€ redis.py             # Redis connector

โš ๏ธ Error Handling

The SDK raises typed exceptions so you can handle failures precisely:

from db_sdk.core.factory import ConnectionFactory
from db_sdk.core.exceptions import (
    DatabaseConnectionError,
    UnsupportedDatabaseError,
    ConfigurationError,
)

try:
    conn = ConnectionFactory.create_connection("mysql", config)

except DatabaseConnectionError as e:
    # Connection failed โ€” wrong password, DB offline, network issue
    print(f"Could not connect: {e}")

except UnsupportedDatabaseError as e:
    # db_type string not recognised
    print(f"Unknown database type: {e}")

except ConfigurationError as e:
    # Missing or invalid keys in the config dict
    print(f"Bad config: {e}")

Exception Hierarchy

UniversalDBException          โ† catch this for any SDK error
    โ”œโ”€โ”€ DatabaseConnectionError
    โ”œโ”€โ”€ UnsupportedDatabaseError
    โ””โ”€โ”€ ConfigurationError

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

db_sdk-1.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

db_sdk-1.1.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file db_sdk-1.1.0.tar.gz.

File metadata

  • Download URL: db_sdk-1.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for db_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 868e9802481b2abafbf9fa1e2f56b49a36f236ae93884b4f9c6775167a974678
MD5 0d781f287ae7d6b113f5d3fe42d307c8
BLAKE2b-256 5532a1d5231c6c6f730d7bb8f23be3e3455f183b82aeb1e4d06ab6138a703471

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_sdk-1.1.0.tar.gz:

Publisher: publish.yml on DataTemplateInfotech/SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file db_sdk-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: db_sdk-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for db_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 795469378c6bad994ac2f7294ade52b7cbdeb43e193eaffed7cebee11fc45ae2
MD5 2b9434d7367882f6a4e1c3532db8eaef
BLAKE2b-256 a66b8ed76803d552330cb44558012c5b53ee6671a123ae14022c6c16327685ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_sdk-1.1.0-py3-none-any.whl:

Publisher: publish.yml on DataTemplateInfotech/SDK

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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