Skip to content

Dashboard Store

panel_flowdash.asset_store

Persistence for dashboard graphs, backed by SQLite or an in-memory dict.

CHAT_KIND = 'chat' module-attribute

DASHBOARD_KIND = 'dashboard' module-attribute

DEFAULT_DB_NAME = 'assets.db' module-attribute

KINDS = (DASHBOARD_KIND, CHAT_KIND, REPORT_KIND) module-attribute

LEGACY_DB_NAME = 'dashboards.db' module-attribute

MALFORMED_ERRORS = (KeyError, TypeError, ValueError, AttributeError, RecursionError) module-attribute

MODEL_VERSION = 4 module-attribute

REPORT_KIND = 'report' module-attribute

_AMBIGUOUS_TITLES = set() module-attribute

_INHERITED = [] module-attribute

_RANDOM_ID = re.compile('[0-9a-f]{12}') module-attribute

__getattr__ = module_getattr(__name__, old_names(globals())) module-attribute

_dataclass_init = AssetModel.__init__ module-attribute

logger = logging.getLogger(__name__) module-attribute

AssetConflictError

Bases: AssetStoreError

A save was refused because the dashboard changed since it was loaded.

Raised by :meth:BaseAssetStore.save_asset when the stored revision differs from the revision the saved model was loaded at, that is when another session saved the dashboard in the meantime.

Attributes:

Name Type Description
asset_id

The dashboard that was being saved.

expected

The revision the rejected model was based on.

current

The revision now stored.

asset_id = asset_id instance-attribute

current = current instance-attribute

dashboard_id property

Deprecated alias of :attr:asset_id.

expected = expected instance-attribute

AssetEdge dataclass

A connection between two component ports, with the transform steps it applies.

source instance-attribute

source_port instance-attribute

target instance-attribute

target_port instance-attribute

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

from_dict(data) classmethod

to_dict()

AssetItem dataclass

A component instance on the dashboard.

x, y store the ReactFlow node canvas position. Grid layout (widths, heights, visibility) lives in AssetModel.tile_layout. origin is the id of the turn that created the item, see AssetModel.turns. inputs holds literal values of unconnected inputs, by port; a connection wins over them.

collapsed = False class-attribute instance-attribute

component_id instance-attribute

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

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

instance_id instance-attribute

origin = None class-attribute instance-attribute

preview_output = None class-attribute instance-attribute

x = 0 class-attribute instance-attribute

y = 0 class-attribute instance-attribute

from_dict(data) classmethod

to_dict()

AssetModel dataclass

A persisted dashboard: nodes + edges + tile layout, and the turns that made them.

asset_id instance-attribute

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

dashboard_id property writable

Deprecated alias of :attr:asset_id.

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

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

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

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

kind = DASHBOARD_KIND class-attribute instance-attribute

owner property

The owner principal: the creating user, unless an admin gave it to someone else.

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

permission = field(default_factory=Permission) class-attribute instance-attribute

reference_width = None class-attribute instance-attribute

report = None class-attribute instance-attribute

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

revision = None class-attribute instance-attribute

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

source = None class-attribute instance-attribute

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

title instance-attribute

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

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

user_id instance-attribute

version = MODEL_VERSION class-attribute instance-attribute

from_dict(data) classmethod

Read a model from its dict, including one written before the rename with dashboard_id.

to_dict()

AssetStore

Bases: BaseAssetStore

SQLite-backed store for dashboard models.

Each thread reuses one connection, so a _get_conn() block nested in another on the same thread (for example in a subclass) shares its transaction: the inner block's commit or rollback ends the outer one too.

all_assets(kind=None)

append_history(asset_id, record)

close()

Close the connections this process opened; later calls reopen them.

delete_asset(user_id, asset_id)

delete_history(asset_id)

find_by_id_or_title(ref, identity=None, *, default_allow=True)

list_assets(user_id, kind=DASHBOARD_KIND)

