betty.core module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.core module

Provide tools to build core application components.

class betty.core.Bootstrapped

  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)
  final assert_bootstrapped() → None

    Assert that the component has been bootstrapped.

  final assert_not_bootstrapped() → None

    Assert that the component was not bootstrapped.

  property bootstrapped: bool

    Whether the component has been bootstrapped.

class betty.core.CoreComponent

  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)
  async bootstrap() → None

    Bootstrap the component.

  async shutdown(*, wait: bool = True) → None

    Shut the component down.

class betty.core.ShutdownCallbackKwargs

  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

  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__()
  append(callback: Callable[[Unpack[ShutdownCallbackKwargs]], Awaitable[None]] | Shutdownable) → None

    Append a callback or another component to the stack.

  async shutdown(*, wait: bool = True) → None

    Shut the component down.

class betty.core.Shutdownable

  Bases: `ABC`

  A component that can be shut down.

  abstractmethod async shutdown(*, wait: bool = True) → None

    Shut the component down.