A library to unify database connections and drivers
Project description
DbYoke
DbYoke is a library designed to standardize database connections. It supports multiple drivers (PostgreSQL, MSSQL, Oracle) and simplifies connection string generation and connection management.
Features
- Simplified database connection management.
- Support for PostgreSQL, Microsoft SQL Server, and Oracle.
- Unified interface for working with database drivers.
- Connection string generation.
- Configuration loading from JSON or YAML files.
- Utility functions (logging, configuration validation).
Installation
You can install DbYoke using pip install dbyoke.
Install from PyPI
To install the library with all available drivers:
pip install dbyoke[all]
To install only specific drivers, use the following commands:
• For PostgreSQL:
pip install dbyoke[postgresql]
• For Oracle:
pip install dbyoke[oracle]
• For MSSQL:
pip install dbyoke[mssql]
Optional Dependencies
DbYoke provides optional dependencies for different database drivers. You can install the specific drivers you need by using the extras feature of pip. For example, to install support for PostgreSQL, you can use:
pip install dbyoke[postgresql]
Quick Start
Connecting to a Database
Example for PostgreSQL
from dbyoke.connection import DatabaseConnection
config = {
"db_type": "postgresql",
"dbname": "example_db",
"user": "admin",
"password": "secret",
"host": "localhost",
"port": 5432
}
with DatabaseConnection(config) as db:
connection = db.connect()
cursor = connection.cursor()
cursor.execute("SELECT * FROM my_table")
print(cursor.fetchall())
Example for MSSQL
from dbyoke.connection import DatabaseConnection
config = {
"db_type": "mssql",
"dbname": "example_db",
"user": "admin",
"password": "secret",
"host": "localhost",
"driver": "{ODBC Driver 18 for SQL Server}",
"trust_certificate": "yes"
}
with DatabaseConnection(config) as db:
connection = db.connect()
cursor = connection.cursor()
cursor.execute("SELECT 1")
print(cursor.fetchall())
Generating a Connection String
from dbyoke.connection_string import ConnectionStringBuilder
config = {
"db_type": "oracle",
"user": "system",
"password": "oracle",
"host": "localhost",
"port": 1521,
"service_name": "XE"
}
builder = ConnectionStringBuilder(config)
print(builder.build())
# Output: "system/oracle@localhost:1521/XE"
Logging
To enable logging, you can use the following utility function:
from dbyoke.utils import configure_logging
logger = configure_logging(level="DEBUG")
Supported Databases
| Database Type | Driver | Dependency |
|---|---|---|
| PostgreSQL | Psycopg2Driver | psycopg2-binary |
| MSSQL | PyODBCDriver | pyodbc |
| Oracle | OracleDriver | oracledb |
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 dbyoke-0.1.1.tar.gz.
File metadata
- Download URL: dbyoke-0.1.1.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4220ead49f26c8596a3758769b51fc46d464a35f6b257a208371e1f1391d3a12
|
|
| MD5 |
4743502fc0f6e92556c86a5c5094ebcf
|
|
| BLAKE2b-256 |
297bfa7288c185b8f49b6f018f44703fe598afa9392011f14b975c86ef3cfe27
|
File details
Details for the file dbyoke-0.1.1-py3-none-any.whl.
File metadata
- Download URL: dbyoke-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ae49b828376ff2fa99877084a5265293ce0b71c6c9eb787e28939eece557ef61
|
|
| MD5 |
1a6d6500e031b5ceb44e7a4c5fbeaaeb
|
|
| BLAKE2b-256 |
c133eab4f9f1dfbe3db5a051ac3121936099dcee2f128a6547cba0e142061769
|