waku
¶
WakuApplication
¶
WakuApplication(
*,
container: AsyncContainer,
registry: ModuleRegistry,
lifespan: Sequence[LifespanFunc | LifespanWrapper],
extension_registry: ExtensionRegistry,
)
Source code in src/waku/application.py
initialize
async
¶
WakuFactory
¶
WakuFactory(
root_module_type: ModuleType,
/,
context: dict[Any, Any] | None = None,
lifespan: Sequence[LifespanFunc] = (),
extensions: Sequence[
ApplicationExtension
] = DEFAULT_EXTENSIONS,
container_config: ContainerConfig | None = None,
)
Source code in src/waku/factory.py
create
¶
create() -> WakuApplication
Source code in src/waku/factory.py
DynamicModule
dataclass
¶
DynamicModule(
*,
providers: list[BaseProvider] = list(),
imports: list[ModuleType | DynamicModule] = list(),
exports: list[
type[object] | ModuleType | DynamicModule
] = list(),
extensions: list[ModuleExtension] = list(),
is_global: bool = False,
id: UUID = uuid4(),
parent_module: ModuleType,
)
Bases: ModuleMetadata
providers
class-attribute
instance-attribute
¶
List of providers for dependency injection.
imports
class-attribute
instance-attribute
¶
imports: list[ModuleType | DynamicModule] = field(
default_factory=list
)
List of modules imported by this module.
exports
class-attribute
instance-attribute
¶
exports: list[type[object] | ModuleType | DynamicModule] = (
field(default_factory=list)
)
List of types or modules exported by this module.
extensions
class-attribute
instance-attribute
¶
extensions: list[ModuleExtension] = field(
default_factory=list
)
List of module extensions for lifecycle hooks.
Module
¶
Module(module_type: ModuleType, metadata: ModuleMetadata)
Source code in src/waku/modules/_module.py
exports
instance-attribute
¶
exports: Final[
Sequence[type[object] | ModuleType | DynamicModule]
] = exports
module
¶
module(
*,
providers: Sequence[BaseProvider] = (),
imports: Sequence[ModuleType | DynamicModule] = (),
exports: Sequence[
type[object] | ModuleType | DynamicModule
] = (),
extensions: Sequence[ModuleExtension] = (),
is_global: bool = False,
) -> Callable[[type[_T]], type[_T]]
Decorator to define a module.
PARAMETER | DESCRIPTION |
---|---|
providers
|
Sequence of providers for dependency injection.
TYPE:
|
imports
|
Sequence of modules imported by this module.
TYPE:
|
exports
|
Sequence of types or modules exported by this module.
TYPE:
|
extensions
|
Sequence of module extensions for lifecycle hooks.
TYPE:
|
is_global
|
Whether this module is global or not.
TYPE:
|
Source code in src/waku/modules/_metadata.py
application
¶
WakuApplication
¶
WakuApplication(
*,
container: AsyncContainer,
registry: ModuleRegistry,
lifespan: Sequence[LifespanFunc | LifespanWrapper],
extension_registry: ExtensionRegistry,
)
Source code in src/waku/application.py
initialize
async
¶
cqrs
¶
NextHandlerType
module-attribute
¶
IPipelineBehavior
¶
Bases: ABC
, Generic[RequestT, ResponseT]
Interface for pipeline behaviors that wrap request handling.
handle
abstractmethod
async
¶
handle(
request: RequestT,
next_handler: NextHandlerType[RequestT, ResponseT],
) -> ResponseT
Handle the request and call the next handler in the pipeline.
PARAMETER | DESCRIPTION |
---|---|
request
|
The request to handle
TYPE:
|
next_handler
|
Function to call the next handler in the pipeline
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ResponseT
|
The response from the pipeline |
Source code in src/waku/cqrs/contracts/pipeline.py
Request
dataclass
¶
EventHandler
¶
The event handler interface.
Usage::
class UserJoinedEventHandler(EventHandler[UserJoinedEvent]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, event: UserJoinedEvent) -> None:
await self._meetings_api.notify_room(event.meeting_id, "New user joined!")
Mediator
¶
Mediator(
container: AsyncContainer,
event_publisher: EventPublisher,
)
Bases: IMediator
Default CQRS implementation.
Initialize the mediator.
PARAMETER | DESCRIPTION |
---|---|
container
|
Container used to resolve handlers and behaviors
TYPE:
|
event_publisher
|
Function to publish events to handlers
TYPE:
|
Source code in src/waku/cqrs/impl.py
send
async
¶
Send a request through the CQRS pipeline chain.
PARAMETER | DESCRIPTION |
---|---|
request
|
The request to process |
RETURNS | DESCRIPTION |
---|---|
ResponseT
|
Response from the handler |
RAISES | DESCRIPTION |
---|---|
RequestHandlerNotFound
|
If no handler is registered for the request type |
Source code in src/waku/cqrs/impl.py
publish
async
¶
publish(event: Event) -> None
Publish an event to all registered handlers.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to publish
TYPE:
|
RAISES | DESCRIPTION |
---|---|
EventHandlerNotFound
|
If no handlers are registered for the event type |
Source code in src/waku/cqrs/impl.py
IMediator
¶
ISender
¶
MediatorConfig
dataclass
¶
MediatorConfig(
*,
mediator_implementation_type: type[
IMediator
] = Mediator,
event_publisher: type[
EventPublisher
] = SequentialEventPublisher,
pipeline_behaviors: Sequence[
type[IPipelineBehavior[Any, Any]]
] = (),
)
Configuration for the Mediator extension.
This class defines the configuration options for setting up the cqrs pattern implementation in the application.
ATTRIBUTE | DESCRIPTION |
---|---|
mediator_implementation_type |
The concrete implementation class for the cqrs interface (IMediator). Defaults to the standard Mediator class. |
event_publisher |
The implementation class for publishing events. Defaults to
TYPE:
|
pipeline_behaviors |
A sequence of pipeline behavior configurations that will be applied to the cqrs pipeline. Behaviors are executed in the order they are defined. Defaults to an empty sequence.
TYPE:
|
mediator_implementation_type
class-attribute
instance-attribute
¶
event_publisher
class-attribute
instance-attribute
¶
event_publisher: type[EventPublisher] = (
SequentialEventPublisher
)
MediatorExtension
¶
Bases: OnModuleConfigure
Source code in src/waku/cqrs/modules.py
bind_request
¶
bind_request(
request_type: type[RequestT],
handler_type: RequestHandlerType[RequestT, ResponseT],
*,
behaviors: list[
type[IPipelineBehavior[RequestT, ResponseT]]
]
| None = None,
) -> Self
Source code in src/waku/cqrs/modules.py
bind_event
¶
on_module_configure
¶
on_module_configure(metadata: ModuleMetadata) -> None
Source code in src/waku/cqrs/modules.py
MediatorModule
¶
register
classmethod
¶
register(
config: MediatorConfig | None = None,
) -> DynamicModule
Application-level module for Mediator setup.
PARAMETER | DESCRIPTION |
---|---|
config
|
Configuration for the Mediator extension.
TYPE:
|
Source code in src/waku/cqrs/modules.py
RequestHandler
¶
Bases: ABC
, Generic[RequestT, ResponseT]
The request handler interface.
The request handler is an object, which gets a request as input and may return a response as a result.
Command handler example::
class JoinMeetingCommandHandler(RequestHandler[JoinMeetingCommand, None]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, request: JoinMeetingCommand) -> None:
await self._meetings_api.join_user(request.user_id, request.meeting_id)
Query handler example::
class ReadMeetingQueryHandler(RequestHandler[ReadMeetingQuery, ReadMeetingQueryResult]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, request: ReadMeetingQuery) -> ReadMeetingQueryResult:
link = await self._meetings_api.get_link(request.meeting_id)
return ReadMeetingQueryResult(link=link, meeting_id=request.meeting_id)
RequestMap
¶
contracts
¶
event
¶
pipeline
¶
NextHandlerType
module-attribute
¶
IPipelineBehavior
¶
Bases: ABC
, Generic[RequestT, ResponseT]
Interface for pipeline behaviors that wrap request handling.
handle
abstractmethod
async
¶
handle(
request: RequestT,
next_handler: NextHandlerType[RequestT, ResponseT],
) -> ResponseT
Handle the request and call the next handler in the pipeline.
PARAMETER | DESCRIPTION |
---|---|
request
|
The request to handle
TYPE:
|
next_handler
|
Function to call the next handler in the pipeline
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
ResponseT
|
The response from the pipeline |
Source code in src/waku/cqrs/contracts/pipeline.py
events
¶
handler
¶
EventHandler
¶
The event handler interface.
Usage::
class UserJoinedEventHandler(EventHandler[UserJoinedEvent]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, event: UserJoinedEvent) -> None:
await self._meetings_api.notify_room(event.meeting_id, "New user joined!")
map
¶
EventMapRegistry
module-attribute
¶
EventMapRegistry: TypeAlias = MutableMapping[
type[EventT], list[EventHandlerType[EventT]]
]
EventMap
¶
Source code in src/waku/cqrs/events/map.py
bind
¶
Source code in src/waku/cqrs/events/map.py
publish
¶
SequentialEventPublisher
¶
Bases: EventPublisher
GroupEventPublisher
¶
Bases: EventPublisher
exceptions
¶
ImproperlyConfiguredError
¶
Bases: MediatorError
Raised when cqrs configuration is invalid.
RequestHandlerAlreadyRegistered
¶
RequestHandlerAlreadyRegistered(
request_type: type[Request[Any]],
handler_type: RequestHandlerType[Any, Any],
)
Bases: MediatorError
, KeyError
Raised when a request handler is already registered.
ATTRIBUTE | DESCRIPTION |
---|---|
request_type |
The type of request that caused the error.
|
handler_type |
The type of handler that was already registered.
|
Source code in src/waku/cqrs/exceptions.py
RequestHandlerNotFound
¶
Bases: MediatorError
, TypeError
Raised when a request handler is not found.
ATTRIBUTE | DESCRIPTION |
---|---|
request_type |
The type of request that caused the error.
|
Source code in src/waku/cqrs/exceptions.py
EventHandlerAlreadyRegistered
¶
EventHandlerAlreadyRegistered(
event_type: type[EventT],
handler_type: EventHandlerType[EventT],
)
Bases: MediatorError
, KeyError
Raised when an event handler is already registered.
ATTRIBUTE | DESCRIPTION |
---|---|
event_type |
The type of event that caused the error.
|
handler_type |
The type of handler that was already registered.
|
Source code in src/waku/cqrs/exceptions.py
EventHandlerNotFound
¶
Bases: MediatorError
, TypeError
Raised when an event handler is not found.
ATTRIBUTE | DESCRIPTION |
---|---|
event_type |
The type of event that caused the error.
|
Source code in src/waku/cqrs/exceptions.py
PipelineBehaviorAlreadyRegistered
¶
PipelineBehaviorAlreadyRegistered(
request_type: type[Request],
behavior_type: type[IPipelineBehavior[Any, Any]],
)
Bases: MediatorError
, KeyError
Raised when a pipeline behavior is already registered.
ATTRIBUTE | DESCRIPTION |
---|---|
request_type |
The type of request that caused the error.
|
behavior_type |
The type of behavior that was already registered.
|
Source code in src/waku/cqrs/exceptions.py
impl
¶
Mediator
¶
Mediator(
container: AsyncContainer,
event_publisher: EventPublisher,
)
Bases: IMediator
Default CQRS implementation.
Initialize the mediator.
PARAMETER | DESCRIPTION |
---|---|
container
|
Container used to resolve handlers and behaviors
TYPE:
|
event_publisher
|
Function to publish events to handlers
TYPE:
|
Source code in src/waku/cqrs/impl.py
send
async
¶
Send a request through the CQRS pipeline chain.
PARAMETER | DESCRIPTION |
---|---|
request
|
The request to process |
RETURNS | DESCRIPTION |
---|---|
ResponseT
|
Response from the handler |
RAISES | DESCRIPTION |
---|---|
RequestHandlerNotFound
|
If no handler is registered for the request type |
Source code in src/waku/cqrs/impl.py
publish
async
¶
publish(event: Event) -> None
Publish an event to all registered handlers.
PARAMETER | DESCRIPTION |
---|---|
event
|
The event to publish
TYPE:
|
RAISES | DESCRIPTION |
---|---|
EventHandlerNotFound
|
If no handlers are registered for the event type |
Source code in src/waku/cqrs/impl.py
interfaces
¶
ISender
¶
modules
¶
MediatorConfig
dataclass
¶
MediatorConfig(
*,
mediator_implementation_type: type[
IMediator
] = Mediator,
event_publisher: type[
EventPublisher
] = SequentialEventPublisher,
pipeline_behaviors: Sequence[
type[IPipelineBehavior[Any, Any]]
] = (),
)
Configuration for the Mediator extension.
This class defines the configuration options for setting up the cqrs pattern implementation in the application.
ATTRIBUTE | DESCRIPTION |
---|---|
mediator_implementation_type |
The concrete implementation class for the cqrs interface (IMediator). Defaults to the standard Mediator class. |
event_publisher |
The implementation class for publishing events. Defaults to
TYPE:
|
pipeline_behaviors |
A sequence of pipeline behavior configurations that will be applied to the cqrs pipeline. Behaviors are executed in the order they are defined. Defaults to an empty sequence.
TYPE:
|
mediator_implementation_type
class-attribute
instance-attribute
¶
event_publisher
class-attribute
instance-attribute
¶
event_publisher: type[EventPublisher] = (
SequentialEventPublisher
)
MediatorModule
¶
register
classmethod
¶
register(
config: MediatorConfig | None = None,
) -> DynamicModule
Application-level module for Mediator setup.
PARAMETER | DESCRIPTION |
---|---|
config
|
Configuration for the Mediator extension.
TYPE:
|
Source code in src/waku/cqrs/modules.py
MediatorExtension
¶
Bases: OnModuleConfigure
Source code in src/waku/cqrs/modules.py
bind_request
¶
bind_request(
request_type: type[RequestT],
handler_type: RequestHandlerType[RequestT, ResponseT],
*,
behaviors: list[
type[IPipelineBehavior[RequestT, ResponseT]]
]
| None = None,
) -> Self
Source code in src/waku/cqrs/modules.py
bind_event
¶
on_module_configure
¶
on_module_configure(metadata: ModuleMetadata) -> None
Source code in src/waku/cqrs/modules.py
pipeline
¶
PipelineBehaviorWrapper
¶
PipelineBehaviorWrapper(
behaviors: Sequence[
IPipelineBehavior[RequestT, ResponseT]
],
)
Bases: Generic[RequestT, ResponseT]
Composes pipeline behaviors into a processing chain.
Initialize the pipeline behavior chain.
PARAMETER | DESCRIPTION |
---|---|
behaviors
|
Sequence of pipeline behaviors to execute in order
TYPE:
|
Source code in src/waku/cqrs/pipeline/chain.py
wrap
¶
wrap(
handle: NextHandlerType[RequestT, ResponseT],
) -> NextHandlerType[RequestT, ResponseT]
Create a pipeline that wraps the handler function with behaviors.
Pipeline behaviors are executed in the order they are provided.
PARAMETER | DESCRIPTION |
---|---|
handle
|
The handler function to wrap with behaviors
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NextHandlerType[RequestT, ResponseT]
|
A function that executes the entire pipeline |
Source code in src/waku/cqrs/pipeline/chain.py
chain
¶
PipelineBehaviorWrapper
¶
PipelineBehaviorWrapper(
behaviors: Sequence[
IPipelineBehavior[RequestT, ResponseT]
],
)
Bases: Generic[RequestT, ResponseT]
Composes pipeline behaviors into a processing chain.
Initialize the pipeline behavior chain.
PARAMETER | DESCRIPTION |
---|---|
behaviors
|
Sequence of pipeline behaviors to execute in order
TYPE:
|
Source code in src/waku/cqrs/pipeline/chain.py
wrap
¶
wrap(
handle: NextHandlerType[RequestT, ResponseT],
) -> NextHandlerType[RequestT, ResponseT]
Create a pipeline that wraps the handler function with behaviors.
Pipeline behaviors are executed in the order they are provided.
PARAMETER | DESCRIPTION |
---|---|
handle
|
The handler function to wrap with behaviors
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
NextHandlerType[RequestT, ResponseT]
|
A function that executes the entire pipeline |
Source code in src/waku/cqrs/pipeline/chain.py
map
¶
PipelineBehaviorMapRegistry
module-attribute
¶
PipelineBehaviorMapRegistry = MutableMapping[
type[RequestT],
list[type[IPipelineBehavior[RequestT, ResponseT]]],
]
PipelineBehaviourMap
¶
Source code in src/waku/cqrs/pipeline/map.py
bind
¶
bind(
request_type: type[RequestT],
behavior_types: list[
type[IPipelineBehavior[RequestT, ResponseT]]
],
) -> Self
Source code in src/waku/cqrs/pipeline/map.py
requests
¶
handler
¶
RequestHandlerType
module-attribute
¶
RequestHandlerType: TypeAlias = type[
RequestHandler[RequestT, ResponseT]
]
RequestHandler
¶
Bases: ABC
, Generic[RequestT, ResponseT]
The request handler interface.
The request handler is an object, which gets a request as input and may return a response as a result.
Command handler example::
class JoinMeetingCommandHandler(RequestHandler[JoinMeetingCommand, None]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, request: JoinMeetingCommand) -> None:
await self._meetings_api.join_user(request.user_id, request.meeting_id)
Query handler example::
class ReadMeetingQueryHandler(RequestHandler[ReadMeetingQuery, ReadMeetingQueryResult]) def init(self, meetings_api: MeetingAPIProtocol) -> None: self._meetings_api = meetings_api
async def handle(self, request: ReadMeetingQuery) -> ReadMeetingQueryResult:
link = await self._meetings_api.get_link(request.meeting_id)
return ReadMeetingQueryResult(link=link, meeting_id=request.meeting_id)
map
¶
RequestMapRegistry
module-attribute
¶
RequestMapRegistry: TypeAlias = MutableMapping[
type[RequestT], RequestHandlerType[RequestT, ResponseT]
]
di
¶
provider
¶
provider(
source: Callable[..., Any] | type[Any],
*,
scope: Scope = REQUEST,
provided_type: Any = None,
cache: bool = True,
) -> Provider
Create a Dishka provider for a callable or type.
PARAMETER | DESCRIPTION |
---|---|
source
|
Callable or type to provide as a dependency. |
scope
|
Scope of the dependency (default: Scope.REQUEST).
TYPE:
|
provided_type
|
Explicit type to provide (default: inferred).
TYPE:
|
cache
|
Whether to cache the instance in the scope.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Configured provider instance.
TYPE:
|
Source code in src/waku/di.py
singleton
¶
Create a singleton provider (lifetime: app).
PARAMETER | DESCRIPTION |
---|---|
source
|
Callable or type to provide as a singleton. |
provided_type
|
Explicit type to provide (default: inferred).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Singleton provider instance.
TYPE:
|
Source code in src/waku/di.py
scoped
¶
Create a scoped provider (lifetime: request).
PARAMETER | DESCRIPTION |
---|---|
source
|
Callable or type to provide as a scoped dependency. |
provided_type
|
Explicit type to provide (default: inferred).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Scoped provider instance.
TYPE:
|
Source code in src/waku/di.py
transient
¶
Create a transient provider (new instance per injection).
PARAMETER | DESCRIPTION |
---|---|
source
|
Callable or type to provide as a transient dependency. |
provided_type
|
Explicit type to provide (default: inferred).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Transient provider instance.
TYPE:
|
Source code in src/waku/di.py
object_
¶
Provide the exact object passed at creation time as a singleton dependency.
The provider always returns the same object instance, without instantiation or copying.
PARAMETER | DESCRIPTION |
---|---|
source
|
The object to provide as-is.
TYPE:
|
provided_type
|
Explicit type to provide (default: inferred).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Provider that always returns the given object.
TYPE:
|
Source code in src/waku/di.py
contextual
¶
contextual(
provided_type: Any, *, scope: Scope = REQUEST
) -> Provider
Provide a dependency from the current context (e.g., app/request).
PARAMETER | DESCRIPTION |
---|---|
provided_type
|
The type to resolve from context.
TYPE:
|
scope
|
Scope of the context variable (default: Scope.REQUEST).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Provider
|
Contextual provider instance.
TYPE:
|
Source code in src/waku/di.py
extensions
¶
ApplicationExtension
module-attribute
¶
ApplicationExtension: TypeAlias = (
OnApplicationInit
| AfterApplicationInit
| OnApplicationShutdown
)
ModuleExtension
module-attribute
¶
ModuleExtension: TypeAlias = (
OnModuleConfigure | OnModuleInit | OnModuleDestroy
)
DEFAULT_EXTENSIONS
module-attribute
¶
DEFAULT_EXTENSIONS: Sequence[ApplicationExtension] = (
ValidationExtension(
[DependenciesAccessibleRule()], strict=True
),
)
AfterApplicationInit
¶
Bases: Protocol
Extension for application post-initialization actions.
after_app_init
async
¶
after_app_init(app: WakuApplication) -> None
OnApplicationInit
¶
Bases: Protocol
Extension for application pre-initialization actions.
on_app_init
async
¶
on_app_init(app: WakuApplication) -> None
OnApplicationShutdown
¶
Bases: Protocol
Extension for application shutdown actions.
on_app_shutdown
async
¶
on_app_shutdown(app: WakuApplication) -> None
OnModuleConfigure
¶
Bases: Protocol
Extension for module configuration.
on_module_configure
¶
on_module_configure(metadata: ModuleMetadata) -> None
ExtensionRegistry
¶
Registry for extensions.
This registry maintains references to all extensions in the application, allowing for centralized management and discovery.
Source code in src/waku/extensions/registry.py
register_application_extension
¶
register_application_extension(
extension: ApplicationExtension,
) -> Self
Register an application extension with optional priority and tags.
Source code in src/waku/extensions/registry.py
register_module_extension
¶
register_module_extension(
module_type: ModuleType, extension: ModuleExtension
) -> Self
get_application_extensions
¶
get_module_extensions
¶
get_module_extensions(
module_type: ModuleType, extension_type: type[_ModExtT]
) -> list[_ModExtT]
Source code in src/waku/extensions/registry.py
protocols
¶
Extension protocols for application and module lifecycle hooks.
ApplicationExtension
module-attribute
¶
ApplicationExtension: TypeAlias = (
OnApplicationInit
| AfterApplicationInit
| OnApplicationShutdown
)
ModuleExtension
module-attribute
¶
ModuleExtension: TypeAlias = (
OnModuleConfigure | OnModuleInit | OnModuleDestroy
)
OnApplicationInit
¶
Bases: Protocol
Extension for application pre-initialization actions.
on_app_init
async
¶
on_app_init(app: WakuApplication) -> None
AfterApplicationInit
¶
Bases: Protocol
Extension for application post-initialization actions.
after_app_init
async
¶
after_app_init(app: WakuApplication) -> None
OnApplicationShutdown
¶
Bases: Protocol
Extension for application shutdown actions.
on_app_shutdown
async
¶
on_app_shutdown(app: WakuApplication) -> None
OnModuleConfigure
¶
Bases: Protocol
Extension for module configuration.
on_module_configure
¶
on_module_configure(metadata: ModuleMetadata) -> None
registry
¶
Extension registry for centralized management of extensions.
ExtensionRegistry
¶
Registry for extensions.
This registry maintains references to all extensions in the application, allowing for centralized management and discovery.
Source code in src/waku/extensions/registry.py
register_application_extension
¶
register_application_extension(
extension: ApplicationExtension,
) -> Self
Register an application extension with optional priority and tags.
Source code in src/waku/extensions/registry.py
register_module_extension
¶
register_module_extension(
module_type: ModuleType, extension: ModuleExtension
) -> Self
get_application_extensions
¶
get_module_extensions
¶
get_module_extensions(
module_type: ModuleType, extension_type: type[_ModExtT]
) -> list[_ModExtT]
Source code in src/waku/extensions/registry.py
factory
¶
ContainerConfig
dataclass
¶
WakuFactory
¶
WakuFactory(
root_module_type: ModuleType,
/,
context: dict[Any, Any] | None = None,
lifespan: Sequence[LifespanFunc] = (),
extensions: Sequence[
ApplicationExtension
] = DEFAULT_EXTENSIONS,
container_config: ContainerConfig | None = None,
)
Source code in src/waku/factory.py
create
¶
create() -> WakuApplication
Source code in src/waku/factory.py
lifespan
¶
LifespanFunc
module-attribute
¶
LifespanFunc: TypeAlias = (
Callable[
['WakuApplication'],
AbstractAsyncContextManager[None],
]
| AbstractAsyncContextManager[None]
)
LifespanWrapper
¶
LifespanWrapper(lifespan_func: LifespanFunc)
Source code in src/waku/lifespan.py
lifespan
async
¶
lifespan(app: WakuApplication) -> AsyncIterator[None]
Source code in src/waku/lifespan.py
modules
¶
DynamicModule
dataclass
¶
DynamicModule(
*,
providers: list[BaseProvider] = list(),
imports: list[ModuleType | DynamicModule] = list(),
exports: list[
type[object] | ModuleType | DynamicModule
] = list(),
extensions: list[ModuleExtension] = list(),
is_global: bool = False,
id: UUID = uuid4(),
parent_module: ModuleType,
)
Bases: ModuleMetadata
providers
class-attribute
instance-attribute
¶
List of providers for dependency injection.
imports
class-attribute
instance-attribute
¶
imports: list[ModuleType | DynamicModule] = field(
default_factory=list
)
List of modules imported by this module.
exports
class-attribute
instance-attribute
¶
exports: list[type[object] | ModuleType | DynamicModule] = (
field(default_factory=list)
)
List of types or modules exported by this module.
extensions
class-attribute
instance-attribute
¶
extensions: list[ModuleExtension] = field(
default_factory=list
)
List of module extensions for lifecycle hooks.
ModuleCompiler
¶
extract_metadata
¶
extract_metadata(
module_type: ModuleType | DynamicModule,
) -> tuple[ModuleType, ModuleMetadata]
Source code in src/waku/modules/_metadata.py
ModuleMetadata
dataclass
¶
ModuleMetadata(
*,
providers: list[BaseProvider] = list(),
imports: list[ModuleType | DynamicModule] = list(),
exports: list[
type[object] | ModuleType | DynamicModule
] = list(),
extensions: list[ModuleExtension] = list(),
is_global: bool = False,
id: UUID = uuid4(),
)
providers
class-attribute
instance-attribute
¶
List of providers for dependency injection.
imports
class-attribute
instance-attribute
¶
imports: list[ModuleType | DynamicModule] = field(
default_factory=list
)
List of modules imported by this module.
exports
class-attribute
instance-attribute
¶
exports: list[type[object] | ModuleType | DynamicModule] = (
field(default_factory=list)
)
List of types or modules exported by this module.
extensions
class-attribute
instance-attribute
¶
extensions: list[ModuleExtension] = field(
default_factory=list
)
List of module extensions for lifecycle hooks.
Module
¶
Module(module_type: ModuleType, metadata: ModuleMetadata)
Source code in src/waku/modules/_module.py
exports
instance-attribute
¶
exports: Final[
Sequence[type[object] | ModuleType | DynamicModule]
] = exports
ModuleRegistry
¶
ModuleRegistry(
*,
compiler: ModuleCompiler,
root_module: Module,
modules: dict[UUID, Module],
providers: list[BaseProvider],
adjacency: AdjacencyMatrix,
)
Immutable registry and graph for module queries, traversal, and lookups.
Source code in src/waku/modules/_registry.py
get
¶
get(module_type: ModuleType | DynamicModule) -> Module
get_by_id
¶
traverse
¶
Traverse the module graph in depth-first post-order (children before parent) recursively.
PARAMETER | DESCRIPTION |
---|---|
from_
|
Start module (default: root)
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
Module
|
Each traversed module (post-order)
TYPE::
|
Source code in src/waku/modules/_registry.py
ModuleRegistryBuilder
¶
ModuleRegistryBuilder(
root_module_type: ModuleType,
compiler: ModuleCompiler | None = None,
)
Source code in src/waku/modules/_registry_builder.py
module
¶
module(
*,
providers: Sequence[BaseProvider] = (),
imports: Sequence[ModuleType | DynamicModule] = (),
exports: Sequence[
type[object] | ModuleType | DynamicModule
] = (),
extensions: Sequence[ModuleExtension] = (),
is_global: bool = False,
) -> Callable[[type[_T]], type[_T]]
Decorator to define a module.
PARAMETER | DESCRIPTION |
---|---|
providers
|
Sequence of providers for dependency injection.
TYPE:
|
imports
|
Sequence of modules imported by this module.
TYPE:
|
exports
|
Sequence of types or modules exported by this module.
TYPE:
|
extensions
|
Sequence of module extensions for lifecycle hooks.
TYPE:
|
is_global
|
Whether this module is global or not.
TYPE:
|
Source code in src/waku/modules/_metadata.py
testing
¶
override
¶
override(
container: AsyncContainer, *providers: BaseProvider
) -> Iterator[None]
Temporarily override providers in an AsyncContainer for testing.
PARAMETER | DESCRIPTION |
---|---|
container
|
The container whose providers will be overridden.
TYPE:
|
*providers
|
Providers to override in the container.
TYPE:
|
YIELDS | DESCRIPTION |
---|---|
None
|
Context in which the container uses the overridden providers.
TYPE::
|
Example
from waku import WakuFactory, module
from waku.di import Scope, singleton
from waku.testing import override
class Service: ...
class ServiceOverride(Service): ...
with override(application.container, singleton(ServiceOverride, provided_type=Service)):
service = await application.container.get(Service)
assert isinstance(service, ServiceOverride)
Source code in src/waku/testing.py
validation
¶
ValidationRule
¶
Bases: Protocol
validate
¶
validate(
context: ValidationContext,
) -> list[ValidationError]
Source code in src/waku/validation/_abc.py
ValidationExtension
¶
ValidationExtension(
rules: Sequence[ValidationRule], *, strict: bool = True
)
Bases: AfterApplicationInit
Source code in src/waku/validation/_extension.py
after_app_init
async
¶
after_app_init(app: WakuApplication) -> None
rules
¶
DependenciesAccessibleRule
¶
DependenciesAccessibleRule(cache_size: int = 1000)
Bases: ValidationRule
Validates that all dependencies required by providers are accessible.
Source code in src/waku/validation/rules/dependency_accessible.py
validate
¶
validate(
context: ValidationContext,
) -> list[ValidationError]
Source code in src/waku/validation/rules/dependency_accessible.py
DependencyInaccessibleError
¶
DependencyInaccessibleError(
required_type: type[object],
required_by: object,
from_module: Module,
)
Bases: ValidationError
Error indicating a dependency is not accessible to a provider/module.
Source code in src/waku/validation/rules/dependency_accessible.py
dependency_accessible
¶
DependencyInaccessibleError
¶
DependencyInaccessibleError(
required_type: type[object],
required_by: object,
from_module: Module,
)
Bases: ValidationError
Error indicating a dependency is not accessible to a provider/module.
Source code in src/waku/validation/rules/dependency_accessible.py
DependencyAccessChecker
¶
DependencyAccessChecker(
modules: list[Module],
context: ValidationContext,
types_extractor: ModuleTypesExtractor,
)
Handles dependency accessibility checks between modules.
Source code in src/waku/validation/rules/dependency_accessible.py
DependenciesAccessibleRule
¶
DependenciesAccessibleRule(cache_size: int = 1000)
Bases: ValidationRule
Validates that all dependencies required by providers are accessible.
Source code in src/waku/validation/rules/dependency_accessible.py
validate
¶
validate(
context: ValidationContext,
) -> list[ValidationError]