Skip to main content

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 connection
  • read_query(): Execute SELECT queries
  • execute(): Execute INSERT/UPDATE/DELETE
  • execute_query(): Execute with RETURNING
  • execute_many(): Batch operations
  • Transaction management methods

PostgreSQL

  • Postgres: Direct connection without pooling
  • PostgresPool: Connection pooling for production use

MySQL

  • MySQL: Direct connection without pooling
  • MySQLPool: 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


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.2.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

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

ff_storage-0.2.2-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file ff_storage-0.2.2.tar.gz.

File metadata

  • Download URL: ff_storage-0.2.2.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

Hashes for ff_storage-0.2.2.tar.gz
Algorithm Hash digest
SHA256 70e7eec5150f6aa0513198916db7e6b23b3cdcf74bc2c9d45cfda39e67992509
MD5 2da41e88a42a1f04b3a5cd8787371103
BLAKE2b-256 68a1cedc2d809594ada0e3afd142d944a6d8b797726c4ec0a7174ea4304dc1eb

See more details on using hashes here.

File details

Details for the file ff_storage-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: ff_storage-0.2.2-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

Hashes for ff_storage-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 edd21c7974fc2902ff18dd0237690a3078060a7daabea0cdc35b8a02e904d7a1
MD5 aa820063f73d40c151f55458a74741fb
BLAKE2b-256 a632c1e738e211a31099c90ff0926346916504225f51847887ce0ee2763a44ea

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