Skip to content

settings — API Reference ​

python
from fastapi_viewsets.conf import settings

settings is the one instance of fastapi_viewsets.conf.Settings. The application assigns its attributes once, before any viewset class is decorated with route_viewset.

AttributeTypeDefaultDescription
viewsets_context_processorslist[ContextProcessor][]Build each request's context; see Context Processors
viewsets_context_json_encodertype[json.JSONEncoder] | NoneNoneEncodes context values that cross the Celery boundary
viewsets_context_json_decodertype[json.JSONDecoder] | NoneNoneDecodes them on the worker
viewsets_command_middlewarelist[CommandMiddleware][]Wraps every request-facing execution; see Command Middleware
viewsets_idempotency_ttlfloat86400Seconds an outcome recorded by Idempotency is kept; see Idempotent Calls
viewsets_idempotency_lock_ttlfloat600Seconds a running record of Idempotency is kept after it was last extended; the process running the call extends it every third of this time
viewsets_auth_processorslist[AuthBackend][]Tried in order to resolve context.user; see Authentication
default_action_configurationdict[Any, Any]{}The configuration every action starts from; see Action Configuration
default_list_shapestr"plain"The list shape of a viewset that states none: "plain", "paginated" or "cursor"
viewsets_register_muxwsboolTrueWhether a viewset is published on muxws when neither it nor its endpoint says; see muxws
viewsets_tag_nameCallable[[type], str] | NoneNoneReturns the OpenAPI tag of a viewset class; an empty string gives no tag. None uses default_tag_name(cls) (ProfileEmailViewSet → Profile email); see Automatic OpenAPI tags
viewsets_security_schemeSecurityBase | NoneNoneA FastAPI security scheme added to every route, for the OpenAPI "Authorize" flow only
viewsets_event_storeEventStore | NoneNoneThe event store; None is one MemoryEventStore per process. A deployment of more than one process sets a RedisEventStore in every process; see Events
viewsets_event_authorizerslist[EventAuthorizer][]Decide whether a caller may follow a topic, in list order; the first True admits, the first False refuses, no decision refuses
viewsets_event_delivery_filterslist[DeliveryFilter][]Decide per subscription and per event whether a push is sent, and per poll and per event whether the poll answers the event; False skips the socket or leaves the event out of the poll answer, an exception counts as True
viewsets_event_listenerslist[EventListener][]Called with every event, in list order, in every process whose store is started and before the event's pushes, whether or not the process holds a subscription of its topic; a listener that raises is logged and the next one runs
viewsets_event_log_sizeint32Events kept per topic for poll
viewsets_event_log_ttlfloat60.0Seconds a topic's log is kept after its last event; the topic's rev is kept without expiry
viewsets_event_push_timeoutfloat2.0Seconds the delivery filters and peer.notify() of one push to one socket may take together; notify() queues the push and does not wait for the socket
viewsets_event_max_subscriptionsint256Topics one socket may hold, and cursors one poll may carry
viewsets_event_poll_after_msint0poll_after_ms of every poll answer, the shortest interval a client polls at
viewsets_event_reauthorize_afterfloat | None300.0Seconds after which a push to a subscription of a scoped topic runs the topic's gate again with the subscribing request: the push is sent when the gate answers the subscription's store topic, a refusal (an HTTPException of a status from 400 to 499 other than 429) or another store topic removes the subscription and skips the push, another exception, a 429 or 5xx included, skips the push. None never; unscoped topics are not affected

ContextProcessor is Callable[[Request, Any], Awaitable[dict[str, Any]]]; a processor may also take a config keyword, see Action Configuration.

viewsets_register_muxws, viewsets_tag_name and viewsets_security_scheme are read when a viewset is decorated, and so are the modifies_response_shape and openapi_parameters of the entries of viewsets_command_middleware: changed later, they do not reach viewsets already decorated. The middleware list itself, the processors, the auth backends, the idempotency TTLs and the viewsets_event_* settings are read on every use.

Other public classes ​

NameModuleDescription
SaveStatefastapi_viewsets.save_state.save_stateBase of a viewset that loads and saves its state around each call: load_state(), save_state(); see ViewSet Lifecycle
SaveStateRedisfastapi_viewsets.save_state.save_stateSaveState backed by one Redis key, save_state_redis_key
SerializeState, SerializeStateSlotsfastapi_viewsets.save_state.serialize_stateserialize_state() / deserialize_state(state); the second serialises the slots __slots__ names
NOT_FOUND_RESPONSE, BULK_NOT_FOUND_RESPONSE, CURSOR_ERROR_RESPONSES, SUBSCRIBE_ERROR_RESPONSES, POLL_ERROR_RESPONSES, VIEWSET_ERROR_RESPONSES, with_error_responses(responses), error_entry(status, description, *errors, as_ref=False, **named_errors), merge_responses(*responses)fastapi_viewsets.response_classeserror_entry builds an OpenAPI responses entry with the body ApiErrorBody and one example per exception, merge_responses merges entries by status. The OpenAPI responses entries of a viewset's error responses, built with them, each with the schema ApiErrorBody and examples: the endpoints' own (the 404 of the endpoints that address items by pk or by the keys of the body, the cursor codes of the list endpoint, kept on a viewset serving the cursor shape, the 422 of the events subscribe and poll), and the 422, 500 and default route_viewset attaches to every endpoint under the endpoint's own entries; see Documenting endpoints
ApiErrorBody, ApiFieldError, install_error_handlers(app), error_body(error), error_response(error), error_status(error), field_errors(errors)fastapi_viewsets.error_responsesThe error body of every error response and the functions that build it; see Error codes. For Django's ValidationError, error_status returns 422 and error_body a validation_failed body; see Django's ValidationError
FIELD_ERROR_PARAMSfastapi_viewsets, fastapi_viewsets.error_responsesThe field error codes the package declares, Mapping[str, tuple[str, ...]] from the full code to the names of its params; see Field error codes
PYDANTIC_ERROR_TYPES, CUSTOM_ERROR_CODEfastapi_viewsets.error_responsesThe error types pydantic declares (frozenset of the values of pydantic_core.core_schema.ErrorType); pydantic.custom_error, the code of a custom error type without a namespace
ERROR_NAMESPACE, ERROR_NAMESPACE_PYDANTIC, ERROR_NAMESPACE_DJANGOfastapi_viewsetsThe namespaces of the package's error codes; see Namespaces

Released under the MIT License.