As of v0.8.0, Forti4D exposes a fully in-process Python library API for embedding Fortran static analysis directly into Python programs, notebooks, and CI scripts. Rather than shelling out to theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/acdeveloper-sci/forti4d/llms.txt
Use this file to discover all available pages before exploring further.
forti4d command, you call forti4d.run_pipeline() from your own code. All 19 analyzers run inside the same process — no subprocesses, no temp files for inter-step communication — and results are returned in memory through a PipelineResult object. The CLI itself uses this exact API internally.
Public Exports
The package exposes the following names via__all__:
| Name | Kind | Description |
|---|---|---|
run_pipeline | function | Run the full analysis pipeline in-process and return a PipelineResult. |
RunContext | dataclass | Mutable state threaded through a pipeline run. |
PipelineResult | dataclass | Return value of run_pipeline() — step outcomes and in-memory data. |
configure_logging | function | Opt in to console and/or file logging (silent by default in library mode). |
__version__ | string | Current package version, e.g. "0.8.0". |
run_pipeline()
run_pipeline() is the primary entry point. It accepts the source and results directories plus optional keyword arguments for step filtering, error handling, parallelism, and progress callbacks.
Parameters
Path to the directory containing the Fortran source files to analyze. Passed directly to each analyzer as
source_dir. Converted to a pathlib.Path internally.Root directory where all output files are written. Created automatically (
parents=True, exist_ok=True) before the first step runs. Converted to a pathlib.Path internally.Step name at which execution begins. All steps that appear before
from_step in the pipeline are skipped. Must be a valid step name (see the pipeline step table); raises ValueError if the name is not found.If provided, only the steps listed here are executed. Steps run in their canonical pipeline order regardless of the order listed. All other steps are skipped.
Step names to exclude from the run. Every other step executes normally. Can be combined with
from_step — from_step is applied first, then skip.When
False (default), the pipeline stops immediately after the first step that raises an exception or calls sys.exit. When True, execution continues to the next step and the failure is recorded in PipelineResult.steps.Number of parallel worker processes for the steps that support per-file parallelism (
inventory, profiler, and blocks). Resolution order: explicit argument → FORT_WORKERS environment variable → 1 (sequential). Values below 1 are clamped to 1.Optional callback invoked immediately before each step starts. Signature:
on_step_start(name: str, description: str). Useful for displaying progress in custom UIs or notebooks.Optional callback invoked immediately after each step completes, whether or not it succeeded. Signature:
on_step_end(name: str, success: bool, elapsed: float, error: str). The error string is empty on success and contains a short ExceptionType: message representation on failure.Return value
run_pipeline() returns a PipelineResult instance.
PipelineResult
PipelineResult is a dataclass holding the outcome of a completed (or partially completed) run.
A list of
(name, success, elapsed, error) tuples — one per step that was attempted. name is the step name string, success is a bool, elapsed is wall-clock time in seconds as a float, and error is an empty string on success or a short exception representation on failure.In-memory results accumulated across all steps. Each step that returns a non-empty dict merges its output into this shared dictionary. Keys are output names — for example,
"report_prioritization" holds the prioritization step’s result. Access individual step outputs with result.data["<output_name>"].Inspecting results
RunContext
RunContext is the mutable state dataclass threaded through every step during a pipeline run. It is created internally by run_pipeline() but is part of the public API so that advanced callers and custom step runners can type-annotate against it.
Absolute path to the Fortran source directory, resolved from the
source_dir argument passed to run_pipeline().Absolute path to the output directory where all files are written.
Shared in-memory result store. Each step reads prior steps’ outputs from this dict and writes its own outputs back into it. At the end of the run this dict is exposed as
PipelineResult.data.Resolved number of parallel workers, after applying the priority chain (explicit argument →
FORT_WORKERS → 1).Logging
By default, Forti4D is completely silent when used as a library. Theloguru logger is disabled for the forti4d namespace at import time, so no output appears on the console and no log file is created unless you explicitly opt in.
To enable logging, call configure_logging() before run_pipeline():
configure_logging signature: configure_logging(results_dir, *, console_level="INFO", quiet=False, log_file=True, log_path=None). It returns the resolved log file Path, or None when log_file=False.
results_dir— directory used to derive the default log file path (<results_dir>/forti4d.log).console_level— loguru level string for the console sink whenquiet=False. Defaults to"INFO".quiet— whenTrue, overridesconsole_levelto"WARNING". The file sink always capturesDEBUG-level output regardless of this flag.log_file— set toFalseto skip the file sink entirely (console output only). Equivalent to the--no-log-fileCLI flag.log_path— absolute or relative path to override the default log file location. Ignored whenlog_file=False.
quiet=True raises the console threshold to WARNING while the log file still captures full DEBUG-level output — the same behavior as the --quiet CLI flag.
Progress Callbacks
Theon_step_start and on_step_end callbacks give you fine-grained visibility into pipeline progress without relying on log output. This is particularly useful in notebook environments or when building custom progress displays:
Accessing In-Memory Results
Every step that produces structured output stores it inRunContext.data (and by extension PipelineResult.data) under a string key matching the output name. You can read any step’s results directly from memory after the run completes, without parsing the CSV files on disk:
Analyzer output files (CSV, DOT, HTML, etc.) are always written to disk regardless of whether you are using the library API or the CLI. The
data dict provides the same structured data in memory as a convenience — it does not replace the on-disk files.