Skip to main content

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

  • Unified Interface for multiple databases
  • Connection pooling support for PostgreSQL
  • Bulk insertion & dynamic table creation
  • Automated logging & query execution
  • CSV export & backup functionality

📦 Installation

pip install sqlpyhelper

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=test_db
DB_PORT=5432
DB_DRIVER={ODBC Driver 17 for SQL Server}
ORACLE_SID=XE
ORACLE_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()

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:

  1. Fork the repo: SQLPyHelper GitHub Repository
  2. Clone your fork:
    git clone https://github.com/adebayopeter/sqlpyhelper.git
    
  3. Create a new branch:
    git checkout -b feature-new-functionality
    
  4. Make changes, commit, and push:
    git commit -m "Added new feature"
    git push origin feature-new-functionality
    
  5. 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

sqlpyhelper-0.1.1.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

sqlpyhelper-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file sqlpyhelper-0.1.1.tar.gz.

File metadata

  • Download URL: sqlpyhelper-0.1.1.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for sqlpyhelper-0.1.1.tar.gz
Algorithm Hash digest
SHA256 dca32b4208cc35abed978f8fa7186ced5e803ece156be96163f63fe66a4eed7f
MD5 7949fd1d5e1d3df3d078837bc17c410f
BLAKE2b-256 0353642ae15db848b322df84d52147e14d43916778fb6f4e2112cd724304e1b5

See more details on using hashes here.

File details

Details for the file sqlpyhelper-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: sqlpyhelper-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.5

File hashes

Hashes for sqlpyhelper-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e447a6507f9f58b92422e47fc5caa48ba19f5f3b2f5fa4529adc61135eddab0f
MD5 da3c4237af28f7313d7d9694f5a7bcbf
BLAKE2b-256 10be0459ab4fd824f8dc63d1374ffbbb508acf92eb8d9e7fe01067faa20b89aa

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