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
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72ced96ad196b010dc212195f738057c4951c84c74c4394186c87a8c26f31a4a
|
|
| MD5 |
ae3f821239056178a801895f3a1414d6
|
|
| BLAKE2b-256 |
e65263065afb15560163652b3d1ab8ada11ce7a0b918e0785a26ee523c211845
|
Provenance
The following attestation bundles were made for muscles_sql-1.0.0.tar.gz:
Publisher:
release.yml on butkoden/muscles-sql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
muscles_sql-1.0.0.tar.gz -
Subject digest:
72ced96ad196b010dc212195f738057c4951c84c74c4394186c87a8c26f31a4a - Sigstore transparency entry: 2258770478
- Sigstore integration time:
-
Permalink:
butkoden/muscles-sql@905e33a245133e6dea350c533496409d59cb3811 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/butkoden
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@905e33a245133e6dea350c533496409d59cb3811 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32d407dc387bfd222b5d2a98032d735fe0b23aea0167e16c38ba37297d7f488b
|
|
| MD5 |
b2cf7de83d43e69efaf648f7dadcfee3
|
|
| BLAKE2b-256 |
a6ee2686a2600c26987682c733f0ee3a238130dd04594c263278ae3d74699edc
|
Provenance
The following attestation bundles were made for muscles_sql-1.0.0-py3-none-any.whl:
Publisher:
release.yml on butkoden/muscles-sql
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
muscles_sql-1.0.0-py3-none-any.whl -
Subject digest:
32d407dc387bfd222b5d2a98032d735fe0b23aea0167e16c38ba37297d7f488b - Sigstore transparency entry: 2258770569
- Sigstore integration time:
-
Permalink:
butkoden/muscles-sql@905e33a245133e6dea350c533496409d59cb3811 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/butkoden
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@905e33a245133e6dea350c533496409d59cb3811 -
Trigger Event:
release
-
Statement type: