inspect_flow.api
Python API
init
Initialize the inspect_flow API.
def init(
log_level: str = DEFAULT_LOG_LEVEL,
display: DisplayType = "full",
dotenv_base_dir: str | None = ".",
) -> Nonelog_levelstr-
The Inspect Flow log level to use.
displayDisplayType-
The display mode.
dotenv_base_dirstr | None-
Directory (or file path) to search for
.envfiles. If a file path is given, its parent directory is used.Noneto skip.envloading. Defaults to"."(current working directory).
run
Run an inspect_flow evaluation.
def run(
spec: FlowSpec,
base_dir: str | None = None,
*,
dry_run: bool = False,
resume: bool = False,
) -> NonespecFlowSpec-
The flow spec configuration.
base_dirstr | None-
The base directory for resolving relative paths. Defaults to the current working directory.
dry_runbool-
If
True, do not run eval, but show a count of tasks that would be run. resumebool-
If
True, reuse the log directory from the previous run.
load_spec
Load a spec from file.
def load_spec(
file: str,
*,
args: dict[str, Any] | None = None,
) -> FlowSpecfilestr-
The path to the spec file.
argsdict[str, Any] | None-
A dictionary of arguments to pass as kwargs to the function in the flow config.
config
Return the flow spec configuration.
def config(
spec: FlowSpec,
base_dir: str | None = None,
) -> strspecFlowSpec-
The flow spec configuration.
base_dirstr | None-
The base directory for resolving relative paths. Defaults to the current working directory.
list_logs
List log paths grouped by directory, directories ordered by most recent log file.
Within each directory, logs are sorted by filename timestamp descending. Logs without a timestamp prefix sort at the end.
def list_logs(
log_dir: str | None = None,
store: str | FlowStore = "auto",
since: str | datetime | None = None,
until: str | datetime | None = None,
) -> list[str]log_dirstr | None-
Directory to list logs from recursively. If provided, the store is not used.
storestr | FlowStore-
The store to read logs from. Can be a FlowStore instance, a path, or
"auto"for the default. Only used whenlog_dirisNone. sincestr | datetime | None-
Only include logs whose filename timestamp is at or after this date. Accepts a
datetimeor a date string (e.g."2 weeks ago","2024-01-15"). untilstr | datetime | None-
Only include logs whose filename timestamp is at or before this date. Accepts a
datetimeor a date string (e.g."yesterday","2024-06-01").
store_get
Get a FlowStore instance.
def store_get(store: str = "auto", create: bool = True) -> FlowStorestorestr-
The store location. Can be a path to the store directory or
"auto"for the default store location. createbool-
Whether to create the store if it does not exist.
delete_store
Delete a flow store.
def delete_store(store_path: str) -> Nonestore_pathstr-
Path to the store directory.
copy_all_logs
Copy all log files from src_dir to dest_dir, preserving directory structure.
def copy_all_logs(src_dir: str, dest_dir: str, dry_run: bool, recursive: bool) -> Nonesrc_dirstr-
Source directory containing log files.
dest_dirstr-
Destination directory to copy log files to.
dry_runbool-
If True, preview what would be copied without making changes.
recursivebool-
If True, search src_dir recursively for log files.
FlowStore
Interface for flow store implementations.
class FlowStore(ABC)Attributes
store_pathstr-
The path to the store directory.
versionstr-
The store version.
Methods
- import_log_path
-
Import a log file(s) or directory(ies) into the store.
@abstractmethod def import_log_path( self, log_path: str | Sequence[str], recursive: bool = False, dry_run: bool = False, verbose: bool = False, ) -> Nonelog_pathstr | Sequence[str]-
Path or paths to log files or directories containing log files.
recursivebool-
Whether to search directories recursively.
dry_runbool-
Preview what would be imported without making changes
verbosebool-
Print paths of files being added
- get_logs
-
Get all log file paths in the store.
@abstractmethod def get_logs(self, filter: LogFilter | None = None) -> set[str]filterLogFilter | None-
Optional filter to apply to log headers. Only logs passing the filter are included. It is an error to specify both a per-call filter and a store-level filter.
- remove_log_prefix
-
Remove logs matching the given prefixes.
@abstractmethod def remove_log_prefix( self, prefix: str | Sequence[str], missing: bool = False, recursive: bool = False, dry_run: bool = False, verbose: bool = True, filter: LogFilter | None = None, ) -> Noneprefixstr | Sequence[str]-
One or more prefixes to match against log paths.
missingbool-
Whether to remove log paths that are missing from the file system.
recursivebool-
Whether to remove log files recursively.
dry_runbool-
Preview what would be removed without making changes
verbosebool-
Print paths of files being removed
filterLogFilter | None-
Optional filter to narrow which matched logs are removed. Each candidate log’s header is read and only those passing the filter are removed.
DisplayType
Display mode for flow output.
DisplayType = Literal["full", "rich", "plain"]