Decorators and Markers¶
Module Summary¶
This page lists every public decorator and dependency marker that the framework exposes. Each entry includes a short usage hint plus a pointer to the topic guide that covers the broader pattern.
Decorators¶
@context¶
- @context(func_or_key=None, *, inherit_context=False, serialize=False, serializer=None)
Registers a context function on a page module (page.py).
The first positional argument is func_or_key.
Called bare as @context it receives the decorated function and merges its returned dict into the template context.
Called as @context("greeting") it receives a key string and binds the function’s return value to that key.
Pass inherit_context=True to publish the value to every descendant page.
Pass serialize=True to expose the return value to the browser under window.Next.context.
The value must be JSON-encodable by the active serializer.
See Serialization for the Browser for the contract.
Pass serializer= to route that key through a custom JsContextSerializer.
@component.context¶
- @component.context(func_or_key=None, *, serialize=False, serializer=None)
Registers a component context function inside component.py.
The first positional argument is func_or_key.
Called bare as @component.context it merges the function’s returned dict into the component template scope.
Called as @component.context("greeting") it binds the function’s return value to that key.
Pass serialize=True to include the return value in window.Next.context.
The value must be JSON-encodable by the active serializer, the same contract documented under Serialization for the Browser.
Pass serializer= to route that key through a custom JsContextSerializer.
@action¶
- @action(name, *, form_class=None, namespace=None)
Registers a form action handler under name.
name is the first positional argument and must be unique across the project.
Pass form_class= for forms that need validation.
Pass namespace= to scope short names, which prefixes the stored key with "<namespace>:".
Dependency Markers¶
Depends¶
- class next.deps.Depends(dependency: object | None = None)[source]
Mark a parameter as a dependency resolved by the resolver.
Use as a default parameter value. Depends(“name”) resolves a registered callable by name. Depends(callable) calls a factory with DI-resolved arguments. Depends(value) injects a constant value directly. Depends() resolves by the parameter name.
Default argument that injects a named, callable, or constant dependency. See Dependency Injection for all resolution modes and the registration API.
Context¶
- class next.pages.Context(source: object | None = None, *, default: object = <object object>)[source]
Mark a parameter default so the value is taken from context_data.
An empty Context() reads the parameter name from context_data. A string source reads that context key. A callable source is called with DI-resolved arguments. Any other object becomes a constant. The default keyword supplies a fallback when the context key is missing.
- default: object
Default argument that reads a value from the current page context data by key. See Context for all source forms and the resolution order.
DUrl¶
- class next.urls.markers.DUrl[source]
Annotation for a captured URL path parameter with optional type coercion.
Use DUrl[SomeType] to read the captured segment that matches the parameter name and coerce it. Use DUrl[“param”] to read a named segment without coercion. Use DUrl[“param”, SomeType] to read a named segment and coerce it, which is the form to reach for when the parameter name differs from the captured segment name.
- classmethod __class_getitem__(item: object) object[source]
Build the marker for the type, named-key, and named-key-with-type forms.
A plain type follows the standard generic path. A string, or a (string, type) tuple, is wrapped so the provider can read the captured segment by an explicit name rather than the parameter name.
Type annotation that injects the captured URL parameter with the matching name.
Pass a generic argument to coerce the value to a type.
The named form DUrl["key"] targets a segment by name and delivers it in string form, without extra type coercion.
The named-and-typed form DUrl["key", Type] targets a segment by name and coerces the value to Type.
See Dependency Injection for the supported coercion types.
DQuery¶
- class next.urls.markers.DQuery[source]
Annotation marker for a request.GET parameter.
Use DQuery[str], DQuery[int], DQuery[bool], or DQuery[float] for scalar values, or DQuery[list[T]] for multi-value parameters. The list form accepts the plain repeated form ?brand=a&brand=b, the qs-style bracket suffix ?brand[]=a&brand[]=b emitted by axios and other front-end clients, and the comma-delimited form ?brand=a,b produced by qs.stringify with the comma array format. The provider returns the parameter default when the key is absent, or None when no default is given.
Type annotation that injects a query string value.
Supports DQuery[str], DQuery[int], DQuery[bool], DQuery[float], DQuery[UUID], DQuery[Decimal], DQuery[date], and DQuery[datetime].
DQuery[list[T]] accepts any of those scalars as the element type.
DForm¶
- class next.forms.markers.DForm[source]
Annotation for injecting a form instance by class.
Use as DForm[MyForm] or DForm[“MyForm”].
Type annotation that injects a form instance during action dispatch.
FormProvider¶
- class next.forms.markers.FormProvider[source]
Inject a form instance matching the annotation or the parameter name form.
- priority = 40
Provider class for injecting bound forms.
Matches a DForm[...] annotation or any parameter named form.
DDependencyBase¶
- class next.deps.DDependencyBase[source]
Shared base for annotation markers such as DForm and DUrl.
Base class for custom DI markers. Subclass with a parameterised generic to declare a typed parameter.
RegisteredParameterProvider¶
- class next.deps.RegisteredParameterProvider[source]
Auto-registered base used by built-in providers shipped with the framework.
- resolver: ClassVar[DependencyResolver]
Build keyword-arguments for a callable by consulting registered providers.
- priority: ClassVar[int] = 100
- classmethod __init_subclass__(**kwargs: object) None[source]
Track concrete subclasses for lazy instantiation by the resolver.
- abstractmethod can_handle(param: inspect.Parameter, context: ResolutionContext) bool[source]
Return True when this provider owns the parameter.
- abstractmethod resolve(param: inspect.Parameter, context: ResolutionContext) object[source]
Return the resolved value for the parameter.
Base class for custom parameter providers.
Implement can_handle and resolve to plug a custom data source into the resolver.
See Also¶
See also
Context for @context semantics.
Components for @component.context.
Actions for @action handlers.
Dependency Injection for the resolver and providers.