Project File¶
The project file, flowdash.yaml, holds the settings of a FlowDash app
that belong to the deployment rather than to one dashboard, such as an
extension's shared definitions. It is a YAML mapping of named sections:
# flowdash.yaml
metrics: # read by the extension that registered `metrics`
capacity:
table: plants
sum: capacity_mw
FlowDash registers general, theme, ai, permissions and
components, which the admin view edits;
extensions add theirs, see
Add a Project File Section.
Built-in sections¶
The admin view (/admin, the Admin item at the bottom of the rail) writes
these. A setting the app is also given in code, in the project's
__init__.py, on the command line or as a FlowDashApp parameter, keeps
the value from code and shows locked in the admin view. Each takes effect
for pages opened after it is saved.
general:
admins: [local:philipp, auth:ana@example.com] # who may open Admin, besides admin_groups
edit_workspace: split # dataflow, layout or split (FlowDash.mode)
home_dashboard: fleet # a dashboard id or title (home_dashboard)
live_values: hover # click, hover or off (popup_trigger)
history: true
history_coalesce: 3 # seconds
history_limit: 500 # versions
history_max_days: 90
history_max_mb: 16
explore: read_only # ask or read_only (explore_agent=False)
agent_palette: true
provenance: true
tile_cards: true # defaults for dashboards that do not set their own
tile_titles: false
node_previews: false
controls_position: left # top or left
theme:
color_scheme: dark # system (the default: follows the browser), light or dark
primary_color: "#006D77"
font_family: Inter # Roboto, Inter, IBM Plex Sans, Source Sans 3, Open Sans or System UI
border_radius: 6
title: Wind Energy Explorer
logo: logo.svg # a URL, or a path relative to the project file
favicon: favicon.png # the same; without one, it is made from the logo
Without a favicon, the browser tab shows one made from the logo: an SVG
logo as it is, any other image padded to a 32 px square. The Apple touch
icon (180 px, on white) is made from the logo too. Both are embedded in the
page, so they work offline. A favicon file that is missing or isn't an
image is not used. Admin › Theme can upload a favicon or write one made
from the logo into the project directory; saving it updates the open tab's
icon without a reload. In code, page_options takes favicon and
apple_touch_icon.
The ai section lists the model providers and the models people may pick
in the assistant and Explore. Models given in code (agent_models,
--agent-model) come first; an entry with the same id adds its offer,
settings and limit to them. The admin view saves each change to it as it
is made, and sessions started afterwards use it.
ai:
default: openai:gpt-6-luna
providers:
openrouter:
api_key: ${OPENROUTER_API_KEY} # or a key stored encrypted, see Secrets
ollama:
base_url: http://127.0.0.1:11434
models:
- id: openai:gpt-6-luna
label: Luna
offered_to: [assistant, explore] # the default; [] offers it nowhere
groups: [analysts] # only for these groups; omit for everyone
settings: {max_tokens: 1000} # temperature, max_tokens, timeout
monthly_limit: 50 # US dollars, for everyone together
person_limit: 5 # US dollars, for each person
fallback: anthropic:claude-haiku-5.5 # used at either limit; without one, requests are refused
person_limit is counted per signed-in user name, so it is only as strict
as sign-in. Without sign-in every visitor is the server's account and counts
as one person, and with a single shared password (--basic-auth) anyone can
sign in under a new name and start again; rely on monthly_limit there.
The spend counted against monthly_limit and person_limit is kept in .flowdash/usage.json
beside the project file, with who last opened the app; processes sharing
the project update it under a file lock.
If the project file cannot be read, for example while it holds a merge conflict, the permissions last read from it stay in force, and an app that has never read them denies access with an error page until it is fixed.
The permissions section is layered under the app's auth_config:
default_allow and admin_groups apply when the project's __init__.py
does not set them, and the sensitive components and approval rules are
added to agent_sensitive_components and agent_approval_rules.
permissions:
default_allow: false # dashboards nobody shared are private
admin_groups: [admins]
people:
ana: {groups: [analysts]} # added to the groups from code and sign-in
priya: {assistant: false} # no assistant for priya
assistant_groups: [analysts, admins] # who gets the assistant, unless agent_authorize is set
sensitive_components: ["Lumen/deckgl"]
approval_rules:
- tool: run_command
when: {command: "action:refresh"} # argument values; text may use * wildcards
- tool: run_sql
enabled: false
The components section turns components off and limits who may place
them. A component turned off is left out of the component list, the
command palette and the agent's components, and nobody can add it to a
dashboard; dashboards that already have it keep working, and their editors
are told when they open one. placed_by limits adding it to members of
those groups, without changing who may view or edit dashboards that have
it, and approval: true adds it to agent_sensitive_components. The
admin view's Components page saves each change as it is made.
components:
panel_flowdash/image:
enabled: false
wind_maps/turbine_map:
placed_by: [analysts]
approval: true
The admin view's Assets page works on the asset store rather than the
project file: it lists every dashboard (or, with its Kind filter, every
chat, or both) with its owner, history and access, and lets admins share, change the owner of, download, prune the
history of and delete several at once. Each of these asks for
confirmation, checks again that the caller is an admin, and is noted with
who made it and when in the admin log in .flowdash/usage.json, which
also records when each dashboard was last opened. Every save in the other
sections checks again too, so an admin removed meanwhile cannot save from
a page left open.
In general.admins, local:<name> is an account that runs the server
without sign-in and auth:<name> a signed-in user, so turning sign-in on
later never makes a signed-in user admin because they share a local
account's name. A name without either prefix, as earlier versions wrote,
is a local account. A name added in the admin view gets the prefix of how
the server runs.
Without a project file the admin view writes flowdash.yaml in the project
directory on the first save. An app with no project directory, such as
FlowDashApp(registry=...) or panel serve app.py, uses flowdash.yaml in
the working directory instead: it is read at startup if it is there and
created on the first save, and the admin sidebar shows its full path. Until
then such an app writes nothing and keeps spend, visits and the admin log in
memory; once the file exists, .flowdash/usage.json goes beside it. Every
app without a project directory in one process shares that one file, so
apps served together with pn.serve({"/a": ..., "/b": ...}) share their
title, theme, admins and models; give each a project_dir or a project to
keep them apart. Pass project=Project() to keep settings in memory only.
Where it is found¶
flowdash serve reads, in order:
- the file given with
--project FILE(relative to the working directory), flowdash.yamlin the served project directory.
A flowdash.yaml in the working directory is not read when a directory is
served. Without either the app runs without a project file. An embedded app
passes it as FlowDashApp(project="flowdash.yaml"), or a Project already
loaded with panel_flowdash.project.load_project. Apps that serve data
files can look beside them with find_project([data_file, ...]), which
checks the directory of each local file or folder in turn, then the working
directory.
Loaders receive a context: flowdash serve and FlowDashApp pass
project_dir and registry; an app can pass its own with
load_project(path, context={...}).
Rules¶
| Rule | What happens otherwise |
|---|---|
| The file is a YAML mapping of sections. | Startup fails. |
| A key appears once per mapping. | Startup fails at the second occurrence. |
| Keys are text. | Startup fails. |
| A section is registered by FlowDash or an installed extension. | The section is ignored with a warning naming the known sections, so a file written for a newer app or for an extension that is not installed still loads. |
| A registered section is valid for its loader. | Startup fails. |
Every problem found is reported together, each as
FILE:LINE:COLUMN: message pointing at the value at fault, and with the
section and keys of that value, e.g.
The file is read as YAML 1.2, so only true and false are booleans and
yes, no, on, off or 1:20 are text. When FlowDash writes a section
it quotes such text, so YAML 1.1 readers read it the same.
Problems that do not stop the app, such as unknown sections or a loader's
Section.warn, are logged with their position and kept in
Project.warnings.
Secrets¶
Sections name secrets by environment variable, ${NAME} or
${NAME:-default}, and never hold the value. Loaders keep the reference
and expand it with expand_env where it is used, and dump writes the
reference back. See Secrets.
A model provider's api_key may instead be stored encrypted from the admin
view (Replace key), which needs pip install 'panel-flowdash[secrets]'.
The file then holds {encrypted: ..., key_id: ...}, made with Fernet. The
key is FLOWDASH_SECRET_KEY (several, comma-separated, to rotate: the
first encrypts and all decrypt), else the OS keyring, else a key file
made with mode 0600 at ~/.config/flowdash/secret.key
(FLOWDASH_SECRET_KEY_FILE). Servers sharing a project share
FLOWDASH_SECRET_KEY.
When people sign in (OAuth, or basic auth with a users file, but not one
shared --basic-auth password), a key is stored encrypted only with
FLOWDASH_SECRET_KEY set: the keyring and the key file belong to the
server's account rather than the deployment, so they are not offered, and
the admin view and setup wizard say why. ${VAR} references always work.
A key stored before with the keyring or key file still decrypts; it stays
in the file until an admin replaces it with a reference or sets
FLOWDASH_SECRET_KEY and enters it again.
The keyring and the key file belong to the user who saved the key, so on a
project shared through version control or a network drive, where each
person runs the app themselves, a stored key only decrypts for that user.
Use ${VAR} references there and let each person set the variable. On
Windows the key file is protected by the user profile's permissions, not
by mode 0600. A key is never written to the file in plain text,
shown in the admin view (only its last four characters), logged or put
into the process environment; it goes to the provider's client.
Python API¶
| Name | Description |
|---|---|
load_project(path, context=None) |
Read and load a project file, raising ProjectError with every problem. |
parse_project(text, path=None, context=None) |
The same for YAML text. |
find_project(places=(), cwd=None) |
The flowdash.yaml beside the first of places that has one, else in cwd, or None. |
Project.get(name, default=None) |
The value the section's loader returned. |
Project.raw(name) |
The section's YAML data. |
Project.set(name, value) |
Validate the section with its loader and write it back, keeping the rest of the file. |
Project.warnings |
The warnings found while loading, as Problems. |
Section.warn(path, message) |
Report a problem that does not stop loading. |
expand_env(value) |
Expand ${NAME} references in text, lists and mappings. |
Project.problem(path, message, key=False) |
A Problem positioned at a value, or at its key. |
register_section(section) |
Register a ProjectSection, or register_section(name, loader, **fields). |
sections() |
The registered sections, including those of entry points. |
ProjectSection |
name, loader, title, icon, description, dump, settings_view. |
SectionError(message, path=(), key=False) |
Raised by a loader for one problem. |
ProjectError(problems) |
Raised for the problems of a file; problems lists each Problem. |
Entry points in the panel_flowdash.project_sections group are registered
the first time sections are looked up.
panel_flowdash.project
¶
Read and write the project file, flowdash.yaml.
The project file is one YAML 1.2 file of named sections that configure a
FlowDash app, e.g. the admin settings or an extension's metrics:. Every
key and value keeps the line and column it is written at, so a problem is
reported where it is.
flowdash serve reads flowdash.yaml (PROJECT_FILE), given with
--project or found in the served directory (find_project). Each
top-level section is read by the loader registered for it
(register_section); a section no one registered is ignored with a
warning, so a file written for a newer app or for an extension that is not
installed still loads.
A ProjectSection is the unit an extension registers, programmatically
or through the panel_flowdash.project_sections entry point group: the
section's loader, its dump for writing it back and, optionally, the
factory of its admin settings tab.
Dumper = Callable[[Any], Any]
module-attribute
¶
ENTRY_POINT_GROUP = 'panel_flowdash.project_sections'
module-attribute
¶
FILE_LOCK = threading.RLock()
module-attribute
¶
KEY = object()
module-attribute
¶
Loader = Callable[['Section'], Any]
module-attribute
¶
PROJECT_FILE = 'flowdash.yaml'
module-attribute
¶
SettingsView = Callable[['Project', bool], Any]
module-attribute
¶
WizardView = Callable[['Project'], Any]
module-attribute
¶
_AMBIGUOUS = re.compile('^(?:y|Y|yes|Yes|YES|n|N|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF|~|null|Null|NULL|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+(?:\\.[0-9_]*)?)$')
module-attribute
¶
_COMMENT = re.compile('(?:^|\\s)(#.*)$', re.MULTILINE)
module-attribute
¶
_ENV_REFERENCE = re.compile('\\$\\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\\}')
module-attribute
¶
_FILE_LOCK = FILE_LOCK
module-attribute
¶
_NOT_A_MAPPING = 'A project file is a mapping of sections, e.g. `metrics:`.'
module-attribute
¶
_REGISTRY_LOCK = threading.RLock()
module-attribute
¶
_SECTIONS = {}
module-attribute
¶
_SHARING_RETRY_SECONDS = 2.0
module-attribute
¶
__all__ = ['ENTRY_POINT_GROUP', 'FILE_LOCK', 'KEY', 'PROJECT_FILE', 'Problem', 'Project', 'ProjectError', 'ProjectSection', 'Section', 'SectionError', 'current_raw_section', 'current_section', 'expand_env', 'find_project', 'load_entry_points', 'load_project', 'parse_project', 'parse_project_data', 'register_section', 'sections', 'unregister_section']
module-attribute
¶
_entry_points_loaded = False
module-attribute
¶
_entry_points_loading = False
module-attribute
¶
_parse = parse_project_data
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
Problem
dataclass
¶
A problem in a project file.
path, line and column say where it is written; section
and keys say which value it concerns, e.g. "metrics" and
("capacity", "table"), so a settings form can show it at its field.
Project
dataclass
¶
A loaded project file.
It holds the raw data, where each key and value is written, by path
(e.g. ("metrics", "capacity", "table")), the value each registered
loader made of its section, the warnings found while loading and the
context the loaders were given.
context = field(default_factory=dict)
class-attribute
instance-attribute
¶
data = field(default_factory=dict)
class-attribute
instance-attribute
¶
directory
property
¶
Return the directory the file is in, against which paths it names resolve.
path = None
class-attribute
instance-attribute
¶
positions = field(default_factory=dict)
class-attribute
instance-attribute
¶
warnings = field(default_factory=list)
class-attribute
instance-attribute
¶
get(name, default=None)
¶
Return the value of section name, or default if the file has none.
The value is what the section's loader returned. A section whose loader
was registered after the file was loaded is loaded now (raising
ProjectError); a section no loader is registered for gives its
raw data.
load_all()
¶
Load every section a loader is registered for, warning about the others.
Raises ProjectError with every problem the loaders found.
position(path)
¶
Return the 1-based line and column of the value at path.
A path that is not in the file gives the position of its nearest enclosing value.
problem(path, message, key=False)
¶
Return a problem at the value at path (with key, at the key naming it).
raw(name, default=None)
¶
Return the raw YAML data of section name.
set(name, value)
¶
Set section name to value and write it to the project's file.
The value goes through the section's dump and the result through
its loader, so a value the loader rejects raises ProjectError,
positioned where it would be written, and the file is left alone.
Only the lines of this section change in the file; comments inside it
are not kept. Text a YAML 1.1 reader would take for something else,
such as no or 1:20, is quoted.
update(name, change)
¶
Change section name from its raw data as the file has it now, and write it.
change is called with a copy of the section's raw YAML data, read
again from the file (None when the file has no such section), and
returns the new value, which is written as set writes it. The read,
change and the write happen under FILE_LOCK, so no other write
from this process comes in between. An exception from change
leaves the file alone. Returns the value written.
ProjectError
¶
Bases: ValueError
The problems of a project file, each with the file, line and column it concerns.
problems = list(problems)
instance-attribute
¶
ProjectSection
dataclass
¶
A top-level section of the project file, as an extension registers it.
loader turns the section's raw YAML data (Section.value) into
the typed value Project.get(name) gives, reporting problems by
raising SectionError (one problem at a path in the section) or
ProjectError (several, made with Section.problem) and warnings
with Section.warn; a ValueError or TypeError is reported at
the section's key. dump turns a typed value back into plain YAML
data for Project.set; without it the value is written as it is.
settings_view(project, editable), if given, builds the section's page
in the admin view, listed under the heading group, e.g. "Data".
wizard_view(project), if given, builds the section's step of the setup
wizard (a panel_flowdash.admin.wizard.WizardStep or a SettingsForm);
a "Data" section's step takes the place of the wizard's Data step,
any other comes after People. The wizard writes nothing until its Review.
description = ''
class-attribute
instance-attribute
¶
dump = None
class-attribute
instance-attribute
¶
group = 'Extensions'
class-attribute
instance-attribute
¶
icon = None
class-attribute
instance-attribute
¶
label
property
¶
Return the title, or one made from the name.
loader
instance-attribute
¶
name
instance-attribute
¶
settings_view = None
class-attribute
instance-attribute
¶
title = ''
class-attribute
instance-attribute
¶
wizard_view = None
class-attribute
instance-attribute
¶
Section
dataclass
¶
One top-level section of a project file, as a loader receives it.
context
property
¶
Return what the app loaded the project with, e.g. its data sources.
name
instance-attribute
¶
project
instance-attribute
¶
value
instance-attribute
¶
position(path=())
¶
Return the line and column of the value at path in this section.
problem(path, message, key=False)
¶
Return a problem at the value at path in this section (with key, at its key).
warn(path, message, key=False)
¶
Report a problem at path that does not stop the section from loading.
SectionError
¶
Bases: ValueError
A section loader's problem at path inside its section.
path is e.g. ("capacity", "table"). With key=True the problem
is reported where the last key of path is written instead of its value.
_anchor_owners(node, owner, owners, shared)
¶
Record the top-level key that first holds each node under node.
A node met again under another key is an alias of an anchor defined
earlier; it is added to shared with its anchor and both keys.
_build(yaml, node, path, positions, problems, source)
¶
_check_anchors(text, name, source)
¶
Refuse to replace section name when another key aliases an anchor defined in it.
_check_written(name, value, old, new, source)
¶
_dump(document)
¶
_mark(node)
¶
_plain(value, quote=False)
¶
Return value with tuples as lists and, with quote, ambiguous text quoted.
_problem(message, source, line, column, path)
¶
_qualname(loader)
¶
_read(path)
¶
_register_entry_point(entry_point)
¶
_replace_section(text, data, positions, name, value, source=None)
¶
Return text with section name set to value and its other lines untouched.
_retry_sharing(operation)
¶
Run operation, retrying a Windows sharing violation for a bounded time.
_rewrite(text, data, name, value, source)
¶
Return text written whole with section name set to value.
ruamel's round trip keeps the comments and merge keys it can; whatever it cannot keep, or a file it does not read back the same, is logged.
_write_atomically(target, text)
¶
Replace target with text through a temporary file in its directory.
current_raw_section(project, name, default=None)
¶
Return a copy of the raw YAML data of section name as the project file has it now.
The file is read again under FILE_LOCK, so what another process wrote
since the project was loaded counts; without a file it is the project's
own data. default when the section is not there. Raises
ProjectError when the file cannot be read or parsed.
current_section(project, name)
¶
Return section name as the project file has it now, loaded by its loader.
The file is read again, so what another process wrote since the project was loaded counts; without a file, or if it cannot be read, the loaded value is returned. None when the section is not in the file.
error_text(exc)
¶
Return an exception's message with its credentials masked, to show a user or an agent.
expand_env(value, environ=None)
¶
Replace ${NAME} and ${NAME:-default} references with environment values.
Text in value, or in the lists and mappings it holds, is expanded;
other values are returned as they are. Raises ValueError naming a
variable that is not set and has no default. A loader keeps the
reference and expands it where it is used, so dump writes the
reference back and never the secret.
find_project(places=(), cwd=None)
¶
Find the project file an app reads when none is given.
It is PROJECT_FILE in the first of places that has one (a local
directory, or a local file whose directory is used; URLs and other
values are skipped), else in cwd (the working directory by default).
None if there is none.
load_entry_points(force=False)
¶
Register the sections installed packages declare as entry points, once.
The group is panel_flowdash.project_sections. Each entry point names
a ProjectSection, a sequence of them, or a callable returning either.
One that fails to load is skipped with a warning. Concurrent callers
wait until every entry point is registered.
load_project(path, context=None, *, lazy=False)
¶
Read and parse the project file at path, see parse_project.
parse_project(text, path=None, context=None, *, lazy=False)
¶
Parse the project file in text and load each registered section.
context is handed to the loaders as Section.context. Raises
ProjectError with every problem found: invalid YAML, a file that is
not a mapping, a key given twice or a section its loader rejects.
Unknown sections and loader warnings are logged and kept in
Project.warnings.
With lazy, no section is loaded now: each is loaded when first asked
for with Project.get, so a section the file gets wrong is reported
where it is used rather than stopping whoever reads the file.
parse_project_data(text, source=None)
¶
Parse the project file in text into its raw data and the positions of its values.
Nothing is loaded: the data is the YAML as written, and the positions map
each value's path (see Project.positions) to its 1-based line and
column. source names the file in problems. Raises ProjectError
for invalid YAML, a file that is not a mapping or a key given twice.
register_section(section, loader=None, **fields)
¶
Register a section of the project file and return it.
The section is a ProjectSection, or its name with its loader and
other ProjectSection fields. Registering a name again replaces it,
so a module that is reloaded can register again.
sections()
¶
Return the registered sections by name, including those of installed extensions.
unregister_section(name)
¶
Remove the section name from the registry, if it is registered.