Framework Primitives¶
Core primitives in vertebra.framework for dependency injection, security guards, OpenAPI and AsyncAPI specs, live state sync, typed RPC procedures, email, and key-value stores. See Framework Features for usage examples.
Dependency Injection¶
Provide and Container compile a static dependency graph at route registration time. They support sync, async, and generator-scoped dependencies without per-request reflection.
Provide
¶
Bases: Struct
Dependency provider descriptor with scope, generator teardown, and type metadata.
Attributes:
| Name | Type | Description |
|---|---|---|
dependency | Callable[..., Any] | |
scope | Scope | Default: 'request' |
sync_to_thread | bool | Default: False |
use_cache | bool | Default: True |
parameter_names | tuple[str, ...] | Default: () |
param_bindings | tuple[ParamBinding, ...] | Default: () |
return_type | type[Any] | None | Default: None |
is_async | bool | Default: False |
is_generator | bool | Default: False |
is_async_generator | bool | Default: False |
value
¶
Construct a singleton provider returning a pre-built constant value.
Container
¶
Scoped dependency injection container executing a compiled DependencyGraph.
Attributes:
| Name | Type | Description |
|---|---|---|
graph | DependencyGraph | Return the underlying DependencyGraph. |
singletons | dict[str, Any] | Return the active singleton instance cache. |
create_child
¶
Create a child container inheriting un-overridden singletons while isolating layer overrides.
scope
¶
Create a synchronous or asynchronous request scope context manager.
resolve_sync
¶
resolve_sync(
key_or_type,
*,
request=None,
request_cache=None,
exit_stack=None,
extra_context=None,
)
Synchronously resolve a dependency key or type and its transitive dependencies.
resolve
¶
resolve(
key_or_type,
*,
request=None,
request_cache=None,
exit_stack=None,
async_exit_stack=None,
extra_context=None,
)
Resolve a dependency key or type and its transitive dependencies.
Security & Guards¶
Principal
¶
Bases: Struct
Authenticated subject identity with roles, scopes, capabilities, and tenant context.
Attributes:
| Name | Type | Description |
|---|---|---|
subject | str | |
email | str | None | Default: None |
tenant_id | str | None | Default: None |
roles | frozenset[str] | |
scopes | frozenset[str] | |
capabilities | frozenset[str] | |
claims | dict[str, Any] |
SecurityConfig
¶
Bases: Struct
Aggregate security configuration for Vertebra and Litestar applications.
Attributes:
| Name | Type | Description |
|---|---|---|
jwt_issuer | str | None | Default: None |
jwt_audience | str | None | Default: None |
enable_iap | bool | Default: False |
csrf | CsrfConfig | None | Default: None |
rate_limit | RateLimitConfig | None | Default: None |
exclude_paths | tuple[str, ...] | Default: ('/health', '/healthz', '/readyz') |
Guard
¶
Security guard evaluating a SecurityContext.
requires
¶
Construct a compiled guard with required roles, scopes, capabilities, or tenants.
OpenAPI & AsyncAPI¶
OpenAPIConfig
¶
Bases: Struct
OpenAPI 3.1/3.2 document and multi-backend interactive UI configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
title | str | Default: 'Vertebra API' |
version | str | Default: '0.1.0' |
description | str | Default: '' |
openapi_version | str | Default: '3.1.0' |
schema_path | str | Default: '/openapi.json' |
default_docs | DocsBackendType | Default: 'scalar' |
enabled_docs | tuple[DocsBackendType, ...] | Default: ('scalar', 'swagger', 'asyncapi') |
scalar | ScalarDocsConfig | |
swagger | SwaggerDocsConfig | |
redoc | RedocDocsConfig | |
elements | ElementsDocsConfig | |
rapidoc | RapiDocDocsConfig | |
asyncapi | AsyncAPIDocsConfig |
OpenAPISpecBuilder
¶
Constructs OpenAPI 3.1/3.2 documents from route metadata and msgspec.Struct types.
Attributes:
| Name | Type | Description |
|---|---|---|
config | OpenAPIConfig | Return the OpenAPIConfig. |
AsyncAPIConfig
¶
Bases: Struct
AsyncAPI 3.0.0 document configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
title | str | Default: 'Vertebra Realtime API' |
version | str | Default: '0.1.0' |
asyncapi_version | str | Default: '3.0.0' |
schema_path | str | Default: '/asyncapi.json' |
Live State & Procedures¶
LiveState
¶
Reactive server-client synchronized state object with LWW conflict resolution.
Attributes:
| Name | Type | Description |
|---|---|---|
state_id | int | Default: 0 |
compute_state_id
¶
Compute the deterministic 64-bit FNV-1a state identifier matching Rust state_id.
compute_field_id
¶
Compute the deterministic 32-bit FNV-1a field identifier matching Rust field_id.
drain_encoded_deltas
¶
Drain and encode all pending state deltas as MessagePack frames.
encode_sync_response
¶
Encode a full SYNC_RESPONSE frame for initial client hydration.
apply_delta
¶
Apply an incoming client or peer delta using HLC Last-Write-Wins resolution.
dispatch_action
¶
Execute a @live_action method from an ACTION_CALL frame and return ACTION_RESULT.
ProcedureRouter
¶
Registry and dispatcher for typed RPC procedures with hierarchical DI and guards.
Attributes:
| Name | Type | Description |
|---|---|---|
prefix | str | Return the RPC URL prefix. |
dependencies | dict[str, Any] | Return router-level dependency providers. |
guards | tuple[Callable[..., Any], ...] | Return router-level guard callables. |
procedures | dict[str, Procedure] | Return registered procedures keyed by name. |
register
¶
Register a Procedure, ProcedureRouter, or Controller with procedure methods.
query
¶
Decorator defining and registering a query procedure on this router.
mutation
¶
Decorator defining and registering a mutation procedure on this router.
subscription
¶
Decorator defining and registering a subscription procedure on this router.
call
¶
Invoke a registered procedure by name with guard enforcement and dependency injection.
from_proto
¶
from_proto(
proto_source,
handlers=None,
*,
runtime_types=None,
prefix=None,
service_name=None,
dependencies=None,
guards=None,
container=None,
)
Create a ProcedureRouter populated from a .proto v3 schema and optional handler mapping.
Email & Stores¶
EmailService
¶
Transactional email dispatcher supporting direct and background queue-backed delivery.
Attributes:
| Name | Type | Description |
|---|---|---|
config | EmailConfig | Return the active EmailConfig. |
transport | EmailTransport | Return the active EmailTransport. |
queue_service | QueueService | None | Return the bound QueueService if configured. |
outbox | tuple[EmailMessage, ...] | Return captured messages if the transport supports outbox recording. |
KeyValueStore
¶
Bases: BaseKeyValueStore
Lock-free monotonic TTL store with optional Valkey/Redis backing and RESP3 invalidation.