A simple SQL database helper package for Python.
Project description
📌 SQLPyHelper
A Python library for simplified database interactions across SQLite, PostgreSQL, MySQL, SQL Server, and Oracle. This open-source package provides an intuitive API for handling database operations efficiently.
📖 Table of Contents
- 🚀 Features
- 📦 Installation
- ⚙️ Setup Using
.env - 🛠 Usage Examples
- 📂 Project Structure
- 🌍 Contributing
- ☕ Support the Project
🚀 Features
- Unified Interface for multiple databases
- Connection pooling support for PostgreSQL
- Bulk insertion & dynamic table creation
- Automated logging & query execution
- CSV export & backup functionality
📦 Installation
Install via PyPI:
pip install sqlpyhelper
📌 Package on PyPI: SQLPyHelper on PyPI
Or, if working from source:
git clone https://github.com/adebayopeter/sqlpyhelper.git
cd sqlpyhelper
pip install -r requirements.txt
⚙️ Setup Using .env
Create a .env file in your project root to manage database configurations securely by renaming .env_example.
# .env_example (Rename to .env)
DB_TYPE=postgres
DB_HOST=localhost
DB_USER=your_user
DB_PASSWORD=your_secure_password
DB_NAME=database_name
DB_DRIVER={ODBC Driver 17 for SQL Server}
ORACLE_SID=XE
ORACLE_DB_PORT=1521
Loading .env in Code
from dotenv import load_dotenv
import os
load_dotenv()
db_type = os.getenv("DB_TYPE")
host = os.getenv("DB_HOST")
user = os.getenv("DB_USER")
password = os.getenv("DB_PASSWORD")
database = os.getenv("DB_NAME")
🛠 Usage Examples
SQLite Example
from sqlpyhelper.db_helper import SQLPyHelper
db = SQLPyHelper()
db.execute_query("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)")
db.execute_query("INSERT INTO users (name) VALUES (?)", ("Alice",))
db.execute_query("SELECT * FROM users")
print(db.fetch_all())
db.close()
PostgreSQL Example
db = SQLPyHelper()
db.execute_query("CREATE TABLE IF NOT EXISTS employees (id SERIAL PRIMARY KEY, name VARCHAR(100))")
db.execute_query("INSERT INTO employees (name) VALUES (%s)", ("Charlie",))
db.execute_query("SELECT * FROM employees")
print(db.fetch_all())
db.close()
MySQL Example
db = SQLPyHelper()
db.execute_query("CREATE TABLE IF NOT EXISTS customers (id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100))")
db.execute_query("INSERT INTO customers (name) VALUES (%s)", ("David",))
db.execute_query("SELECT * FROM customers")
print(db.fetch_all())
db.close()
db = SQLPyHelper()
# Fetch rows where customer_id = 3
customers = db.fetch_by_param("customers", "id", 3)
print(customers)
db.close()
SQL Server Example
db = SQLPyHelper()
db.execute_query("CREATE TABLE IF NOT EXISTS orders (id INT PRIMARY KEY, product VARCHAR(100))")
db.execute_query("INSERT INTO orders (id, product) VALUES (?, ?)", (1, "Laptop"))
db.execute_query("SELECT * FROM orders")
print(db.fetch_all())
db.close()
Oracle Example
db = SQLPyHelper()
db.execute_query("CREATE TABLE employees (id NUMBER PRIMARY KEY, name VARCHAR2(100))")
db.execute_query("INSERT INTO employees (id, name) VALUES (:1, :2)", (1, "Emily"))
db.execute_query("SELECT * FROM employees")
print(db.fetch_all())
db.close()
📂 Project Structure
📦 SQLPyHelper/
├─ sqlpyhelper/
│ ├─ __init__.py
│ └─ db_helper.py
├─ tests/
│ └─ test_sqlpyhelper.py
├─ .env_example
├─ .gitignore
├─ setup.py
├─ README.md
└─ requirements.txt
🌍 Contributing
We welcome contributions from the open-source community! Follow these steps to contribute:
- Fork the repo: SQLPyHelper GitHub Repository
- Clone your fork:
git clone https://github.com/adebayopeter/sqlpyhelper.git
- Create a new branch:
git checkout -b feature-new-functionality
- Make changes, commit, and push:
git commit -m "Added new feature" git push origin feature-new-functionality
- Submit a Pull Request!
☕ Support the Project
If you find SQLPyHelper useful, consider buying me a coffee to support continued development! Donate Here: PayPal
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 sqlpyhelper-0.1.2.tar.gz.
File metadata
- Download URL: sqlpyhelper-0.1.2.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ecbe1eb335e00ba0ce7514b5fc17cc1e9b9fd2d0b88a724e3d63ed36611d9b2
|
|
| MD5 |
feaf8e9ca9d474666131513facfe84a1
|
|
| BLAKE2b-256 |
403d387ab29d87a4abc17d1ebfadc185b131ce974748a6853198bc4ab7382fcc
|
File details
Details for the file sqlpyhelper-0.1.2-py3-none-any.whl.
File metadata
- Download URL: sqlpyhelper-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
585e68c511ac696f9da4bbcc7b5f23edd65e75ba1ffeccd157f2968fc2a8ea21
|
|
| MD5 |
5e049c95c471e5496884278184487e47
|
|
| BLAKE2b-256 |
beeb396610eb429ac82767e72f8639a9734b98cabc17e7a29581195dc4a7d213
|