Skip to content

Module spangle.component

Component tools.

Classes

AsyncShutdownComponentProtocol

class AsyncShutdownComponentProtocol(*args, **kwargs)

Component must be initialized without arguments.


Base classes


Methods

shutdown

async def shutdown(self) -> None

Called on server shutdown. To access other components, use use_component .


AsyncStartupComponentProtocol

class AsyncStartupComponentProtocol(*args, **kwargs)

Component must be initialized without arguments.


Base classes


Methods

startup

async def startup(self) -> None

Called on server startup. To access other components, use use_component .


ComponentProtocol

class ComponentProtocol(self)

Component must be initialized without arguments.


Base classes

  • typing.Protocol

ComponentsCache

class ComponentsCache(self)

Store registered component instances based on its context.

Initialize self. See help(type(self)) for accurate signature.


SyncShutdownComponentProtocol

class SyncShutdownComponentProtocol(*args, **kwargs)

Component must be initialized without arguments.


Base classes


Methods

shutdown

def shutdown(self) -> None

Called on server shutdown. To access other components, use use_component .


SyncStartupComponentProtocol

class SyncStartupComponentProtocol(*args, **kwargs)

Component must be initialized without arguments.


Base classes


Methods

startup

def startup(self) -> None

Called on server startup. To access other components, use use_component .

Functions

use_api

def use_api() -> Api

Return Api instance.

Returns

  • Api Raises

  • KeyError: Called out of api context.


use_component

def use_component(component: type[T], *, api: Optional[Api] = None) -> T

Return registered component instance.

Args

  • component (type[spangle.component.AnyComponentProtocol]): Component class.
  • api (Optional[spangle.api.Api]): Api instance to use its context. Default: None (use current context)

Returns

  • Registered component instance.

Raises

  • LookupError: The component is not registered.