Skip to content

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

algorithms(standard)

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

"sdtm" or "adam".

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
def algorithms(standard: Standard) -> tuple[AlgorithmInfo, ...]:
    """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.

    Args:
        standard: ``"sdtm"`` or ``"adam"``.

    Returns:
        tuple[AlgorithmInfo, ...]: One entry per verb.

    Raises:
        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")]
    """
    _check_standard(standard)

    from fleet.core import spec_registry

    return tuple(_to_info(algo) for algo in spec_registry.algorithms(standard))

options: show_root_heading: true heading_level: 3

get_algorithm

fleet.introspect.get_algorithm

get_algorithm(standard, name)

Return the algorithm registered under name, or None.

Parameters:

Name Type Description Default
standard Standard

"sdtm" or "adam".

required
name str

Algorithm name or accepted alias.

required

Returns:

Type Description
AlgorithmInfo | None

AlgorithmInfo | None: The algorithm, or None when name is not registered for standard.

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
def get_algorithm(standard: Standard, name: str) -> AlgorithmInfo | None:
    """Return the algorithm registered under *name*, or ``None``.

    Args:
        standard: ``"sdtm"`` or ``"adam"``.
        name: Algorithm name or accepted alias.

    Returns:
        AlgorithmInfo | None: The algorithm, or ``None`` when *name* is
            not registered for *standard*.

    Raises:
        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 []
    """
    _check_standard(standard)

    from fleet.core import spec_registry

    algo = spec_registry.get_algorithm(standard, name)
    return None if algo is None else _to_info(algo)

options: show_root_heading: true heading_level: 3

suggest_algorithm

fleet.introspect.suggest_algorithm

suggest_algorithm(standard, name)

Return the registered algorithm closest to name, if any.

Parameters:

Name Type Description Default
standard Standard

"sdtm" or "adam".

required
name str

The unrecognised spelling to match against.

required

Returns:

Type Description
str | None

str | None: The closest algorithm name, or None when nothing is close enough to suggest.

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
def suggest_algorithm(standard: Standard, name: str) -> str | None:
    """Return the registered algorithm closest to *name*, if any.

    Args:
        standard: ``"sdtm"`` or ``"adam"``.
        name: The unrecognised spelling to match against.

    Returns:
        str | None: The closest algorithm name, or ``None`` when nothing
            is close enough to suggest.

    Raises:
        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}'?"
    """
    _check_standard(standard)

    from fleet.core import spec_registry

    return spec_registry.suggest_algorithm(standard, name)

options: show_root_heading: true heading_level: 3

algorithm_doc

fleet.introspect.algorithm_doc

algorithm_doc(name)

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 None when the algorithm has no resolvable verb.

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
def algorithm_doc(name: str) -> AlgorithmDoc | None:
    """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.

    Args:
        name: Canonical algorithm name.

    Returns:
        AlgorithmDoc | None: Summary and dotted verb path, or ``None``
            when the algorithm has no resolvable verb.

    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 ""
    """
    from fleet.core.algorithm_resolver import resolve_algorithm_docstring

    summary, verb_path = resolve_algorithm_docstring(name)
    if summary is None or verb_path is None:
        return None
    return AlgorithmDoc(summary=summary, verb_path=verb_path)

options: show_root_heading: true heading_level: 3

define_schema

fleet.introspect.define_schema cached

define_schema()

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
@lru_cache(maxsize=1)
def define_schema() -> dict[str, Any]:
    """Return the generated JSON schema for ``define.yaml`` specs.

    Returns:
        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": {}}))
    """
    import json

    from fleet.define_xml.schema_builder import SCHEMA_PATH

    return json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))

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 algorithm: value).

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
@dataclass(frozen=True, slots=True)
class AlgorithmInfo:
    """A spec-executable algorithm as tooling sees it.

    Args:
        name: Canonical algorithm name (the ``algorithm:`` value).
        standard: The standard the algorithm belongs to.
        description: One-line description, possibly empty.
        params: Declared parameters, in spec order.
    """

    name: str
    standard: Standard
    description: str
    params: tuple[ParamInfo, ...]

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 derivation block).

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
@dataclass(frozen=True, slots=True)
class ParamInfo:
    """One parameter of a spec algorithm.

    Args:
        name: Spec field name (the YAML key inside the ``derivation`` block).
        required: Whether the field must be present in the spec.
        description: Short human-readable description, possibly empty.
    """

    name: str
    required: bool
    description: str

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 module.Class.method path of that verb.

required
Source code in src/fleet/introspect.py
@dataclass(frozen=True, slots=True)
class AlgorithmDoc:
    """The docstring of the verb an algorithm dispatches to.

    Args:
        summary: First sentence of the verb's docstring.
        verb_path: Dotted ``module.Class.method`` path of that verb.
    """

    summary: str
    verb_path: str

options: show_root_heading: true heading_level: 3 filters: ["!^_"]