load_asset(user_id, asset_id)

load_history(asset_id)

rename_asset(user_id, asset_id, new_title)

replace_history(asset_id, records)

rewrite_history(asset_id, rewrite)

save_asset(dashboard)

set_owner(asset_id, owner)

set_permission(asset_id, permission)

Persist a new permission set on a dashboard. Returns success.

title_exists(user_id, title, exclude_id=None, kind=DASHBOARD_KIND)

Check if a dashboard of kind with the given title already exists for this user.

AssetStoreError

Bases: Exception

A store refused an operation for a reason the user should see.

Raise it from a :class:BaseAssetStore method to reject a request, for example a duplicate title, a name the backend cannot store or a missing permission. The app shows the message to the user as written and leaves its state unchanged, so phrase it for an end user. Any other exception is treated as a bug or an infrastructure failure and is logged with its traceback.

AssetTurn dataclass

One request to an agent, or one batch of a person's edits, that changed a dashboard.

Attributes:

Name Type Description
id str

Unique within the dashboard and never reused, so the nodes' origin and the edit history can refer to it.

actor str | None

"agent" or "user". A planned turn may leave it out.

at str | None

When the turn's first edit was made, as ISO 8601 UTC, e.g. "2026-11-17T20:14:03Z".

run str | None

The panel-agents run id of the agent's request.

question str | None

What the person asked the agent. Recorded by default; exports can leave it out, see :func:~panel_flowdash.editor.export_model.

summary str | None

What the turn changed, a few words per change.

status str | None

None for a turn that ran, "pending" for a planned one that has not.

actor = None class-attribute instance-attribute

at = None class-attribute instance-attribute

id instance-attribute

question = None class-attribute instance-attribute

run = None class-attribute instance-attribute

status = None class-attribute instance-attribute

summary = None class-attribute instance-attribute

from_dict(data) classmethod

Read a turn written by :meth:to_dict, ignoring keys it does not know.

Raises:

Type Description
TurnError

If a field has the wrong type or value, or one that is required is missing.

to_dict()

Return the turn as JSON data, leaving out fields that are not set.

BaseAssetStore

Bases: ABC

The persistence interface the editor and app shell depend on.

Subclasses implement the six storage primitives below; the access-control and lookup helpers are backend-independent and inherited. Implement this to back dashboards with something other than SQLite.

To refuse a create, save, rename, delete or permission change, raise :class:AssetStoreError with a message for the user.

Stores that detect concurrent edits keep a revision per dashboard: every save stores dashboard.revision + 1 (see :func:check_revision), and a save based on an older revision than the stored one raises :class:AssetConflictError. A store that does not support revisions simply ignores the field and saves last-writer-wins.

Models returned by listings may be shared with a backend cache, so callers treat them as read-only; single-dashboard lookups return private copies.

Set :attr:random_ids to False in a store whose ids can be guessed.

random_ids = True class-attribute instance-attribute

Whether dashboard ids are random, so only someone given a link knows one.

The default :meth:create_asset makes random ids. A store whose ids can be guessed (derived from titles, say) sets this to False, and the app then answers a dashboard someone may not open exactly like a missing one, rather than saying it exists and who owns it. Even with random ids, an id a caller chose when saving (see :meth:guessable_id) is treated so.

all_assets(kind=None)

Every stored dashboard regardless of owner, most recently updated first.

kind keeps only assets of that kind ("dashboard", "report" or "chat"); None keeps every kind. No access check is applied: use :meth:list_accessible for what a user may open. Some stores hand out shared, cached models, so copy one (or load it with :meth:load_asset) before changing it. Custom stores implement :meth:_all_assets, not this method.

append_history(asset_id, record)

Add a record to the end of a dashboard's edit history.

Does nothing when the dashboard is not stored, e.g. because it was deleted while an editor still had it open.

can_administer(identity, asset_id, admin_groups=frozenset())

