betty.plugin package¶
Submodules¶
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[source]¶
Bases:
ABC
A plugin.
Plugins are identified by their
IDs
as well as their types. Each must be able to uniquely identify the plugin within a plugin repository.To test your own subclasses, use
betty.test_utils.plugin.PluginTestBase
.- classmethod plugin_description() Localizable | None [source]¶
Get the human-readable long plugin description.
- abstract classmethod plugin_id() str [source]¶
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 [source]¶
Get the human-readable short plugin label.
- exception betty.plugin.PluginError[source]¶
Bases:
UserFacingError
Any error originating from the Plugin API.
- exception betty.plugin.PluginNotFound[source]¶
Bases:
PluginError
Raised when a plugin cannot be found.
- class betty.plugin.PluginRepository[source]¶
Bases:
Generic
[_PluginT
],FactoryProvider
[_PluginT
],ABC
Discover and manage plugins.
- abstract async get(plugin_id: str) type[_PluginT] [source]¶
Get a single plugin by its ID.
- Raises:
PluginNotFound – if no plugin can be found for the given ID.
- async new(cls: type[_PluginT] | str) _PluginT [source]¶
Create a new instance.
- Raises:
FactoryError – raised when
cls
could not be instantiated.
- async select() Sequence[type[_PluginT]] [source]¶
- 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 unpackTs
into anbasedtyping.Intersection
return type.
- class betty.plugin.ShorthandPluginBase[source]¶
Bases:
Plugin
Allow shorthand declaration of plugins.
This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.
- classmethod plugin_description() Localizable | None [source]¶
Get the human-readable long plugin description.
- classmethod plugin_id() str [source]¶
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.
- classmethod plugin_label() Localizable [source]¶
Get the human-readable short plugin label.