GlobalRegistry
GlobalRegistry is a class-level key-value store for sharing data between plugins.
FastPluggy extends it, so fast_pluggy and GlobalRegistry access the same store.
API
from fastpluggy.core.global_registry import GlobalRegistry
# Store / retrieve a single value
GlobalRegistry.register_global("my_key", my_value)
value = GlobalRegistry.get_global("my_key", default=None)
exists = GlobalRegistry.has_global("my_key")
# Extend a list (deduplicates) or merge a dict
GlobalRegistry.extend_globals("topbar_actions", items=[TopbarAction(...)])
GlobalRegistry.extend_globals("fp_widgets", items={"admin_home": my_widget})
# Introspection
all_data = GlobalRegistry.get_all_globals()
# Cleanup (mainly for tests)
GlobalRegistry.clear_globals()
GlobalRegistry.clear_globals_key("my_key")
Built-in keys
| Key | Type | Set by | Description |
|---|---|---|---|
topbar_actions |
List[TopbarAction] |
Plugins (in on_load_complete) |
Topbar buttons, sorted by position before rendering |
list_widget_to_inject |
List |
Plugins | Widgets injected globally into every page (via ViewBuilder) |
fp_widgets |
Dict[str, Widget] |
Plugins | Named widget slots, e.g. "admin_home": its render() replaces the admin home's Health and Needs attention cards; admins still get the System and Plugin tools cards under it |
Entries owned by a plugin
What a plugin adds from one of its lifecycle hooks (on_load_complete,
after_setup_templates) belongs to it: each list item and dict key added by
extend_globals, and each register_capability. The hooks run on every load_app()
(startup, settings save, plugin enabled or disabled), and at the end of each load the
core drops the entries the plugins did not register again. So:
- a disabled plugin's topbar buttons, injected widgets and capabilities disappear with its routes, without a restart;
- an entry the plugin no longer registers (a button turned off by a setting) disappears on the next load;
- register on every load, from a hook: an "already registered" guard makes the entry vanish on the next reload.
Not tracked, and kept until the restart:
register_globalreplaces a whole key, which several plugins may share (the task registry): the object a disabled plugin published stays;- what is registered outside a hook (at import, from a route), or inside
with GlobalRegistry.unowned():. Widget classes register themselves that way, once, when their module is imported.
Entries are dropped at the end of the load: while it runs, pages and hooks still see the previous ones.
Conventions
- Prefer calling
extend_globalsinsideon_load_completeso all plugins are already discovered when you run (avoids ordering issues). - Use namespaced keys to avoid collisions:
"my_plugin_data"not"data". extend_globalsfor lists deduplicates using__hash__/__eq__, and the last registration wins: an item equal to one already there replaces it at its position.TopbarActionusesidas its equality key, so re-registering the sameid(on everyload_app()) updates the action instead of adding a second one.