A Python package providing a unified interface for database operations, supporting Parquet, SQLite, and PostgreSQL backends.
Project description
DBEngine
A unified, production-ready database interface for Python that provides seamless access to SQLite, Parquet, and PostgreSQL databases through a consistent pandas-based API.
Features
- 🚀 Multi-Database Support: Work with SQLite, Parquet files, and PostgreSQL databases using the same API
- 🔧 Production-Ready: Built-in configuration management, error handling, and security features
- 🛡️ Security First: Environment-based configuration, security validation, and secure credential handling
- 🎯 Pandas Integration: Native pandas DataFrame/Series support for all operations
- ⚡ High Performance: Connection pooling, batching, and optimised data handling
- 🐳 PostgreSQL Server Management: Programmatically start/stop PostgreSQL servers using Docker for development and testing
- 🧪 Comprehensive Testing: Full test suite with validation and integration tests
- 📦 Easy Setup: Simple installation and configuration with sensible defaults
Quick Start
Installation
pip install dbengine
Basic Usage
from dbengine import create_database
import pandas as pd
# Create a SQLite database
db = create_database('sqlite', path='my_data.db')
# Create sample data
data = pd.DataFrame({
'id': [1, 2, 3],
'name': ['Alice', 'Bob', 'Charlie'],
'age': [25, 30, 35]
})
# Write data
db.write(table_name='users', data)
# Read data
users = db.query(table_name='users')
print(users)
# Query data
young_users = db.query(criteria={'age': 25}, table_name='users')
print(young_users)
PostgreSQL Server Management
## Supported Databasespython
from dbengine import create_postgres_server, PostgreSQLDatabase
# Start a PostgreSQL server for development/testing
with create_postgres_server(port=5433) as server:
# Create database connection
db = PostgreSQLDatabase(**server.get_connection_params())
# Use the database normally
data = pd.DataFrame({'id': [1, 2], 'name': ['Alice', 'Bob']})
db.write(table_name='users', item=data)
# Database and server automatically cleaned up
Supported Databases
SQLite
- Use Case: Local development, testing, lightweight applications
- Features: File-based, serverless, ACID transactions
- Configuration: Simple file path specification
Parquet
- Use Case: Data analytics, archival, big data processing
- Features: Columnar storage, compression, fast analytics
- Configuration: Directory path with compression options
PostgreSQL
- Use Case: Production applications, multi-user systems
- Features: Full ACID compliance, connection pooling, advanced SQL
- Configuration: Host, port, credentials, SSL support
- Server Management: Docker-based server lifecycle management for development/testing
Configuration
DBEngine supports configuration files for different environments with YAML format.
Environment-Based Configuration
Create configuration files for different environments:
databases:
postgresql:
host: "prod-db.example.com"
port: 5432
database: "myapp_prod"
user: "prod_user"
password: "secure_password" # Set directly in config
logging:
level: "WARNING"
handlers: ["file", "syslog"]
Note: All configuration values must be set in the YAML configuration files.
Advanced Usage
PostgreSQL Server Management
DBEngine includes utilities to programmatically start and stop PostgreSQL servers using Docker, making it perfect for development workflows and testing:
from dbengine import PostgreSQLServerManager, PostgreSQLDatabase
# Manual server lifecycle management
server = PostgreSQLServerManager(port=5433, database='my_test_db')
server.start()
try:
# Create database connection
db = PostgreSQLDatabase(**server.get_connection_params())
# Perform database operations
data = pd.DataFrame({'id': [1, 2, 3], 'value': ['a', 'b', 'c']})
db.write(table_name='test_table', item=data)
result = db.query(table_name='test_table')
print(result)
finally:
db.close()
server.stop()
# Context manager (recommended)
with PostgreSQLServerManager(port=5434) as server:
db = PostgreSQLDatabase(**server.get_connection_params())
# Server automatically stopped when exiting context
Server Management Features:
- Docker Integration: Automatic container lifecycle management
- Port Configuration: Avoid conflicts with existing PostgreSQL instances
- Custom Databases: Create servers with specific database names and credentials
- Health Checks: Automatic server readiness detection
- Multiple Servers: Run multiple isolated PostgreSQL instances simultaneously
Examples
See the notebooks/ directory for comprehensive usage examples.
Testing
Run the comprehensive test suite:
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
Note: PostgreSQL server management tests require Docker to be running. Tests will be automatically skipped if Docker is not available.
Development
Setup Development Environment
git clone https://github.com/tomemgouveia/dbengine.git
cd dbengine
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e .
Prerequisites
For PostgreSQL server management features, you'll need:
- Docker: Required for PostgreSQL server management utilities
# Install Docker (macOS)
brew install docker
# Install Docker (Ubuntu/Debian)
sudo apt-get update && sudo apt-get install docker.io
# Start Docker daemon
sudo systemctl start docker # Linux
# or use Docker Desktop on macOS/Windows
Code Quality
The project uses automated code quality tools:
# Format code
black src/ tests/
# Check imports
isort src/ tests/
# Lint code
flake8 src/ tests/
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
MIT License - see LICENSE file for details.
Project details
Release history Release notifications | RSS feed
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 dbengine-1.0.1.tar.gz.
File metadata
- Download URL: dbengine-1.0.1.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45af2c48e989a8c351695b8a58dc419ba8704df89711611b6ce98191ec0d579c
|
|
| MD5 |
036ef82ac657c615bf8cc9e4a19324f5
|
|
| BLAKE2b-256 |
06c88716470fe58613a418282a887e07d49fb321858477c2fcf394de0f04b619
|
Provenance
The following attestation bundles were made for dbengine-1.0.1.tar.gz:
Publisher:
python-publish.yml on tomemgouveia/dbengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbengine-1.0.1.tar.gz -
Subject digest:
45af2c48e989a8c351695b8a58dc419ba8704df89711611b6ce98191ec0d579c - Sigstore transparency entry: 488179444
- Sigstore integration time:
-
Permalink:
tomemgouveia/dbengine@9dfda987442065352351961f31a6531e0d162eb1 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/tomemgouveia
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9dfda987442065352351961f31a6531e0d162eb1 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dbengine-1.0.1-py2.py3-none-any.whl.
File metadata
- Download URL: dbengine-1.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 22.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e6768d1f919d4642e330e841dc7c204b9f9da1afbd0b418b3ae36b25f99781
|
|
| MD5 |
01bbaaba67c6e1aadb9eff3575fa5c43
|
|
| BLAKE2b-256 |
33c617817fb74a1520a26c1ed8998c84ebb5a8fd8fe1b52a9e9f44cb13edb299
|
Provenance
The following attestation bundles were made for dbengine-1.0.1-py2.py3-none-any.whl:
Publisher:
python-publish.yml on tomemgouveia/dbengine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbengine-1.0.1-py2.py3-none-any.whl -
Subject digest:
06e6768d1f919d4642e330e841dc7c204b9f9da1afbd0b418b3ae36b25f99781 - Sigstore transparency entry: 488179462
- Sigstore integration time:
-
Permalink:
tomemgouveia/dbengine@9dfda987442065352351961f31a6531e0d162eb1 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/tomemgouveia
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9dfda987442065352351961f31a6531e0d162eb1 -
Trigger Event:
release
-
Statement type: