Fenixflow storage package for database and file operations
Project description
ff-storage
Database and object storage operations for Fenixflow applications.
Features
- Database Connections: PostgreSQL and MySQL with connection pooling
- Multi-Database Support: Consistent API for PostgreSQL and MySQL
- Migration Management: Simple SQL file-based migrations
- Object Storage: Async local filesystem and S3/S3-compatible storage
- Streaming Support: Read/write large files without loading into memory
- Atomic Operations: Safe file writes with temp file + rename
- Metadata Management: Store and retrieve metadata with objects
- Base Models: Dataclass-based models with UUID and timestamp support
- Query Builder: SQL query construction utilities
Installation
# From GitLab
pip install git+https://gitlab.com/fenixflow/fenix-packages.git@main#subdirectory=ff-storage
# Local development
pip install -e .
Usage
PostgreSQL Connection
from ff_storage import PostgresPool
# Create connection pool
db = PostgresPool(
dbname="fenix_db",
user="fenix",
password="password",
host="localhost",
port=5432,
pool_size=20
)
# Connect and execute query
db.connect()
results = db.read_query("SELECT * FROM documents WHERE status = %s", {"status": "active"})
# Execute with RETURNING
new_id = db.execute_query(
"INSERT INTO documents (title) VALUES (%s) RETURNING id",
{"title": "New Document"}
)
# Return connection to pool
db.close_connection()
MySQL Connection
from ff_storage import MySQLPool
# Create connection pool
db = MySQLPool(
dbname="fenix_db",
user="root",
password="password",
host="localhost",
port=3306,
pool_size=10
)
# Connect and execute query
db.connect()
results = db.read_query("SELECT * FROM documents WHERE status = %s", {"status": "active"})
# Execute INSERT (returns last insert ID)
new_id = db.execute_query(
"INSERT INTO documents (title) VALUES (%s)",
{"title": "New Document"}
)
# Check open connections
open_conns = db.get_open_connections()
# Return connection to pool
db.close_connection()
Migrations
from ff_storage.db.migrations import MigrationManager
# Setup migration manager
manager = MigrationManager(db_connection, "./migrations")
# Run all pending migrations
manager.migrate()
Object Storage
from ff_storage import LocalObjectStorage, S3ObjectStorage
import asyncio
async def main():
# Local filesystem storage
local = LocalObjectStorage("/var/data/documents")
await local.write("docs/report.pdf", pdf_bytes, {"content-type": "application/pdf"})
data = await local.read("docs/report.pdf")
exists = await local.exists("docs/report.pdf")
files = await local.list_keys(prefix="docs/")
# S3 storage (AWS or S3-compatible)
s3 = S3ObjectStorage(
bucket="fenix-documents",
region="us-east-1"
)
await s3.write("docs/report.pdf", pdf_bytes)
data = await s3.read("docs/report.pdf")
# Stream large files
async for chunk in s3.read_stream("large_file.bin", chunk_size=8192):
process_chunk(chunk)
asyncio.run(main())
Database Classes
SQL Base Class
Abstract base providing interface for all SQL operations:
connect(): Establish connectionread_query(): Execute SELECT queriesexecute(): Execute INSERT/UPDATE/DELETEexecute_query(): Execute with RETURNINGexecute_many(): Batch operations- Transaction management methods
PostgreSQL
Postgres: Direct connection without poolingPostgresPool: Connection pooling for production use
MySQL
MySQL: Direct connection without poolingMySQLPool: Connection pooling for production use
Testing
# Run tests
pytest tests/
# With coverage
pytest --cov=ff_storage tests/
License
Proprietary - Fenixflow Internal Use Only
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
ff_storage-0.2.1.tar.gz
(25.6 kB
view details)
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 ff_storage-0.2.1.tar.gz.
File metadata
- Download URL: ff_storage-0.2.1.tar.gz
- Upload date:
- Size: 25.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30a89cba07560e14ae7dc2814dff31eb71304478379c1cf8f47f88a541660567
|
|
| MD5 |
517a30c1b6858e65512d8b4831e40794
|
|
| BLAKE2b-256 |
00fb08d483a918b67f09ea4fc4d85a7dd705aa644a31e452279f2061d1017c61
|
File details
Details for the file ff_storage-0.2.1-py3-none-any.whl.
File metadata
- Download URL: ff_storage-0.2.1-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.2.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a89a1c0ab6b0e61e8697b2ba8514d34317c6dc63b22ef3a858665d942b1ff9da
|
|
| MD5 |
84f4e1a41b3e432ab4530b39ed8f9575
|
|
| BLAKE2b-256 |
036aec18d4dc21ee4da2ab5c7bf36d25752cb92a3087b74a4ea9126367e099c0
|