Skip to main content

A Python library for connecting to various databases.

Project description

db-connector-kr

db-connector-kr is a Python library designed to simplify database interactions across multiple DBMS platforms. It provides a consistent interface for executing queries, retrieving results as pandas DataFrames, and inserting data efficiently.

Supported DBMS

The following DBMS platforms are considered:

  • PostgreSQL (Supported)
  • Snowflake (Supported)
  • MySQL (Supported)
  • Microsoft SQL Server (MSSQL) (Planned)
  • Oracle (Planned)

Currently, only PostgreSQL, Snowflake, and MySQL are fully supported. MSSQL and Oracle support are planned for future updates.


Installation

Install db-connector-kr via pip (once published to PyPI):

pip install db-connector-kr

Optional Dependencies

PostgreSQL: To use PostgreSQL, install the additional dependency:

pip install db-connector-kr[postgres]

!PostgreSQL


Features

  1. Database Connection
  • Automatically handles database connection initialization and validation.
  1. Query Execution
  • Retrieve results as pandas DataFrames (read_to_df).
  • Execute DML queries such as INSERT, UPDATE, or DELETE (execution_query).
  1. DataFrame Insertion
  • Insert pandas DataFrames into database tables efficiently (insert_df)

Usage

  1. Initialization
from db_connector.db_connector import DBConnector

# Initialize the connector for PostgreSQL
config = {
    "dbms": "pg",
    "user": "your_username",
    "pw": "your_password",
    "dbname": "your_database",
    "host": "localhost",
    "port": 5432
}
# Initialize the connector for maria, mysql
config = {
    "dbms": "mysql",
    "user": "test_user",
    "pw": "test_password",
    "dbname": "test_db",
    "host": "localhost",
    "port": 3306,
}

# Initialize the connector for snowflake
config = {
    "dbms": "sf",
    "user": "test_user",
    "pw": "test_password",
    "dbname": "test_db",
    "account": "test_account",
    "warehouse": "test_warehouse",
}

connector = DBConnector(**config)
  1. Retrieve Data as DataFrame
query = "SELECT * FROM your_table;"
df = connector.read_to_df(query)
print(df.head())
  1. Execute DML Queries
query = "INSERT INTO your_table (id, name) VALUES (1, 'Alice');"
connector.execution_query(query)
  1. Insert DataFrame into a Table
import pandas as pd

# Example DataFrame
data = {"id": [1, 2], "name": ["Alice", "Bob"]}
df = pd.DataFrame(data)

# Insert into the table
connector.insert_df(df, table="your_table")
  1. Close Connection
connector.close()

Planned Features

  • Support for Microsoft SQL Server (MSSQL).
  • Support for Oracle.
  • Enhanced error handling and logging.

Contributing

Contributions are welcome! If you would like to contribute, please:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request with detailed information about your changes.

License

This project is licensed under the MIT License.


Contact

For any inquiries or issues, please create an issue in the repository or contact the maintainer directly.

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

db_connector_kr-0.1.5.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

db_connector_kr-0.1.5-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file db_connector_kr-0.1.5.tar.gz.

File metadata

  • Download URL: db_connector_kr-0.1.5.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for db_connector_kr-0.1.5.tar.gz
Algorithm Hash digest
SHA256 c1c22961925593651453c3fb071bd6b60c42943a84b9ae576993c4e2100d7d53
MD5 266394d2cb6af6a6af363bce824a4359
BLAKE2b-256 7883c327102fa90d31dac840fbc657d5d2bb847c8f3c20401a58251dc03b0711

See more details on using hashes here.

File details

Details for the file db_connector_kr-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for db_connector_kr-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 96a455a7aa182ec5911fc809457e47539449302bc9621a774d4468c5696eb9d9
MD5 09ba600496ad6eca47f54585f29fe9b9
BLAKE2b-256 f29cd2b01b57588e417d85222ae8a1fcb597ed1f7368e1401bdb407773d0eb7d

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