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]
Features
- Database Connection
- Automatically handles database connection initialization and validation.
- Query Execution
- Retrieve results as pandas DataFrames (
read_to_df). - Execute DML queries such as INSERT, UPDATE, or DELETE (
execution_query).
- DataFrame Insertion
- Insert pandas DataFrames into database tables efficiently (
insert_df)
Usage
- Initialization
from 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
}
connector = DBConnector(**config)
- Retrieve Data as DataFrame
query = "SELECT * FROM your_table;"
df = connector.read_to_df(query)
print(df.head())
- Execute DML Queries
query = "INSERT INTO your_table (id, name) VALUES (1, 'Alice');"
connector.execution_query(query)
- 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")
- 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:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- 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
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 db_connector_kr-0.1.1.tar.gz.
File metadata
- Download URL: db_connector_kr-0.1.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76281ebaa54529e51764df82c958af504b8aac109864399aa1b251859f2fe9fc
|
|
| MD5 |
41a17038f67031512ef879740670b935
|
|
| BLAKE2b-256 |
fb96b41bd372c1470e6bd9a2c8ca469e84b41a28c03cd89f644aa00f1bbe3557
|
File details
Details for the file db_connector_kr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: db_connector_kr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31cdca1aaf65f91eea313aad8ef589302fcdb80832c1f2f477133aaa6cc18e20
|
|
| MD5 |
0072a6c8e9d1ed4dbc20a656094acb8d
|
|
| BLAKE2b-256 |
349f838bd8326a9e60de2a42c1f404dd8a2c4972f77213faa00d97cef6cfaafc
|