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.0.tar.gz (5.7 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.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlpyhelper-0.1.0.tar.gz
  • Upload date:
  • Size: 5.7 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.0.tar.gz
Algorithm Hash digest
SHA256 ebe3adcdf589805d4eba630abcbeb0e49f4e12e4d18edabc5f915fafcea3290c
MD5 5bcf131c17cd85364c4439c5a76e5891
BLAKE2b-256 4d569b28ab40f4bef8a8553793de44e7df82b0ce47a363e39e0013a126c6098e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqlpyhelper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 061a8529b211416f1792c0176da751e5c1819587a54c020ccf7b36db2f471b54
MD5 a666c645e9123757cfd7b440b8ac83e9
BLAKE2b-256 e5e7d71edf300d4efc361d1cd61a1b519f509d3faea714851adcb8b2e89d06f5

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