Skip to main content

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, SQLite, MSSQL, Oracle) and simplifies connection string generation and connection management.

Features

  • Simplified database connection management.
  • Support for PostgreSQL, SQLite, 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 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

dbyoke-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

dbyoke-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file dbyoke-0.1.0.tar.gz.

File metadata

  • Download URL: dbyoke-0.1.0.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

Hashes for dbyoke-0.1.0.tar.gz
Algorithm Hash digest
SHA256 422faa47908403de68843ba0a70e1d0f3a35b263bcad8971daf5ec1dd163160b
MD5 adcce8c6da42a3ff35f64deb99a15871
BLAKE2b-256 c5a83395a4b2864c29596c604e5f19b4c26290c56efcb598ebd04a09c453ada2

See more details on using hashes here.

File details

Details for the file dbyoke-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dbyoke-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for dbyoke-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb3744aa698720ceac7d34979ef44c5e47ab6854a74ba7d7013d79ea389d842e
MD5 3c7fb69370c7312d231f4e436c3930a2
BLAKE2b-256 c98c8468b8034ba2e53ea385c76063cc221259cc3315c0182c32dea76a21ab10

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