FastAPI API¶
Requires pip install ontosql[fastapi]. Beta-experimental tier — see SPECS.md. Not safe on public networks without auth — SECURITY.md.
OntoRouter¶
ontosql.fastapi.router.OntoRouter ¶
Register CRUD routes for OntoModel entities with content negotiation.
Requires onto_async_session_lifespan on the host app (AsyncSessionDep).
Not safe for public internet without dependencies authn/authz — see
docs/guides/production-router.md.
Lifespan and dependencies¶
ontosql.fastapi.deps.onto_async_session_lifespan ¶
Store async engine and maps on app.state for AsyncSessionDep.
ontosql.fastapi.deps.onto_session_lifespan ¶
Store engine and maps on app.state for sync session dependencies.
ontosql.fastapi.deps.AsyncSessionDep
module-attribute
¶
ontosql.fastapi.deps.SessionDep
module-attribute
¶
ontosql.fastapi.deps.get_async_onto_session
async
¶
Yield an AsyncOntoSession bound to app.state async engine and maps.
ontosql.fastapi.deps.get_onto_session ¶
Yield a synchronous OntoSession bound to app.state engine and maps.
Content negotiation¶
ontosql.fastapi.negotiate.negotiate_onto_response ¶
Return a FastAPI Response based on the request Accept header.
Falls back to JSON-LD if data supports to_jsonld(), otherwise JSON.
RDF responses¶
ontosql.fastapi.responses.JSONLDResponse ¶
ontosql.fastapi.responses.TurtleResponse ¶
Bases: RDFResponse
ontosql.fastapi.responses.NTriplesResponse ¶
Bases: RDFResponse
ontosql.fastapi.responses.RDFXMLResponse ¶
Bases: RDFResponse
ontosql.fastapi.responses.RDFResponse ¶
Bases: Response
RDF serialization response (turtle, n-triples, rdf+xml, json-ld).
OpenAPI helpers¶
ontosql.fastapi.openapi.enrich_openapi_schema ¶
Return OpenAPI schema with semantic hints for registered OntoModel types.
ontosql.fastapi.openapi.install_onto_openapi ¶
Replace app.openapi with semantic-enriched schema generation.
Production patterns¶
List GET routes default to application/ld+json when no Accept header is sent (same as item GET). Pass Accept: application/json for a plain JSON array.
See production-router.md and FastAPI quick start.