Skip to main content

Muscles SQL data layer for repositories, migrations and AI-first workflow.

Project description

Muscles SQL

Muscles SQL is a data layer package for SQL databases:

  • model-to-table mapping
  • engine and session management
  • repository CRUD and advanced query API (filters/operators/joins/aggregates)
  • transactions and Unit of Work (nested/savepoint/retry helpers)
  • migrations v2 commands (Alembic-compatible lazy-load)
  • inspect/doctor support with machine-readable diagnostics

Related Repositories

  • muscles - core schemas, actions, DI and canonical documentation.
  • muscles-documents - document metadata/state can use SQL persistence in applications.
  • muscles-ai - AI/RAG flows can use SQL-backed application state without making SQL generic storage.
  • muscles-otel - observability hooks around SQL-backed flows.
  • muscles-benchmarks - SQL transaction and mapping regression checks.

Quickstart

python -m venv .venv
source .venv/bin/activate
pip install muscles-sql

For local development with the test dependencies:

pip install -e ".[dev]"
pytest -q
muscles-sql doctor --url sqlite:///./app.db

Named SQL Connections

muscles-sql can manage multiple SQL connections without becoming a generic storage registry. The registry is SQL-only: it owns SQL connection configs, lazy SQLAlchemy EngineManager instances, sessions, inspect and doctor reports.

from muscles_sql import SqlConnectionConfig, SqlConnectionRegistry

registry = SqlConnectionRegistry(
    [
        SqlConnectionConfig(name="default", url="sqlite:///./app.db"),
        SqlConnectionConfig(name="analytics", url="sqlite:///./analytics.db", role="read"),
    ]
)

session = registry.session("analytics")
report = registry.inspect("analytics")

CLI diagnostics can read a JSON config:

{
  "connections": {
    "default": "sqlite:///./app.db",
    "analytics": {"url": "sqlite:///./analytics.db", "role": "read"}
  }
}
muscles-sql inspect --config sql-connections.json --connection analytics
muscles-sql doctor --config sql-connections.json --all

Diagnostic output uses safe URLs and does not print passwords from DSNs.

Advanced Query Example

from sqlalchemy import func
from muscles_sql import FilterClause, JoinClause, QuerySpec, SqlRepository

spec = QuerySpec(
    filters=[FilterClause("status", "eq", "active")],
    joins=[JoinClause(table=orders, on=users.c.id == orders.c.user_id)],
    select_columns=[users.c.id, func.count(orders.c.id).label("orders_total")],
    group_by=[users.c.id],
    order_by=[users.c.id.asc()],
)
rows = SqlRepository(session, users).aggregate(spec)

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

muscles_sql-1.0.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

muscles_sql-1.0.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file muscles_sql-1.0.1.tar.gz.

File metadata

  • Download URL: muscles_sql-1.0.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for muscles_sql-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b3b6fcfdb51ae71a87f40d2a7481c4b691c817c4d26fcbbc01afb29769573001
MD5 dadd447fb1d12d21ae9ba6d69c4b79ae
BLAKE2b-256 3097f271a86ea63a0c4026de0bdca8ccf8aab15a3783587e3909a55a48cd24ba

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sql-1.0.1.tar.gz:

Publisher: release.yml on butkoden/muscles-sql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file muscles_sql-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: muscles_sql-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for muscles_sql-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 430e0e4d717e71dc1bfba0c66b6968c00ef482e75909e3660c6362bcd1b0dbdf
MD5 33a69f833a41198ab91ffaa9c136b6f3
BLAKE2b-256 6c703e93180892dd05e5eb1617bd8d9851aa62aed25fee85e4bea71832e757f8

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sql-1.0.1-py3-none-any.whl:

Publisher: release.yml on butkoden/muscles-sql

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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