bioamla.workspace¶
bioamla.workspace ¶
bioamla.workspace — project workspaces.
A workspace is a project directory with a .bioamla/ folder holding its
metadata, settings, linked and imported artifacts (recordings, datasets, models),
annotations, run outputs and run history. Commands find the workspace by walking
up from the current directory, like git. See
Workspaces, remote work and agent skills
for how workspaces fit with remote servers and agent skills.
Example
from bioamla.workspace import create_workspace, find_workspace ws = create_workspace("my-survey") ws.link("/data/recordings/site-a") find_workspace("my-survey/notes").name 'my-survey'
Artifact
dataclass
¶
One thing a workspace points at.
Attributes:
| Name | Type | Description |
|---|---|---|
kind |
str
|
|
path |
str
|
Where it is: relative to the workspace root (linked, inside the
workspace), absolute (linked, outside it), or relative to
|
mode |
str
|
|
id |
str
|
Stable identifier, unique within the workspace. |
name |
str
|
Optional display name. |
Workspace ¶
An open workspace: its root directory and the contents of .bioamla/.
Use :func:create_workspace, :func:open_workspace or :func:find_workspace
rather than constructing one directly.
Attributes:
| Name | Type | Description |
|---|---|---|
root |
The workspace's project directory (the parent of |
|
id |
Stable identifier. |
|
name |
Display name. |
|
created |
ISO 8601 creation time (UTC). |
|
format_version |
The on-disk format version. |
history_path
property
¶
history_path: Path
history.jsonl; created by the first run recorded in the workspace.
artifacts ¶
artifacts(kind: str | None = None) -> list[Artifact]
The workspace's artifacts, optionally only those of one kind.
get_artifact ¶
get_artifact(artifact_id: str) -> Artifact
relative ¶
relative(path: str | Path) -> str
path relative to the workspace root (/-separated) if it's inside the
workspace, also when one of them is reached through a symlink (e.g. /var vs
/private/var on macOS); otherwise absolute, keeping symlinks as given.
link ¶
link(
path: str | Path,
kind: str | None = None,
name: str = "",
) -> Artifact
Point the workspace at path without copying it.
Linking a path that is already linked returns the existing artifact.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If |
InvalidInputError
|
If |
link_many ¶
link_many(
paths: Iterable[str | Path],
kind: str | None = None,
name: str = "",
) -> list[Artifact]
:meth:link for several paths at once: all are checked first, then
recorded in one write, so either every path is linked or none is.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If any path does not exist (nothing is linked). |
InvalidInputError
|
If |
import_copy ¶
import_copy(
path: str | Path,
kind: str | None = None,
name: str = "",
) -> Artifact
Copy path (a file or folder) into .bioamla/imported/ and record it.
A name already taken in imported/ gets a short id prefix rather than
overwriting.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If |
InvalidInputError
|
If |
import_many ¶
import_many(
paths: Iterable[str | Path],
kind: str | None = None,
name: str = "",
) -> list[Artifact]
:meth:import_copy for several paths: all are checked first, then copied
and recorded in one write. If anything fails, the copies made are removed and
nothing is recorded.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If any path does not exist. |
InvalidInputError
|
If |
remove ¶
remove(
artifact_id: str, delete_import: bool = False
) -> Artifact
Forget an artifact. Linked files are never touched; an imported copy is
deleted only with delete_import=True.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If there is no such artifact. |
WorkspaceError
|
If an imported artifact's path points outside |
resolve ¶
resolve(artifact: Artifact) -> Path
The artifact's absolute path on this machine.
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If an imported artifact's path is empty, absolute, or
leaves |
record_run ¶
record_run(record: dict[str, Any]) -> None
Append one run record to history.jsonl (one JSON object per line).
Appends happen under the workspace lock, so concurrent runs never interleave.
run_record ¶
run_record(
*,
command: str,
started: float,
ended: float,
ok: bool,
exit_code: int,
error: dict[str, Any] | None,
result: Any = None,
user: str | None = None,
argv: list[str] | None = None,
cwd: str | None = None,
**extra: Any,
) -> dict[str, Any]
A run record for :meth:record_run, in the current format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
The command ( |
required |
started
|
float
|
When it started, and |
required |
ok
|
bool
|
Whether it succeeded, with its |
required |
result
|
Any
|
Its result as JSON-ready data; the files it names become
|
None
|
user
|
str | None
|
Who ran it. |
None
|
argv
|
list[str] | None
|
Its command line ( |
None
|
cwd
|
str | None
|
Where it ran, relative to the workspace. |
None
|
extra
|
Any
|
More fields (e.g. a server run's |
{}
|
history ¶
history(
limit: int | None = None, failed_only: bool = False
) -> list[dict]
Run records, oldest first; the last limit of them if given.
Lines that aren't valid JSON objects (a crash mid-write, a hand edit) are skipped rather than failing.
output_paths ¶
output_paths(result: Any) -> list[str]
The files a run's result says it wrote (its output, output_dir,
metadata_file, results_file, output_path and output_files),
relative to the workspace where they're inside it.
artifact_row ¶
artifact_row(artifact: Artifact) -> dict[str, Any]
artifact as a dict, with where it resolves to and whether it's there
(resolved, exists).
artifact_rows ¶
artifact_rows(
kind: str | None = None,
) -> list[dict[str, Any]]
Every artifact as :meth:artifact_row; only those of kind if given.
status ¶
status(last_runs: int = 5) -> dict[str, Any]
:meth:to_dict plus the last last_runs run records (last_runs).
settings ¶
settings() -> dict[str, Any]
This workspace's own settings (config.toml) as dotted keys, e.g.
{"detect.energy.threshold_db": -25}.
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the file can't be read. |
set_setting ¶
set_setting(key: str, value: Any) -> None
Set the dotted key to value in this workspace's config.toml.
The value is stored as given (no conversion to an option's type; the CLI's
workspace config set does that). Another spelling of the same key (-
for _) is replaced. Comments in the file are not kept.
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the file can't be read, or |
unset_setting ¶
unset_setting(key: str) -> bool
Remove the dotted key (in any spelling: - or _) from this
workspace's config.toml.
Returns:
| Type | Description |
|---|---|
bool
|
Whether it was set. |
list_files ¶
list_files(
path: str | Path = ".",
recursive: bool = False,
limit: int | None = None,
sha256: bool = False,
) -> list[dict[str, Any]]
The files and folders in path (relative to the workspace, or absolute),
sorted by folder. Workspace metadata folders (.bioamla) and unfinished
uploads (*.part files) are left out; links to folders are listed but not followed,
and folders that can't be read are skipped. A file's path lists just it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
The folder (or a file). |
'.'
|
recursive
|
bool
|
Include subfolders. |
False
|
limit
|
int | None
|
Stop after this many entries. |
None
|
sha256
|
bool
|
Add each file's SHA-256 ( |
False
|
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
One |
list[dict[str, Any]]
|
files, when asked): |
list[dict[str, Any]]
|
it, |
list[dict[str, Any]]
|
|
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If |
create_workspace ¶
create_workspace(
root: str | Path, name: str | None = None
) -> Workspace
Make root a workspace (creating the directory if needed).
Raises:
| Type | Description |
|---|---|
WorkspaceError
|
If |
current_workspace ¶
current_workspace(
start: str | Path | None = None,
) -> Workspace
The workspace containing start (default: the current directory).
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If there is none. |
find_workspace ¶
find_workspace(
start: str | Path | None = None,
) -> Workspace | None
The workspace containing start (default: the current directory), found by
walking up the directory tree; None if there is none.
is_workspace ¶
is_workspace(path: str | Path) -> bool
True if path is a directory with a .bioamla/workspace.toml.
open_workspace ¶
open_workspace(root: str | Path) -> Workspace
Open the workspace at root.
Raises:
| Type | Description |
|---|---|
NotFoundError
|
If |
WorkspaceError
|
If its metadata is unreadable, or it was written by a newer bioamla (a higher format version). |