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

dbyoke-0.1.2.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.2-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dbyoke-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 9d54ceed424dedae09cf136fd7f2630a71a4342b0ba911271f3b9455b3d785f4
MD5 a1d91e54031791af4fd57ba54b40c9be
BLAKE2b-256 57a1dc78a3e7193a497c7abfa8db7bed51612f4c9fef4c0f4b4e7dabd154ed70

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dbyoke-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c1407b4041165693d2ffa0da5051bf6fcd9b42a9a9ee262e14abe8acd5c6f941
MD5 3bb8014c7a221768a1ac530c75ea37ff
BLAKE2b-256 b8c861de8da085a550bfd5a1795680ce54d1a8f2388e33f78eb07b777b82cc10

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