Skip to main content

Muscles ASGI

muscles-asgi is the ASGI runtime for Muscles. It mirrors the WSGI API model while using ASGI scopes/events for async-capable servers.

Installation

pip install muscles-asgi

Canonical ecosystem install matrix is documented in core: Muscles installation matrix.

  • muscles - core contracts, routing, actions and canonical documentation.
  • muscles-wsgi - WSGI runtime with the same application model.
  • muscles-cli - CLI projection and developer commands.
  • muscles-sse - streaming projection for action results.
  • muscles-mcp - MCP projection that can bind to ASGI entrypoints.
  • muscles-benchmarks - ASGI regression and architecture checks.

Runtime

An app binds Context to AsgiStrategy:

from muscles import ApplicationMeta, Configurator, Context
from muscles.asgi import AsgiStrategy


class App(metaclass=ApplicationMeta):
    config = Configurator(obj={"main": {"HOST": "0.0.0.0", "PORT": "8080"}})
    context = Context(AsgiStrategy, params={})

    def run(self, *args):
        return self.context.execute(*args, shutup=True)

The ASGI package shares core schemas, route matching and OpenAPI generation with the other runtimes. It should not duplicate core itinerary code.

Schema Ownership

ASGI does not ship its own muscles.asgi.schema_ package. Framework schemas, columns, fields, request/response bodies, security objects and value objects belong to muscles.core.schema and should be imported from muscles:

from muscles import Column, JsonRequestBody, Model, String

REST API And Swagger

RestApi controllers/actions are projected into OpenAPI automatically. Generated paths include the external API prefix, so a mounted route such as /api/v1/bookings appears in Swagger exactly as clients must call it.

More detail: docs/openapi-and-routing.md. Backend pipeline features are documented in docs/backend-pipeline.md.

Application Inspection

Use mount_api(app, api) after declaring a RestApi to project ASGI routes into the core ApplicationRegistry. This makes routes visible to inspect_application(app) and CLI/doctor tooling without making the registry the HTTP dispatch source.

Call it after all controllers/actions are registered and before running inspection, doctor checks or generators. It is safe to call more than once: already projected routes are skipped. finalize_api(app, api) is an alias for projects that prefer a "declare, then finalize" bootstrap style. asgi_app(app) also calls mount_application_apis(app) once when the ASGI entrypoint is created, so APIs stored as attributes on the application are visible to runtime inspection without additional app-side adapters.

from muscles import inspect_application
from muscles.asgi import RestApi, finalize_api

app = App()
api = RestApi(name="Api", prefix="/api")

@api.init("/ping", method="get")
def ping(request):
    return {"ok": True}

finalize_api(app, api)
assert any(route["path"] == "/api/ping" for route in inspect_application(app)["routes"])

Request dispatch still uses the ASGI RestApi route tree. The projected routes are lightweight descriptors for tools that need to understand the application without knowing ASGI internals.

When the application has a neutral TelemetryProvider, ASGI records a muscles.server.dispatch span for matched routes with app, route, method and HTTP status attributes.

Action Bridge

ActionAsgiAdapter is an optional HTTP projection for Muscles actions. It keeps package-specific features out of ASGI routes: packages register normal core actions, and ASGI exposes only the actions explicitly allowed by the project.

from muscles.asgi import ActionAsgiAdapter

application = ActionAsgiAdapter.from_application(
    app,
    allowed_actions={"bookings.echo"},
)

The bridge accepts JSON POST /actions/<action-name> requests, executes through core ActionDispatcher(..., transport="http"), returns JSON for non-stream results, and returns application/problem+json for core action errors. Stream actions should be projected through muscles-sse.

Request Handling

Request parsing does not require cgi, multipart or python-magic at import time. Multipart form data uses the standard library path, and missing MIME detection falls back safely.

ASGI request execution is stateless on Context: request-specific data (scope, receive, send) is passed directly into context.execute(...) per request. The strategy keeps a persistent server lifecycle while request state stays isolated.

Development

Run tests with sibling packages on PYTHONPATH:

PYTHONPATH=../muscles/src:src python -m pytest -q

Production notes: docs/production.md.

Metadata

Release files for muscles-asgi 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for muscles-asgi 2.0.0
File Size Uploaded Provenance Actions
muscles_asgi-2.0.0.tar.gz 198.0 kB With provenance Details for muscles_asgi-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for muscles-asgi 2.0.0
File Interpreter ABI Platform Actions
muscles_asgi-2.0.0-py3-none-any.whl Python 3 none any Details for muscles_asgi-2.0.0-py3-none-any.whl

Total release size: 406.8 kB

Release files / muscles_asgi-2.0.0.tar.gz

Download URL muscles_asgi-2.0.0.tar.gz
Size 198.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cb5ec800095072abd6ee7b382d2ead1981cfac574841f007818f278a437c0e04
BLAKE2b-256 checksum
How to use checksums
b11667a956a1376397a6c0f1d91bbae79c7b000e0352adf785aacace3616de9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / muscles_asgi-2.0.0-py3-none-any.whl

Download URL muscles_asgi-2.0.0-py3-none-any.whl
Size 208.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
34314900067d5f60d5db41bc877b05c3ef1319e57b8a67e470293ca618a421f4
BLAKE2b-256 checksum
How to use checksums
08a73397a4a9d6d6e7b151e198aa74faa07f647a32d7de9e009a61eeb2db97df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for muscles-asgi 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for muscles_asgi-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page