Skip to content

Fleet

Fleet is a lazy expression accumulator with an immutable builder API that specializes in creating CDISC SDTM/ADaM datasets using the well-known Polars library.

  • Polars-fast


    Lazy, multi-threaded pipelines: hundreds of derivations collapse into one optimized query plan. Zero Pandas.

    Namespace pipeline

  • Reads like the spec


    One verb per intent — assign, date, baseline, flag — so the code is the specification a reviewer reads.

    Verb cheat sheet

  • Dual workflow


    Chain verbs inline or drive the same pipeline from define.yaml. to_spec_yaml() writes a draft: verbs listed in fleet.spec_coverage() round-trip, other verbs emit a TODO stub to complete.

    How define.yaml works

  • Define-XML and CORE


    Define-XML 2.1 generation, CDISC CORE validation, trial-design conformance audits with P21 rule IDs.

    Validation strategy

  • AI-native by consequence


    A sharp workflow is what makes assistants reliable. MCP server, define.yaml language server and llms.txt expose it — so they write and verify.

    IDE & AI tooling

  • Six core dependencies


    polars, pydantic, pyyaml, httpx, jsonschema, lxml. Everything else is an opt-in extra.

    Installation

Build Status Coverage GitHub Docs PyPI Python 3.12 to 3.14 License: MIT


What is Fleet?

Fleet adds chainable verb pipelines directly onto every Polars DataFrame so you can build standards-compliant CDISC datasets with minimal boilerplate:

import fleet
import polars as pl
from fleet.ct import import_codelists

import_codelists()  # metadata/sdtm/codelists.py, made by: fleet init ct
from codelists import SEX

# SDTM DM domain from raw data — `assign` is the one assignment verb.
# Raw collected values ("Male"/"Female") remap to CT submission values.
dm = (
    raw_df.sdtm.assign("DOMAIN", value="DM")
    .assign("STUDYID", value="MYSTUDY01")
    .assign("USUBJID", source="patient_id")
    .assign("SEX", source="sex_raw", ct=SEX, ct_map={"Male": "M", "Female": "F"})
    .to_frame()
)

# ADaM BDS dataset (ADVS) from SDTM — one unbroken chain
advs = (
    vs_sdtm.adam.source("USUBJID", "PARAMCD", "AVAL")
    .study_day("ADY", date_col="ADT", ref_col="TRTSDT")
    .flag("ABLFL", criteria='pl.col("VISITNUM") == 1', by=["USUBJID", "PARAMCD"])
    .baseline("BASE", aval="AVAL", baseline_flag="ABLFL", by=["USUBJID", "PARAMCD"])
    .chg("CHG", aval="AVAL", base="BASE")
    .to_frame()
)

Most verbs accumulate into a single Polars with_columns pass; window verbs (baseline, cross-domain joins) checkpoint internally without breaking the chain.


Namespace Extensions

Importing fleet registers chainable namespaces on every Polars DataFrame (and LazyFrame):

Namespace Target dataset Description
df.sdtm SDTM domains domain mapping, CT via assign(ct=), datetime normalisation, TDD (call .verbs())
df.adam ADaM BDS study day, baseline, change, flags, BSA, MAP, QTc, LOCF, summary records (call .verbs())

ADaM sub-structures and therapeutic-area extensions are nested under df.adam:

Property Target dataset Description
df.adam.adsl ADSL patient-level verbs: treatment dates, duration, population flags, age conversion, periods
df.adam.occds OCCDS (ADAE, ADCM…) occurrence verbs: treatment-emergent flag, ASEQ, onset/recovery
df.adam.onco Oncology RECIST response, BOR, filter_pd
df.adam.ophtha Ophthalmology ETDRS/LogMAR, study eye
df.adam.peds Pediatrics Age derivations, prematurity
df.adam.vaccine Vaccine Fever, seroconversion, ADIS AVAL
df.adam.metabolic Metabolic Waist ratios, body fat %
df.adam.neuro Neuroscience Centiloid, MMSE, CDR-SoB
df.adam.tte ADTTE Event/censor frames, TTE params, AVAL/AVALU, KM inputs

These are inspired by the admiral TA packages. They are not ports: a verb can give other values. Each verb docstring names its source under References:.


Architecture at a Glance

flowchart TD
    CFG["study_config.yaml"] --> SPEC["define.yaml<br/>(metadata spec)"]
    RAW["Raw data<br/>CSV · XPT · Parquet"] --> SDTM

    subgraph FLEET["Fleet pipelines"]
        direction TB
        SDTM["df.sdtm<br/>SDTM domains"]
        ADAM["df.adam · df.adam.adsl<br/>ADaM datasets"]
        TLG["df.tlg<br/>Tables · Listings · Graphs"]
        SDTM --> ADAM
        ADAM --> TLG
    end

    SPEC --> FLEET
    FLEET --> VAL["CORE validation<br/>fleet validate"]
    SPEC --> XML["Define-XML 2.1<br/>fleet define-xml"]
    TLG --> OUT["HTML · RTF · PDF · PPTX"]