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.1.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.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

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

Hashes for ff_storage-0.2.1.tar.gz
Algorithm Hash digest
SHA256 30a89cba07560e14ae7dc2814dff31eb71304478379c1cf8f47f88a541660567
MD5 517a30c1b6858e65512d8b4831e40794
BLAKE2b-256 00fb08d483a918b67f09ea4fc4d85a7dd705aa644a31e452279f2061d1017c61

See more details on using hashes here.

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

Hashes for ff_storage-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a89a1c0ab6b0e61e8697b2ba8514d34317c6dc63b22ef3a858665d942b1ff9da
MD5 84f4e1a41b3e432ab4530b39ed8f9575
BLAKE2b-256 036aec18d4dc21ee4da2ab5c7bf36d25752cb92a3087b74a4ea9126367e099c0

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