Skip to main content

A simple database connection SDK

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-4.0.14.tar.gz (6.5 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-4.0.14-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for db_sdk-4.0.14.tar.gz
Algorithm Hash digest
SHA256 7c5d4ee1eb45f64c9144a93e895c51009e460a068e094e3baf5a07a18cbb5471
MD5 f7b8de7ebbe19931daa2fba3b1fa1f39
BLAKE2b-256 f6d5eb2a55302fec71bfb2bc6204660db784090dda66b48f8c7c2e82f525c3d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_sdk-4.0.14.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-4.0.14-py3-none-any.whl.

File metadata

  • Download URL: db_sdk-4.0.14-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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-4.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 fafef85c6a1456c15598944b813b493e99b994db42d0b6fe63bfb69af8dd0aa1
MD5 f11b726a879f39bd94f365ced064c1ad
BLAKE2b-256 608a23fd3a5c896dc31bc47a1480e53091de636043675f3f79396397a2e68692

See more details on using hashes here.

Provenance

The following attestation bundles were made for db_sdk-4.0.14-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