betty.core module

Provide tools to build core application components.

class betty.core.Bootstrapped[source]

Bases: object

A component that can be in a bootstrapped state.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

__init__(*args: Any, **kwargs: Any)[source]
final assert_bootstrapped() None[source]

Assert that the component has been bootstrapped.

final assert_not_bootstrapped() None[source]

Assert that the component was not bootstrapped.

property bootstrapped: bool

Whether the component has been bootstrapped.

class betty.core.CoreComponent[source]

Bases: Bootstrapped, Shutdownable, ABC

A core component.

Core components can manage their resources by being bootstrapped and shut down.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

__init__(*args: Any, **kwargs: Any)[source]
async bootstrap() None[source]

Bootstrap the component.

async shutdown(*, wait: bool = True) None[source]

Shut the component down.

class betty.core.ShutdownCallbackKwargs[source]

Bases: TypedDict

The keyword arguments to a shutdown callback.

wait: bool

True to wait for the component to shut down gracefully, or False to attempt an immediate forced shutdown.

final class betty.core.ShutdownStack[source]

Bases: Bootstrapped, Shutdownable

A stack that invokes callbacks in reverse order upon shutting down.

This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

__init__()[source]
append(callback: Callable[[Unpack[ShutdownCallbackKwargs]], Awaitable[None]] | Shutdownable) None[source]

Append a callback or another component to the stack.

async shutdown(*, wait: bool = True) None[source]

Shut the component down.

class betty.core.Shutdownable[source]

Bases: ABC

A component that can be shut down.

abstractmethod async shutdown(*, wait: bool = True) None[source]

Shut the component down.