CLI reference¶
plotsrv includes a small CLI for starting the server, watching files, creating config, populating config, and managing stored outputs.
Note
Workflows can also be controlled through Python code. See Python API.
Run the server¶
Start plotsrv on the default address:
Open:
Run against a script:
Run against a package or directory:
Choose a host and port:
What plotsrv run does¶
plotsrv run starts the browser UI and scans the target for plotsrv views.
It looks for:
@ps.view(...)decorators- simple
publish_view(...)calls
This lets plotsrv pre-populate the UI with known views before data has been published.
For example:
import plotsrv as ps
@ps.view(label="daily import", section="pipelines")
def daily_import_status():
return {"status": "ok"}
Running:
allows plotsrv to discover the daily import view.
Publish to a running server¶
After starting plotsrv:
publish to it from Python:
import plotsrv as ps
ps.publish_view(
{"status": "ok"},
label="daily import",
section="pipelines",
host="127.0.0.1",
port=8000,
)
When host or port is supplied without launch_server=True, publish_view() publishes to an existing plotsrv server.
It does not start a server.
Callable mode¶
plotsrv run can call a function directly.
For example, given:
run:
To call repeatedly:
Callable mode is useful for simple demos or functions that can be called without required arguments.
Watch files¶
Note
Use plotsrv run rather than plotsrv watch if also publishing content from python scripts (see below). If in doubt, stick to plotsrv run.
Watch one file:
Watch a log from the tail:
Watch a CSV file:
Attach watched files while running the server:
plotsrv run --host 127.0.0.1 --port 8000 \
--watch ./logs/job.log \
--watch-label "job log" \
--watch-section "files" \
--watch-tail
Watch multiple files:
plotsrv run --host 127.0.0.1 --port 8000 \
--watch ./logs/job.log \
--watch ./outputs/results.csv \
--watch ./outputs/status.json \
--watch-label "job log" \
--watch-label "results" \
--watch-label "status"
Watch options¶
Common watch options:
| Option | Purpose |
|---|---|
--watch PATH |
add a file to watch when running the server |
--watch-label LABEL |
set the view label for a watched file |
--watch-section SECTION |
set the section for a watched file |
--watch-head |
read from the start of the file |
--watch-tail |
read from the end of the file |
--watch-max-bytes N |
limit how much of the file is read |
--watch-kind auto/text/json |
control file interpretation |
For standalone plotsrv watch, the equivalent options are:
Create config¶
Simply create a plotsrv.yml file in the project root, or create a starter config:
Overwrite an existing config:
The generated config is intended as a starting point. Edit it to enable storage, freshness, UI settings, and limits.
Populate config¶
plotsrv can scan code and add per-view config entries. If needing view specific settings, this can save typing the view section:label ids within the config file.
Note
The default config file created with plotsrv config create contains placeholders for global freshness, storage and limit parameters. If not needing view specific settings, use these. Otherwise use the populate commands below.
Populate freshness settings:
Populate storage settings:
Populate limits:
Scan a specific file:
Scan a source directory:
Populate modes¶
Merge generated entries into an existing config:
Replace generated entries:
Skip confirmation prompts:
Store commands¶
Storage commands inspect and clear persisted plotsrv output.
Show storage statistics:
List stored material:
List a specific view:
Clear a specific view:
Clear all stored material:
Warning
plotsrv store clear --all removes stored material, including latest restored state and snapshot history.
Common command patterns¶
Quick local check¶
where the script contains:
Server workflow¶
Terminal 1:
Terminal 2:
where the script publishes with:
Server plus watched log¶
plotsrv run demo_pipeline.py --host 127.0.0.1 --port 8000 \
--watch ./logs/job.log \
--watch-label "job log" \
--watch-tail