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, 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.

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

dbyoke-0.1.3.tar.gz (7.4 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.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbyoke-0.1.3.tar.gz
  • Upload date:
  • Size: 7.4 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.3.tar.gz
Algorithm Hash digest
SHA256 f92183a321e031440a09439d9a781606d92f4c92b2ea2273fad28542700edf85
MD5 0f9da2ec9ccb9e3cd2fb84bcd7b68712
BLAKE2b-256 bb34f1d235c030cf859663015a1025a40eb904c5d44703035a8271366a3c185c

See more details on using hashes here.

File details

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

File metadata

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

Hashes for dbyoke-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2a84168804140d22785948cb58c5db10c0f6d0b85e72c85273221864617e565c
MD5 fbb431096d6d0d78772229e9eecf3d57
BLAKE2b-256 2d952c2cdb29ea94c618be109def581a7cf232274f2fa042f314f3198f261c40

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