Introduction
Writing raw SQL queries across PostgreSQL, SQLite, MySQL, SQL Server, and Oracle usually means wrangling five different drivers and endless setup boilerplate.
Object-Relational Mappers (ORMs) like SQLAlchemy solve driver fragmentation, but they introduce heavy performance overhead, complex abstractions, and a steep learning curve when all you want to do is execute straightforward queries.
SQLPyHelper bridges this gap by delivering a lightweight, unified API for Python applications without ORM bloat.
Why choose SQLPyHelper over a full ORM?
If you want a clean, parameterized SQL execution with built-in connection pooling and multi-database compatibility, SQLPyHelper handles the low-level mechanics for you.
- 5 Databases, 1 Syntax: Run identical operational logic across SQLite, PostgreSQL, MySQL, SQL Server, and Oracle.
-
Native Async Support: Seamlessly integrate with FastAPI or
asynciousingAsyncSQLPyHelper. -
Built-in Migration & CSV Exports: Move tables directly between two distinct database engines or export data instantly using
db.backup_table("orders", "orders.csv"). -
Zero-Config Environments: Automatically loads credentials from a root
.envfile when initialized viaSQLPyHelper(). -
Production-Ready Safety: Connection pooling, automatic reconnection handling, explicit transaction management (
BEGIN,ROLLBACK,COMMIT), and SQL injection protection via parameterization.
One API in action
SQLPyHelper standardizes database operations whether you are running synchronous scripts or asynchronous web services.
Synchronous Context Manager & CSV Export
from sqlpyhelper.db_helper import SQLPyHelper
# Automatically detects DB_TYPE, DB_HOST, DB_USER, etc. from .env
with SQLPyHelper() as db:
# Parameterized query using standard tuple arguments
db.execute_query("INSERT INTO customers (name) VALUES (%s)", ("Bob",))
# Export table directly to CSV in a single command
db.backup_table("customers", "customers_backup.csv")
Asynchronous (FastAPI / asyncio)
import asyncio
from sqlpyhelper.async_helper import AsyncSQLPyHelper
async def main():
# Native async support passing positional arguments directly
async with AsyncSQLPyHelper(db_type="sqlite", database="app.db") as db:
await db.execute("INSERT INTO users VALUES ($1, $2)", 1, "Alice")
rows = await db.fetch_all("SELECT * FROM users")
print(rows)
asyncio.run(main())
Modular installation setup
Keep your dependencies lean by installing only the specific database drivers your stack requires:
| Target Database | Package Extra | Installation Command |
|---|---|---|
| SQLite | Base | pip install sqlpyhelper |
| PostgreSQL | [postgres] |
pip install sqlpyhelper[postgres] |
| MySQL | [mysql] |
pip install sqlpyhelper[mysql] |
| SQL Server | [sqlserver] |
pip install sqlpyhelper[sqlserver] |
| Oracle | [oracle] |
pip install sqlpyhelper[oracle] |
| All Drivers | [all] |
pip install sqlpyhelper[all] |
SQLPyHelper help eliminates driver-specific friction and heavy abstractions, giving you direct control over your database queries with minimal setup setup time. Whether you are building background data pipelines, running FastAPI microservices, or managing dynamic table migrations, it lets you focus on writing clean Python code rather than database connection boilerplate.
Resources
Check out the project, report issues, or contribute on GitHub:
- GitHub Repository: adebayopeter/sqlpyhelper
- PyPI Package: sqlpyhelper on PyPI
- Official Documentation: SQLPyHelper Docs
If you find SQLPyHelper useful, consider giving the repository a ⭐ on GitHub!
Top comments (0)