betty.plugin package - Betty 0.4.0a4 documentation

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

# betty.plugin package

## Submodules

- betty.plugin.assertion module
  - `assert_plugin()`
- betty.plugin.entry_point module
  - `EntryPointPluginRepository`
    - `EntryPointPluginRepository.__init__()`
- betty.plugin.lazy module
  - `LazyPluginRepositoryBase`
    - `LazyPluginRepositoryBase.__init__()`
    - `LazyPluginRepositoryBase.get()`
- betty.plugin.proxy module
  - `ProxyPluginRepository`
    - `ProxyPluginRepository.__init__()`
    - `ProxyPluginRepository.get()`
- betty.plugin.static module
  - `StaticPluginRepository`
    - `StaticPluginRepository.__init__()`
    - `StaticPluginRepository.get()`

## Module contents

The Plugin API.

Plugins allow third-party code (e.g. your own Python package) to add functionality to Betty.

Read more at Plugins.

class betty.plugin.Plugin

  Bases: `ABC`

  A plugin.

  classmethod plugin_description() → Localizable | None

    Get the human-readable long plugin description.

  abstract classmethod plugin_id() → str

    Get the plugin ID.

    IDs are unique per plugin type: - A plugin repository MUST at most have a single plugin for any ID. - Different plugin repositories MAY each have a plugin with the same ID.

  abstract classmethod plugin_label() → Localizable

    Get the human-readable short plugin label.

exception betty.plugin.PluginError

  Bases: `UserFacingError`

  Any error originating from the Plugin API.

betty.plugin.PluginId

  A plugin ID is a string that meets these criteria: - At most 250 characters long. - Lowercase letters, numbers, and hyphens (-).

  See `betty.plugin.validate_plugin_id()`.

exception betty.plugin.PluginNotFound

  Bases: `PluginError`

  Raised when a plugin cannot be found.

  classmethod new(plugin_id: str) → Self

    Create a new instance.

class betty.plugin.PluginRepository

  Bases: `Generic`[`_PluginT`], `ABC`

  Discover and manage plugins.

  abstract async get(plugin_id: str) → type[_PluginT]

    Get a single plugin by its ID.

    Raises:

      PluginNotFound – if no plugin can be found for the given ID.

  async select() → Sequence[type[_PluginT]]
  async select(mixin_one: type[_PluginMixinOneT]) → Sequence[type[_PluginT & _PluginMixinOneT]]
  async select(mixin_one: type[_PluginMixinOneT], mixin_two: type[_PluginMixinTwoT]) → Sequence[type[_PluginT & _PluginMixinOneT & _PluginMixinTwoT]]
  async select(mixin_one: type[_PluginMixinOneT], mixin_two: type[_PluginMixinTwoT], mixin_three: type[_PluginMixinThreeT]) → Sequence[type[_PluginT & _PluginMixinOneT & _PluginMixinTwoT & _PluginMixinThreeT]]

    Select a subset of the known plugins.

    When called without arguments, this returns all known plugins. When called with one or more arguments, this returns all known plugins that are also subclasses or all of the given mixins.

    This method is overloaded to provide for the majority use case of at most three mixins, because when using `*args: *Ts`, we cannot unpack `Ts` into an `basedtyping.Intersection` return type.

betty.plugin.validate_plugin_id(plugin_id: str) → TypeGuard[str]

  Validate that a string is a plugin ID.