Tooling Introspection¶
fleet.introspect is the surface for editor and tooling integrations — a language
server offering algorithm: completions, a hover card, a define.yaml linter. If you
are writing derivations rather than tooling, you want the
SDTM and ADaM namespaces instead.
The module is additive-only within a major version: names and return fields may be
added, but nothing is removed or renamed except on a major. A client therefore declares a
minimum Fleet version — read from serverInfo.version in the language-server
handshake — and never a maximum. See
ADR-0001
for the reasoning.
from fleet import introspect
items = [
{"label": algo.name, "documentation": algo.description}
for algo in introspect.algorithms("adam")
]
algorithms¶
fleet.introspect.algorithms
¶
Return every algorithm registered for standard.
Not cached: spec_algorithm() is public, so an algorithm registered
after the first call must still show up in completions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
standard
|
Standard
|
|
required |
Returns:
| Type | Description |
|---|---|
tuple[AlgorithmInfo, ...]
|
tuple[AlgorithmInfo, ...]: One entry per verb. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If standard is not a known CDISC standard. |
Examples:
Build the algorithm: completion list for a define.yaml::
from fleet import introspect
labels = [algo.name for algo in introspect.algorithms("sdtm")]
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3
get_algorithm¶
fleet.introspect.get_algorithm
¶
Return the algorithm registered under name, or None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
standard
|
Standard
|
|
required |
name
|
str
|
Algorithm name or accepted alias. |
required |
Returns:
| Type | Description |
|---|---|
AlgorithmInfo | None
|
AlgorithmInfo | None: The algorithm, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If standard is not a known CDISC standard. |
Examples:
Offer the parameter keys of the algorithm under the cursor::
from fleet import introspect
algo = introspect.get_algorithm("adam", "chg")
keys = [param.name for param in algo.params] if algo else []
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3
suggest_algorithm¶
fleet.introspect.suggest_algorithm
¶
Return the registered algorithm closest to name, if any.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
standard
|
Standard
|
|
required |
name
|
str
|
The unrecognised spelling to match against. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The closest algorithm name, or |
Raises:
| Type | Description |
|---|---|
ValueError
|
If standard is not a known CDISC standard. |
Examples:
Turn an unknown algorithm into a did-you-mean diagnostic::
from fleet import introspect
suggestion = introspect.suggest_algorithm("sdtm", "asign_ct")
message = f"Unknown algorithm. Did you mean '{suggestion}'?"
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3
algorithm_doc¶
fleet.introspect.algorithm_doc
¶
Return the docstring summary of the verb name dispatches to.
Kept separate from :class:AlgorithmInfo on purpose: resolving a
docstring imports and scans the verb-bearing namespace modules, which
is too expensive for the per-keystroke completion path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Canonical algorithm name. |
required |
Returns:
| Type | Description |
|---|---|
AlgorithmDoc | None
|
AlgorithmDoc | None: Summary and dotted verb path, or |
Examples:
Add the verb's own words to a hover card::
from fleet import introspect
doc = introspect.algorithm_doc("baseline")
markdown = f"{doc.summary}\n\nVerb: `{doc.verb_path}`" if doc else ""
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3
define_schema¶
fleet.introspect.define_schema
cached
¶
Return the generated JSON schema for define.yaml specs.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: The parsed schema, cached across calls. |
Examples:
Validate a spec document against the shipped schema::
import jsonschema
from fleet import introspect
validator = jsonschema.Draft202012Validator(introspect.define_schema())
problems = list(validator.iter_errors({"study": {}}))
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3
AlgorithmInfo¶
fleet.introspect.AlgorithmInfo
dataclass
¶
A spec-executable algorithm as tooling sees it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Canonical algorithm name (the |
required |
standard
|
Standard
|
The standard the algorithm belongs to. |
required |
description
|
str
|
One-line description, possibly empty. |
required |
params
|
tuple[ParamInfo, ...]
|
Declared parameters, in spec order. |
required |
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3 filters: ["!^_"]
ParamInfo¶
fleet.introspect.ParamInfo
dataclass
¶
One parameter of a spec algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Spec field name (the YAML key inside the |
required |
required
|
bool
|
Whether the field must be present in the spec. |
required |
description
|
str
|
Short human-readable description, possibly empty. |
required |
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3 filters: ["!^_"]
AlgorithmDoc¶
fleet.introspect.AlgorithmDoc
dataclass
¶
The docstring of the verb an algorithm dispatches to.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
summary
|
str
|
First sentence of the verb's docstring. |
required |
verb_path
|
str
|
Dotted |
required |
Source code in src/fleet/introspect.py
options: show_root_heading: true heading_level: 3 filters: ["!^_"]