Whether identity may administer (rename/delete/share) the dashboard.

Administering includes editing, see :meth:can_edit.

can_administer_model(identity, dashboard, admin_groups=frozenset())

Like :meth:can_administer, for a dashboard that is already loaded.

Listings use it to avoid loading every dashboard a second time. Override this method, not :meth:can_administer, to change who may administer a dashboard.

can_edit(identity, asset_id, admin_groups=frozenset())

Whether identity may edit and save the dashboard's contents and settings.

can_edit_model(identity, dashboard, admin_groups=frozenset())

Like :meth:can_edit, for a dashboard that is already loaded.

Administrators (see :meth:can_administer_model) may always edit; anyone else needs an allow_edit_users/allow_edit_groups grant on the dashboard's permission. Override this method, not :meth:can_edit, to change who may edit a dashboard. A chat is edited only by its owner, administrators included.

create_asset(user_id, title, kind=DASHBOARD_KIND)

Create, persist and return a new empty dashboard (or chat or report, with kind).

A report starts with an empty document, so it never reads as the report a dashboard derives from its tiles.

delete_asset(user_id, asset_id) abstractmethod

Delete a dashboard owned by user_id. Returns whether one was removed.

delete_history(asset_id)

Drop a dashboard's edit history.

find_by_id_or_title(ref, identity=None, *, default_allow=True)

Resolve a dashboard by its id first, then by title.

Titles are only unique per user, so a title can match several dashboards. Without identity (trusted code, such as :meth:FlowDash.load) the most recently updated match is returned.

With identity, as when resolving the operator-configured home dashboard, a dashboard the identity may not open is never returned. The identity's own dashboard with that title wins. Otherwise a title owned by a single user resolves to that user's most recently updated dashboard, while a title owned by several users is ambiguous and resolves to None (the app then shows the launcher) with an error logged asking for the dashboard id. Picking one of them instead would let any user take over everyone's home page by creating a dashboard with the same title.

get_owner(asset_id)

Return the owner (user_id) of a dashboard, or None if missing.

guessable_id(asset_id)

Whether asset_id could be guessed rather than only learned from a link.

Only ids of the form :meth:create_asset makes count as random in a store with :attr:random_ids. Any store saves whatever id a model carries, so one chosen by the caller, like the slug an example seeds its dashboards under, can be guessed. A store whose own ids look different overrides this.

list_accessible(identity, *, default_allow=True, kind=DASHBOARD_KIND)

List dashboards of kind the identity owns or has been granted access to.

Chats are left out unless kind is "chat" or None, and only the identity's own chats are ever listed. Owned dashboards sort first (both groups by recency), so a user's own dashboards stay visually grouped ahead of ones shared with them.

list_assets(user_id, kind=DASHBOARD_KIND)

Dashboards of kind owned by user_id, most recently updated first.

Pass kind="chat" for the user's chats, kind="report" for their reports, or None for every kind.

load_asset(user_id, asset_id)

Load a dashboard, but only if user_id owns it.

load_for_access(identity, asset_id, *, default_allow=True)

Load a dashboard if identity is authorized, else None.

Returns None both when the dashboard does not exist and when access is denied, so callers render a single "not found / denied" view.

load_history(asset_id)

Return the edit history records of a dashboard, oldest first.

rename_asset(user_id, asset_id, new_title) abstractmethod

Retitle a dashboard owned by user_id. Returns whether one was updated.

replace_history(asset_id, records)

Replace a dashboard's edit history, e.g. with what retention keeps of it.

rewrite_history(asset_id, rewrite)

Replace a dashboard's history with what rewrite returns for it, and return that.

rewrite returns its argument itself when nothing changes, which writes nothing. Stores used by several sessions at once override this to read and write in one transaction, so no record appended meanwhile is lost.

save_asset(dashboard) abstractmethod

Insert or update a dashboard.

