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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c5d4ee1eb45f64c9144a93e895c51009e460a068e094e3baf5a07a18cbb5471
|
|
| MD5 |
f7b8de7ebbe19931daa2fba3b1fa1f39
|
|
| BLAKE2b-256 |
f6d5eb2a55302fec71bfb2bc6204660db784090dda66b48f8c7c2e82f525c3d3
|
Provenance
The following attestation bundles were made for db_sdk-4.0.14.tar.gz:
Publisher:
publish.yml on DataTemplateInfotech/SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_sdk-4.0.14.tar.gz -
Subject digest:
7c5d4ee1eb45f64c9144a93e895c51009e460a068e094e3baf5a07a18cbb5471 - Sigstore transparency entry: 1179371675
- Sigstore integration time:
-
Permalink:
DataTemplateInfotech/SDK@8e1d0f8ee8c247f95c6c0084842ce6cbd0ebff0c -
Branch / Tag:
refs/tags/v4.0.14 - Owner: https://github.com/DataTemplateInfotech
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e1d0f8ee8c247f95c6c0084842ce6cbd0ebff0c -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fafef85c6a1456c15598944b813b493e99b994db42d0b6fe63bfb69af8dd0aa1
|
|
| MD5 |
f11b726a879f39bd94f365ced064c1ad
|
|
| BLAKE2b-256 |
608a23fd3a5c896dc31bc47a1480e53091de636043675f3f79396397a2e68692
|
Provenance
The following attestation bundles were made for db_sdk-4.0.14-py3-none-any.whl:
Publisher:
publish.yml on DataTemplateInfotech/SDK
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
db_sdk-4.0.14-py3-none-any.whl -
Subject digest:
fafef85c6a1456c15598944b813b493e99b994db42d0b6fe63bfb69af8dd0aa1 - Sigstore transparency entry: 1179371709
- Sigstore integration time:
-
Permalink:
DataTemplateInfotech/SDK@8e1d0f8ee8c247f95c6c0084842ce6cbd0ebff0c -
Branch / Tag:
refs/tags/v4.0.14 - Owner: https://github.com/DataTemplateInfotech
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8e1d0f8ee8c247f95c6c0084842ce6cbd0ebff0c -
Trigger Event:
push
-
Statement type: