Skip to content

Registry

panel_flowdash.registry

Component registry: the register decorator and metadata model.

_APP_METADATA_BY_ID = {} module-attribute

_AUTH_INVALID = 'auth_invalid' module-attribute

_AUTH_KEYS = {'allow_users', 'allow_groups', 'deny_users', 'deny_groups', 'authorize'} module-attribute

_AUTH_PENDING = 'auth_pending' module-attribute

_DEFAULT_SECTION = 'Components' module-attribute

_LITERAL_KEYS = {'page', 'component', 'sidebar', 'title', 'icon', 'description', 'singleton', 'provides', 'requires', 'placeholder', 'handles_failures', 'aliases', 'port_aliases', 'config', 'tags', 'extensions', 'default_size', 'min_size', 'max_size', 'framed', 'allow_users', 'allow_groups', 'deny_users', 'deny_groups'} module-attribute

_PRESETS_PENDING = 'presets_pending' module-attribute

_REGISTER_NAMES = {'register', 'panel_app'} module-attribute

_UNINFORMATIVE_MODULES = {'main', 'builtins', 'abc'} module-attribute

logger = logging.getLogger(__name__) module-attribute

panel_app = register module-attribute

PackageResolutionError

Bases: ValueError

The package passed to build_registry does not resolve to the project directory.

PanelAppMetadata dataclass

Metadata attached to a component or page by the @register decorator.

aliases = field(default_factory=list) class-attribute instance-attribute

allow_groups = field(default_factory=list) class-attribute instance-attribute

allow_users = field(default_factory=list) class-attribute instance-attribute

auth_pending = False class-attribute instance-attribute

authorize = None class-attribute instance-attribute

check_config = None class-attribute instance-attribute

component = False class-attribute instance-attribute

config = field(default_factory=list) class-attribute instance-attribute

config_choices = None class-attribute instance-attribute

config_completions = None class-attribute instance-attribute

config_editor = None class-attribute instance-attribute

config_schema = None class-attribute instance-attribute

contract = None class-attribute instance-attribute

default_size = None class-attribute instance-attribute

deny_groups = field(default_factory=list) class-attribute instance-attribute

deny_users = field(default_factory=list) class-attribute instance-attribute

description = None class-attribute instance-attribute

extensions = field(default_factory=list) class-attribute instance-attribute

framed = None class-attribute instance-attribute

handles_failures = field(default_factory=list) class-attribute instance-attribute

icon = None class-attribute instance-attribute

max_size = None class-attribute instance-attribute

min_size = None class-attribute instance-attribute

page = True class-attribute instance-attribute

palette_presets = None class-attribute instance-attribute

permission property

Build a :class:~panel_flowdash.auth.Permission from the declared rules.

placeholder = None class-attribute instance-attribute

port_aliases = field(default_factory=dict) class-attribute instance-attribute

presets_pending = False class-attribute instance-attribute

provides = field(default_factory=list) class-attribute instance-attribute

requires = field(default_factory=list) class-attribute instance-attribute

sidebar = False class-attribute instance-attribute

singleton = False class-attribute instance-attribute

tags = field(default_factory=list) class-attribute instance-attribute

title = None class-attribute instance-attribute

from_app(app) classmethod

Extract metadata from an app object.

is_registered(app) staticmethod

Whether @register attached metadata to app.

Permission dataclass

An allow/deny rule set evaluated against an :class:Identity.

The rule fields match either the resolved user (OAuth login or system user) or one of the identity's groups. An empty Permission declares no constraints and defers entirely to the caller's default policy.

allow_edit_users and allow_edit_groups only apply to dashboards: they grant editing (which includes viewing) on top of the view rules, without restricting who else may view.

allow_edit_groups = field(default_factory=frozenset) class-attribute instance-attribute

allow_edit_users = field(default_factory=frozenset) class-attribute instance-attribute

allow_groups = field(default_factory=frozenset) class-attribute instance-attribute

allow_users = field(default_factory=frozenset) class-attribute instance-attribute

deny_groups = field(default_factory=frozenset) class-attribute instance-attribute

deny_users = field(default_factory=frozenset) class-attribute instance-attribute

is_empty property

Whether the permission declares no allow, deny or edit rules.

from_dict(data) classmethod

Deserialize from a (possibly None or partial) mapping.

from_spec(*, allow_users=None, allow_groups=None, deny_users=None, deny_groups=None, allow_edit_users=None, allow_edit_groups=None) classmethod

Build a :class:Permission from loosely-typed iterables.

grants_edit(identity)

Whether an edit rule names identity; deny rules are not consulted.

to_dict()

Serialize to sorted lists for JSON persistence.

Registration

The decorator :func:register returns, holding the metadata it attaches.

record is the :class:PanelAppMetadata that applying the decorator attaches to the app, readable before the app exists.

record = record instance-attribute

RegistryEntry dataclass

A registered component/page with its metadata.

app = None class-attribute instance-attribute

app_id instance-attribute

load_error = field(default=None, repr=False, compare=False) class-attribute instance-attribute

metadata instance-attribute

module_name instance-attribute

module_path = None class-attribute instance-attribute

name instance-attribute

page_path instance-attribute

section instance-attribute

spec = field(default=None, repr=False, compare=False) class-attribute instance-attribute

title property

Human-readable title.

from_app(app, *, app_id=None, section=None, name=None) classmethod

Build an entry from an already-imported app object.

Unlike :func:build_registry, which discovers modules on disk and defers importing them, this wraps a live object so load() is a no-op. Used by the programmatic API where components are passed in directly.

Objects without @register metadata are treated as components, since a bare Viewer subclass handed to the editor is only ever meant to be one.

load()

Import the module and return the app object.

Caches the result on self.app. Raises on import failure.

_app_name(app)

Derive a component name from a live app object.

Modules following the project-directory convention export their component as app, which makes a useless id, so in that case the module stem names the component instead (matching how :func:build_registry ids it).

_app_section(app)

Derive a section from an app object's defining module.

A component defined in myproject.analytics lands in an "analytics" section. When the module stem already names the component (the app convention), the parent package supplies the section instead.

_attached_metadata(app)

_check_component_class(app, title=None)

Refuse a param.Parameterized class that is neither a Panel Viewer nor a Viewable.

A Parameterized class that is not a Viewer gets no input ports from its parameters. A plain Parameterized class also has no view, so it is refused. A Viewable is accepted as a static view.

_check_package(package, project_dir)

Raise unless importing package resolves to project_dir.

find_spec on a dotted name imports its parent packages, so validating a.b executes a/__init__.py.

_eval_literal(node)

Safely evaluate an AST literal node; return None on failure.

_extract_register_kwargs(source)

Parse source and return the kwargs of the first @register/@panel_app call.

Only literal-evaluable arguments are captured; runtime expressions (e.g. config_schema=MyParamClass) are skipped and picked up later when the module is actually imported. A permission argument that cannot be evaluated, or any authorize callable, sets auth_pending instead, so the page fails closed until it is imported rather than appearing open.

Returns None if no @register call is found.

_framed(value)

Validate a framed hint: True, False or None.

_is_name_list(value)

Whether a literal permission value is a name or a collection of names.

_module_parts(app)

Meaningful dotted parts of an app's defining module, outermost first.

_name_list(value)

Normalize a user/group argument, treating a lone string as one name.

_port_aliases(value)

Validate a mapping of former port names to current ones.

_scanned(normalize, value, path, name)

Normalize a scanned argument, ignoring a malformed one until the module is imported.

build_registry(project_dir, *, package=None)

Scan project_dir for page/component modules without importing them.

Reads each .py file with the AST to extract @register metadata. Modules are not imported at this stage; each RegistryEntry.app is None until RegistryEntry.load() is called.

By default modules are named relative to project_dir (<Section>.<name>), so the directory itself must be on sys.path. Pass package when project_dir is an importable package: modules are then named <package>.<Section>.<name>, so the project's own imports and flowdash's lazy imports share one module object. Raises PackageResolutionError (a ValueError) if package does not resolve to project_dir.

register(*, page=True, component=False, sidebar=False, title=None, icon=None, description=None, tags=None, extensions=None, default_size=None, min_size=None, max_size=None, framed=None, singleton=False, provides=None, requires=None, placeholder=None, config_schema=None, config=None, config_editor=None, check_config=None, contract=None, config_choices=None, config_completions=None, palette_presets=None, handles_failures=None, aliases=None, port_aliases=None, allow_users=None, allow_groups=None, deny_users=None, deny_groups=None, authorize=None)

Metadata-only decorator for app exports.

Annotates an app object/callable without altering runtime behavior.

The config_schema, config and config_editor arguments declare design-time configuration options that appear in the node editor. Use config_schema (a param.Parameterized subclass, a Pydantic model, or a JSON Schema dict) to define config explicitly, or config to name which of a Viewer's own params are configuration rather than input ports. Pass config_editor to supply a custom editor callable instead of the auto-generated form.

The check_config argument takes a callable, sync or async, that checks a node's config before it is applied: check(config, inputs) gets the node's whole config with the change applied and its input values that are set and not failed ({} before the node is placed). It returns None, a string or an iterable of strings, each non-empty string a problem, or raises ValueError with the problem as its message. A :class:~panel_flowdash.CheckWarning in place of a string is a warning, shown with the config but not refusing it. Any other result or exception, or taking longer than 10 seconds, counts as a failed check. The check runs again when an input of the node is connected or disconnected. A sync check runs in a worker thread and must not change the editor. A config with problems is refused in the inspector and by the agent tools, and reported by validation and previews.

The contract argument takes a :class:~panel_flowdash.ParameterContract: what the dashboard needs of a value bound to a parameter on one of the component's config fields, e.g. the columns its downstream nodes read from a data source. Its expects(context) writes the parameter's expects and its check(context, expects) runs whenever the parameter is rebound, see :mod:panel_flowdash.parameters.

The config_choices argument takes a callable, sync or async, called like check_config as choices(config, inputs), that returns the values each config field may take: {field: choices}, where choices are a list of values, a {label: value} dict or a :class:~panel_flowdash.Choices. The inspector offers them in a dropdown, or as suggestions with Choices(restrict=False), and asks again when the node's inputs or config change. Choices under the name of an input are offered for the value that input takes while it is not connected. A config param may also declare that it names a column of an input, with metadata={"flowdash": {"choices": "columns", "of": "<input>"}}.

The config_completions argument takes a callable, sync or async, called like config_choices, that returns the words the code editor of a code field completes while typing: {field: words}, where words are a list, a {label: word} dict or a :class:~panel_flowdash.Choices whose types are shown beside each word, e.g. the columns of the tables a query reads. Without it a code field completes the column names of the node's tabular inputs.

The palette_presets argument takes a callable, called with the editor's context, that returns further entries the component palette and the command palette offer for the component, each placing it with a config filled in: dicts with a title and a config, and optionally a description, a tooltip, tags and an icon, e.g. one entry per data source the host provides. It is asked again when the editor's context changes, not on every search; an entry without a title or config, or whose config is not JSON-serializable, is skipped, and a failing callable offers none. An entry's optional id identifies it in the command palette; without one, its title and config do. Components found by scanning a project directory offer their presets once imported, which the app does when a dashboard is edited.

The placeholder argument sets the message a dashboard tile shows while a blocking input of the component is unset, in place of the default "Waiting for " text.

The handles_failures argument names the inputs that can receive a failure. With FlowDash(propagate_failures=True) an upstream failure reaches such an input as a param.ReactiveError instead of leaving the input on its last value; the parameter behind it must accept one, so use an untyped param.Parameter.

The aliases argument lists ids the component was registered under before (e.g. ["Old/section_name"]) and port_aliases maps former port or config names to current ones (e.g. {"ticker": "symbol"}), so a saved dashboard that references the old names still loads after a rename.

The framed argument says whether the component's dashboard tile is drawn as a framed card: False for components that are layout chrome themselves, e.g. a divider or a section heading, True for ones that need a frame, and None (the default) to follow the dashboard's "Frame tiles" setting. A tile's own frame option, set in the Layout tab, takes precedence over it.

The extensions argument names the Panel extensions (e.g. ["tabulator"]) the app's output needs. Components are imported lazily, after the page has loaded its JavaScript, so an editor loads every declared extension up front; an undeclared one fails to render in the browser.

The allow_users, allow_groups, deny_users and deny_groups arguments declare page-level authorization rules. Users are matched against either the OAuth login or the system user; groups against the identity's resolved group membership. Deny rules always win; when only allow rules are present the identity must match at least one; with no rules the project's default policy applies. Pass authorize for a custom callable taking the resolved Identity and returning a bool (resolved on import).

The returned decorator exposes the metadata as its record before it is applied, so a factory that builds the class can read the registered title and the rest of the declaration while it builds it::

registration = register(component=True, title=spec["title"])
if not spec.get("columns"):
    raise ValueError(f"{registration.record.title}: declares no columns.")
return registration(type(name, (Viewer,), namespace))

Arguments register refuses, and a component class it refuses, are named by their title when one is given rather than by the Python name.