Stores that support revisions refuse a dashboard whose revision is not the stored one with :class:AssetConflictError, as one atomic check and write, and on success set dashboard.revision to the stored revision. Renaming a dashboard or changing its permission does not change its revision.

set_owner(asset_id, owner)

Give a dashboard to owner. Returns whether one was updated.

Only the admin view calls it, after checking that the caller is an admin. Like renaming, it does not change the dashboard's revision. A store that cannot change owners raises :class:AssetStoreError, as this default does.

set_permission(asset_id, permission) abstractmethod

Persist a new permission set on a dashboard. Returns success.

title_exists(user_id, title, exclude_id=None, kind=DASHBOARD_KIND)

Check if a dashboard of kind with the given title already exists for this user.

DashboardGroup dataclass

Nodes framed together on the canvas.

Attributes:

Name Type Description
id str

Unique within the dashboard, a name like the dashboard YAML's node names.

label str | None

Shown in the group's header; the id is shown when it is None.

nodes list[str]

Instance ids of the nodes in the group, in the order they were grouped.

collapsed bool

Whether the canvas draws the group as one node.

collapsed = False class-attribute instance-attribute

id instance-attribute

label = None class-attribute instance-attribute

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

title property

from_dict(data) classmethod

to_dict()

DashboardParameter dataclass

A named pointer to one config field of one node.

Attributes:

Name Type Description
node str

The node: its instance id in a :class:~panel_flowdash.AssetModel, its name in the YAML.

field str

A dotted path into the node's config, e.g. ref or spec.tables.orders; a number indexes a list.

type str

One of :data:PARAMETER_TYPES.

description str | None

What the parameter is, for whoever binds it.

expects dict[str, Any] | None

What the dashboard relies on of a bound value, as the node's component's :class:ParameterContract recorded it. Opaque to FlowDash.

description = None class-attribute instance-attribute

expects = None class-attribute instance-attribute

field instance-attribute

node instance-attribute

type = 'value' class-attribute instance-attribute

from_dict(data) classmethod

Read a parameter, raising :class:ParameterError if it is malformed.

to_dict()

Identity dataclass

The resolved principal for a session.

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

oauth_user = None class-attribute instance-attribute

system_user = None class-attribute instance-attribute

user instance-attribute

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

user_names property

All names this identity may be referenced by in a rule.

in_groups(groups)

Whether the identity belongs to any of groups.

is_user(users)

Whether the identity matches any of users (OAuth or system name).

MemoryAssetStore

Bases: BaseAssetStore

Dict-backed store for notebooks, scripts and tests.

Dashboards live for as long as the store does and are never written to disk. Models are deep-copied in and out so a caller mutating a dashboard it saved (or loaded) cannot retroactively change what is stored, matching how the SQLite store behaves.

append_history(asset_id, record)

delete_asset(user_id, asset_id)

delete_history(asset_id)

load_history(asset_id)

rename_asset(user_id, asset_id, new_title)

replace_history(asset_id, records)

rewrite_history(asset_id, rewrite)

save_asset(dashboard)

set_owner(asset_id, owner)

set_permission(asset_id, permission)

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.

_OpenConnection dataclass

conn instance-attribute

pid instance-attribute

thread instance-attribute

_close_all(connections, lock)

_decode_revision(value)

Return a stored revision, or None (no conflict check) if it is not an integer.

_init_asset_model(self, *args, **kwargs)

_migrated(version)

Return the model version a stored one is read as: older ones are upgraded on load.

_of_kind(models, kind)

_parse_sqlite_time(value)

Parse a SQLite datetime('now') value, which is UTC without an offset.

_rename_dashboard_tables(conn)

Rename the tables and id columns of a database written before dashboards became assets.

Runs in one transaction, so a database is either migrated whole or left as it was, and a second process opening it meanwhile waits and then finds nothing left to rename.

add_legacy_methods(cls)

Keep a store class working with the method names stores had before the rename.

Every public method taking asset_id also accepts the deprecated dashboard_id= keyword. A subclass written against the old names overrides, say, save_dashboard: its override then also serves as save_asset, which the app calls. For each new method the class implements itself, the old name is kept as a deprecated alias calling it.

blank_report()

Return the document a new report starts with: no blocks.

can_administer(identity, owner, admin_groups)

Whether identity may administer a resource owned by owner.

The owner and members of admin_groups may administer a resource; nobody else may. In an auth-less deployment every session resolves to the same system user, which owns every dashboard it creates, so such a deployment stays fully editable without configuring admin groups.

can_edit(permission, identity, owner, admin_groups)

Whether identity may edit the contents of a dashboard owned by owner.

Everyone who may administer it may edit it. Otherwise the identity must match an allow_edit_users/allow_edit_groups rule and no deny rule. Editing covers changing and saving the canvas and the dashboard settings, not renaming, deleting or sharing it, which stay administration.

check_revision(dashboard, stored)

Return the revision to store dashboard at, given the stored one.

Raises :class:AssetConflictError if dashboard was loaded at a revision other than the stored one. A model with no revision (None) is saved unconditionally, and stored is None when the dashboard is not stored (new, or deleted since it was loaded).

decode_filters(value)

Return the filters a stored dashboard holds, empty if none; ValueError when malformed.

decode_groups(value)

Return the groups a stored dashboard holds, raising ValueError when malformed.

A node in more than one group stays in the first, and groups left with no node are dropped.

decode_kind(value)

Return the stored value as a dashboard kind; missing reads as a dashboard.

decode_parameters(value)

Return stored parameters, which may be missing (None), by name.

Raises TypeError unless they are a mapping, and :class:ParameterError for a malformed parameter. Parameters are optional, so the stores catch this and drop just the parameters, with a warning.

decode_report(value)

Return the report a stored dashboard holds, None if it has none; ValueError when malformed.

decode_settings(value)

Return a private copy of stored dashboard settings, which may be missing (None).

Raises TypeError unless they are a mapping with string keys. Settings are optional, so the stores catch this and drop just the settings, with a warning, rather than skipping the whole dashboard.

decode_source(value)

Return a stored source asset id, or None when it is missing or not a string.

decode_turns(value)

Return stored turns, which may be missing (None), as a list of :class:AssetTurn.

Raises TypeError unless they are a list, and :class:TurnError for a malformed turn or two turns with the same id. Turns are optional, so the stores catch this and drop just the turns, with a warning, rather than skipping the whole dashboard.

initial_permission(user_id, kind)

Return the permission a new dashboard of kind starts with.

A chat starts allowed to its owner alone, so a store that drops kind turns it into a dashboard only its owner may open rather than one everybody may.

is_authorized(permission, identity, *, default_allow=True, owner=None)

Evaluate permission against identity.

Order of precedence:

  1. A matching deny_users/deny_groups rule denies access (deny always wins, even for the owner).
  2. The owner, if given and matching, is allowed.
  3. An identity granted editing (allow_edit_users/allow_edit_groups) is allowed, since editing includes viewing.
  4. Any allow_users/allow_groups rule present: allowed iff the identity matches at least one of them.
  5. No allow/deny rules at all: fall back to default_allow.

may_view(dashboard, identity, *, default_allow=True)

Whether identity may open dashboard.

A chat is private to its owner: no sharing rule or default grants it to anyone else. Other dashboards follow their permission, see :func:~panel_flowdash.auth.is_authorized.

module_getattr(module, names)

Return a module __getattr__ resolving deprecated names (old to new) with a warning.

old_names(module_globals)

Return the deprecated class names a module keeps, old to new, for its own new classes.

renamed_kwarg(kwargs, old='dashboard_id', new='asset_id')

Move a deprecated keyword argument old in kwargs to new, warning once.

warn_renamed(old, new, stacklevel=3)