Skip to content

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
dependencyCallable[..., Any]
scopeScope
Default: 'request'
sync_to_threadbool
Default: False
use_cachebool
Default: True
parameter_namestuple[str, ...]
Default: ()
param_bindingstuple[ParamBinding, ...]
Default: ()
return_typetype[Any] | None
Default: None
is_asyncbool
Default: False
is_generatorbool
Default: False
is_async_generatorbool
Default: False

value

value(instance, *, return_type=None)

Construct a singleton provider returning a pre-built constant value.

Container

Scoped dependency injection container executing a compiled DependencyGraph.

Attributes:

Name Type Description
graphDependencyGraph

Return the underlying DependencyGraph.

singletonsdict[str, Any]

Return the active singleton instance cache.

create_child

create_child(overrides=None)

Create a child container inheriting un-overridden singletons while isolating layer overrides.

scope

scope(*, request=None, extra_context=None)

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.

close

close()

Close all singleton synchronous generator resources.

aclose

aclose()

Close all singleton asynchronous and synchronous generator resources.

Security & Guards

Principal

Bases: Struct

Authenticated subject identity with roles, scopes, capabilities, and tenant context.

Attributes:

Name Type Description
subjectstr
emailstr | None
Default: None
tenant_idstr | None
Default: None
rolesfrozenset[str]
scopesfrozenset[str]
capabilitiesfrozenset[str]
claimsdict[str, Any]

SecurityConfig

Bases: Struct

Aggregate security configuration for Vertebra and Litestar applications.

Attributes:

Name Type Description
jwt_issuerstr | None
Default: None
jwt_audiencestr | None
Default: None
enable_iapbool
Default: False
csrfCsrfConfig | None
Default: None
rate_limitRateLimitConfig | None
Default: None
exclude_pathstuple[str, ...]
Default: ('/health', '/healthz', '/readyz')

Guard

Security guard evaluating a SecurityContext.

requires

requires(*, roles=(), scopes=(), capabilities=(), tenants=(), any_role=False)

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
titlestr
Default: 'Vertebra API'
versionstr
Default: '0.1.0'
descriptionstr
Default: ''
openapi_versionstr
Default: '3.1.0'
schema_pathstr
Default: '/openapi.json'
default_docsDocsBackendType
Default: 'scalar'
enabled_docstuple[DocsBackendType, ...]
Default: ('scalar', 'swagger', 'asyncapi')
scalarScalarDocsConfig
swaggerSwaggerDocsConfig
redocRedocDocsConfig
elementsElementsDocsConfig
rapidocRapiDocDocsConfig
asyncapiAsyncAPIDocsConfig

OpenAPISpecBuilder

Constructs OpenAPI 3.1/3.2 documents from route metadata and msgspec.Struct types.

Attributes:

Name Type Description
configOpenAPIConfig

Return the OpenAPIConfig.

from_app

from_app(app, config=None)

Build an OpenAPISpecBuilder by inspecting routes on an App instance.

add_operation

add_operation(
    path,
    method,
    *,
    summary="",
    operation_id=None,
    response_schema=None,
    request_body_schema=None,
    tags=(),
)

Register an HTTP operation in the OpenAPI path map.

build

build()

Build and return the complete OpenAPI specification dictionary.

to_json

to_json()

Serialize the complete OpenAPI specification dictionary to formatted JSON.

AsyncAPIConfig

Bases: Struct

AsyncAPI 3.0.0 document configuration.

Attributes:

Name Type Description
titlestr
Default: 'Vertebra Realtime API'
versionstr
Default: '0.1.0'
asyncapi_versionstr
Default: '3.0.0'
schema_pathstr
Default: '/asyncapi.json'

Live State & Procedures

LiveState

Reactive server-client synchronized state object with LWW conflict resolution.

Attributes:

Name Type Description
state_idint
Default: 0

compute_state_id

compute_state_id(name)

Compute the deterministic 64-bit FNV-1a state identifier matching Rust state_id.

compute_field_id

compute_field_id(name)

Compute the deterministic 32-bit FNV-1a field identifier matching Rust field_id.

delete_field

delete_field(name)

Delete a reactive field and emit a FIELD_DELETE tombstone delta.

drain_deltas

drain_deltas()

Drain and return all pending state delta frames.

flush_deltas

flush_deltas()

Flush and return all pending state delta frames.

drain_encoded_deltas

drain_encoded_deltas()

Drain and encode all pending state deltas as MessagePack frames.

snapshot

snapshot()

Return a dictionary snapshot of all current reactive fields.

encode_sync_response

encode_sync_response()

Encode a full SYNC_RESPONSE frame for initial client hydration.

apply_delta

apply_delta(frame)

Apply an incoming client or peer delta using HLC Last-Write-Wins resolution.

dispatch_action

dispatch_action(frame)

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
prefixstr

Return the RPC URL prefix.

dependenciesdict[str, Any]

Return router-level dependency providers.

guardstuple[Callable[..., Any], ...]

Return router-level guard callables.

proceduresdict[str, Procedure]

Return registered procedures keyed by name.

register

register(target)

Register a Procedure, ProcedureRouter, or Controller with procedure methods.

query

query(
    *,
    name=None,
    input_type=None,
    output_type=None,
    dependencies=None,
    guards=None,
)

Decorator defining and registering a query procedure on this router.

mutation

mutation(
    *,
    name=None,
    input_type=None,
    output_type=None,
    dependencies=None,
    guards=None,
)

Decorator defining and registering a mutation procedure on this router.

subscription

subscription(
    *,
    name=None,
    input_type=None,
    output_type=None,
    dependencies=None,
    guards=None,
)

Decorator defining and registering a subscription procedure on this router.

call

call(name, payload=None, *, request=None, container=None)

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
configEmailConfig

Return the active EmailConfig.

transportEmailTransport

Return the active EmailTransport.

queue_serviceQueueService | None

Return the bound QueueService if configured.

outboxtuple[EmailMessage, ...]

Return captured messages if the transport supports outbox recording.

clear_outbox

clear_outbox()

Clear the captured outbox if the transport supports clear.

send

send(message)

Send message directly and return receipt message_id for backward compatibility.

send_with_receipt

send_with_receipt(message)

Send message directly and return full EmailReceipt.

send_batch

send_batch(messages)

Send batch of messages directly and return list of receipts.

enqueue

enqueue(message, *, delay_seconds=None)

Enqueue message for background worker delivery via QueueService.

enqueue_batch

enqueue_batch(messages, *, delay_seconds=None)

Enqueue multiple messages for background worker delivery.

close

close()

Close transport resources.

KeyValueStore

Bases: BaseKeyValueStore

Lock-free monotonic TTL store with optional Valkey/Redis backing and RESP3 invalidation.