Examples#
Runnable scripts for common tasks, in examples/. Each one
runs without an account, and CI runs each one end to end.
Example |
Task |
Needs |
|---|---|---|
Write a record to any destination, read it back, update it, and handle a conflict |
Base install |
|
Log in to LabArchives, list notebooks, open one, and load a record |
|
|
Connect to eLabFTW with an API key, list entries, open one, and load a record |
|
|
Connect to GitHub with a token, list folders, open one, and load a record |
|
|
Read a token from a |
|
Run them from the repository root as modules, after uv sync (add
--extra labarchives for LabArchives, --extra elabftw for eLabFTW,
--extra github for GitHub). save_metadata writes to every destination;
its README shows the URI and settings for
LabArchives,
eLabFTW, and
GitHub:
mkdir -p metadata
uv run python -m examples.save_metadata "file://$PWD/metadata"
How they stay correct#
Each example splits reusable functions, which take a session and return data, from
main(), which handles arguments, login, output, and exit codes. This is the same layout aslabapi’s examples.tests/examples/runs every example against a temporary folder and in-process fake LabArchives and GitHub servers, both by callingmain()and aspython -m examples.<name>. The eLabFTW tests run against the dev stack’s eLabFTW whenMETARELAY_ELABFTW_TEST_API_URLis set, as in CI’selabftwjob.The code in the quickstart, concepts, LabArchives, eLabFTW, and GitHub pages is copied from marked regions of the examples.
tests/examples/test_docs_snippets.pyfails if a page and its example drift apart. After changing an example, update the pages withuv run python tests/examples/test_docs_snippets.py.
Writing a backend isn’t an example here. The “write a backend” guide (#13)
covers it. Until then, read src/metarelay/testing/memory.py (the smallest
backend), then backends/local.py and backends/labarchives.py, and see
architecture.