sirenity
sirenity compiles a complete OpenAPI 3.1 document into a reusable Siren engine. At request
time, the engine turns application data and permissions into a Siren response with concrete links
and authorized actions.
Requires Python 3.12 or later.
Install
python -m pip install sirenity
For local development, install uv and use the locked environment:
UV_CACHE_DIR=.dump/uv-cache uv sync --locked --all-groups
make verify
Supported integrations
This task-oriented guide is generated from the same public source as docs/configuration.md.
Resolve one immutable configuration for every supported integration.
Install Sirenity with python -m pip install sirenity. The application supplies its OpenAPI
provider, capability policy, authentication, and already-executed operation results. Sirenity
owns compilation, source/public mount matching, normalized input placement, and Siren/error
translation. It does not dispatch application operations, infer policy, or require callers to
parse OpenAPI or inspect an adapter's engine.
Framework-neutral adapter
Create one configuration after application routes are registered. source_path is the mount
declared by OpenAPI; public_path is the mount exposed by Siren. Pass the result of the one
application execution to respond():
from example_project.permissions import siren_policy
from sirenity import SirenAdapterRequest, siren_configuration
example_configuration = siren_configuration(
openapi="example_project.api.openapi_schema",
source_path="/api",
public_path="/siren",
policy="example_project.permissions.siren_policy",
profiles=("sirenity.SirenStructuredFormProfile",),
)
example_adapter = example_configuration.adapter()
example_application_result = {
"example_resource_id": "example-resource-42",
"title": "Updated example resource",
}
example_response = example_adapter.respond(SirenAdapterRequest(
operation_id="update_example_resource",
status=200,
result=example_application_result,
base_url="https://api.example.com",
path_values={"example_resource_id": "example-resource-42"},
policy=siren_policy(
"update_example_resource",
200,
object(),
example_application_result,
),
))
Framework authentication and execution stay outside Sirenity. Adapter profiles are the public
extension point for optional representation metadata; policy is the extension point for
application authorization and exceptional representation selection. Contract and projection
failures raise SirenityError or SirenContractError at this direct boundary.
Standard Django installation
Add the public middleware loader after Django's conditional-response middleware. Django calls
the application view exactly once, while Sirenity negotiates JSON versus Siren and rewrites a
matched /siren request to the compiled /api route for dispatch:
MIDDLEWARE: list[str] = [
"django.middleware.http.ConditionalGetMiddleware",
"sirenity.SirenMiddleware",
]
SIRENITY: dict[str, str | list[str]] = {
"OPENAPI": "example_project.api.openapi_schema",
"SOURCE_PATH": "/api",
"PUBLIC_PATH": "/siren",
"POLICY": "example_project.permissions.siren_policy",
"PROFILES": ["sirenity.SirenStructuredFormProfile"],
}
Mount the application's normal JSON routes below /api; no duplicate Siren URL configuration
is needed. Django owns authentication, views, and response creation. The middleware owns only
matched JSON/Siren negotiation and preserves structured application errors. A settings mapping
creates a fresh configuration for each Django startup, autoreload process, and override_settings
middleware construction. A supplied SirenConfiguration retains its exact caller-owned lifecycle;
tests should construct middleware inside the matching settings lifecycle.
Shared Django and MCP composition
Hosts that expose standard Django middleware and MCP from the same process should construct one
configuration, assign that exact value to SIRENITY, and pass it to siren_mcp. MCP
operations include the compiled HTTP method and encoded same-origin source dispatch path;
arguments are normalized into body, query, header, cookie, and path values before the
caller-owned Django or WSGI executor dispatches once:
from example_project.execution import ExampleMcpExecutor
from sirenity import SirenMcpInvocation, siren_configuration, siren_mcp
example_configuration = siren_configuration(
openapi="example_project.api.openapi_schema",
source_path="/api",
public_path="/siren",
policy="example_project.permissions.siren_policy",
profiles=("sirenity.SirenStructuredFormProfile",),
)
MIDDLEWARE = ["sirenity.SirenMiddleware"]
SIRENITY = example_configuration
example_mcp = siren_mcp(example_configuration, executor=ExampleMcpExecutor())
example_result = example_mcp.invoke(SirenMcpInvocation(
operation_id="update_example_resource",
arguments={
"example_resource_id": "example-resource-42",
"title": "Updated example resource",
"metadata": {"source": "example"},
"example_page": 2,
"example_trace": "example-trace",
"example_session": "example-session",
},
))
if example_result.is_error:
raise RuntimeError(example_result.structured_content["detail"])
example_failure = example_mcp.invoke(SirenMcpInvocation(
operation_id="update_example_resource",
arguments={
"example_resource_id": "example-resource-42",
"title": "Invalid example resource",
"metadata": "not-an-object",
"example_trace": "example-trace",
},
))
example_error = example_failure.structured_content if example_failure.is_error else None
The MCP host owns SDK registration and lifecycle. Register example_mcp.tools() and retain
example_mcp.catalogue_fingerprint; when a new configuration lifecycle changes the fingerprint,
register the new catalogue and emit the host's native tools/list_changed notification. Hosts
without that notification reconnect or restart after deployment. Sirenity never creates the MCP
server, stores credentials, retries execution, or mutates projected documents.
All three journeys use only published sirenity root imports. The generated public reference is
the compatibility surface; framework- or protocol-specific behavior beyond these seams belongs in
caller adapters and policies.
Documentation
Guides are generated from marked public modules. Run make docs after changing public guidance.
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 sirenity-7.0.1.tar.gz.
File metadata
- Download URL: sirenity-7.0.1.tar.gz
- Upload date:
- Size: 116.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4d0da7952959706051d211dcfa889570a73fec84b4e7e8c6281142c0f060c99
|
|
| MD5 |
7b5fb5c72c539e84ac4bb5cb77a55b8b
|
|
| BLAKE2b-256 |
c6f2dddca8df6375c1c1b4238ab089627dd5078fbb360305afa118f4f8fc3ce3
|
Provenance
The following attestation bundles were made for sirenity-7.0.1.tar.gz:
Publisher:
release.yml on szpak-dev/sirenity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sirenity-7.0.1.tar.gz -
Subject digest:
c4d0da7952959706051d211dcfa889570a73fec84b4e7e8c6281142c0f060c99 - Sigstore transparency entry: 2550131673
- Sigstore integration time:
-
Permalink:
szpak-dev/sirenity@d7bf34803a1d204c994d4c797146491d6f75ec19 -
Branch / Tag:
refs/tags/v7.0.1 - Owner: https://github.com/szpak-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d7bf34803a1d204c994d4c797146491d6f75ec19 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sirenity-7.0.1-py3-none-any.whl.
File metadata
- Download URL: sirenity-7.0.1-py3-none-any.whl
- Upload date:
- Size: 150.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb2d1bd21a9bcb14f6f13abfdff44730567a4ebaef43557fc3d8cc30306ce49
|
|
| MD5 |
a1b9040a19f501a0dffe8550fc7c180f
|
|
| BLAKE2b-256 |
d7d2a661ef3ea4d3ff496d2c0a56f5cd4834b9fdfabf9e0c27abfbf4b06c6587
|
Provenance
The following attestation bundles were made for sirenity-7.0.1-py3-none-any.whl:
Publisher:
release.yml on szpak-dev/sirenity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sirenity-7.0.1-py3-none-any.whl -
Subject digest:
3bb2d1bd21a9bcb14f6f13abfdff44730567a4ebaef43557fc3d8cc30306ce49 - Sigstore transparency entry: 2550131729
- Sigstore integration time:
-
Permalink:
szpak-dev/sirenity@d7bf34803a1d204c994d4c797146491d6f75ec19 -
Branch / Tag:
refs/tags/v7.0.1 - Owner: https://github.com/szpak-dev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@d7bf34803a1d204c994d4c797146491d6f75ec19 -
Trigger Event:
release
-
Statement type: