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.0.tar.gz (16.3 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.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: muscles_sql-1.0.0.tar.gz
  • Upload date:
  • Size: 16.3 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.0.tar.gz
Algorithm Hash digest
SHA256 72ced96ad196b010dc212195f738057c4951c84c74c4394186c87a8c26f31a4a
MD5 ae3f821239056178a801895f3a1414d6
BLAKE2b-256 e65263065afb15560163652b3d1ab8ada11ce7a0b918e0785a26ee523c211845

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sql-1.0.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: muscles_sql-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 32d407dc387bfd222b5d2a98032d735fe0b23aea0167e16c38ba37297d7f488b
MD5 b2cf7de83d43e69efaf648f7dadcfee3
BLAKE2b-256 a6ee2686a2600c26987682c733f0ee3a238130dd04594c263278ae3d74699edc

See more details on using hashes here.

Provenance

The following attestation bundles were made for muscles_sql-1.0.0-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