Skip to main content

Trail

Trail

pip install trail-lang · import trail · CLI trail

The reference implementation of Trail - a small, total, declarative language for computing financial indicators, scores, and screening strategies over panels of securities. Trail expressions compile to vectorized Polars operations.

The language specification (grammar, reference, standard library) lives in trail-language/spec.

model quality on us_main at annual {
    operating_margin = income.operating_income / income.revenue
    score om_score weight 7 {
        2 if operating_margin > 0.12
        1 if operating_margin > 0.05
        else 0
    }
    export composite = weighted_score()
}

Install

pip install trail-lang        # or: uv add trail-lang

CLI

trail validate models/quality.trail                 # parse, kind-check, dry-run
trail run models/quality.trail --model quality      # evaluate a model
trail run models/quality.trail --model quality --config trail.yaml
trail catalog                                       # discover fields, functions, sources
trail catalog income                                # fields in a namespace
trail catalog cagr                                  # describe a function

The standard library is loaded implicitly; pass --no-stdlib to opt out.

Library

from trail.pipeline import prepare
from trail.compiler import compile_model
from trail.fixtures import load_panel  # a bundled demo panel

program = prepare("model m { export margin = income.operating_income / income.revenue }")
model = next(d for d in program.decls if type(d).__name__ == "ModelDecl")
result = compile_model(model, {}).run(load_panel())

Architecture

Parser (Lark LALR) → typed AST → macro expansion (def inlining) → kind-checked validation → Polars compiler. The engine carries only irreducible primitives; the large derived function library is written in Trail itself and shipped as trail/stdlib/*.trail (canonical copy in the spec).

Development

uv sync
uv run pytest -q
uv run ruff check .

License

MIT.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

trail_lang-0.12.0.tar.gz (118.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trail_lang-0.12.0-py3-none-any.whl (62.4 kB view details)

Uploaded Python 3

File details

Details for the file trail_lang-0.12.0.tar.gz.

File metadata

  • Download URL: trail_lang-0.12.0.tar.gz
  • Upload date:
  • Size: 118.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trail_lang-0.12.0.tar.gz
Algorithm Hash digest
SHA256 219f14783d6880723d98fcb208f2378d9c05811f46ab331be7b76e94ddaf4a37
MD5 dfa7e203c569fd0298a2b3a49e08b094
BLAKE2b-256 3876129435e3355d8b3a58b40002420c807cdcc6a7892e78d3774098f5a10d3f

See more details on using hashes here.

Provenance

The following attestation bundles were made for trail_lang-0.12.0.tar.gz:

Publisher: release.yml on trail-language/trail-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file trail_lang-0.12.0-py3-none-any.whl.

File metadata

  • Download URL: trail_lang-0.12.0-py3-none-any.whl
  • Upload date:
  • Size: 62.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trail_lang-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0c1d6ab3b10ba292a81a768534b1d56dfe512f4575b1aca220e9b3f240625ef0
MD5 ce53699063c7ae862f58f50598b9bffe
BLAKE2b-256 e22b38f1c044b7a87007f32668b2e8928d10e7cbcdcbe3ff041a45e496ad45e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for trail_lang-0.12.0-py3-none-any.whl:

Publisher: release.yml on trail-language/trail-lang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.18.0

2 files

0.14.0

2 files

0.13.0

2 files

This release

0.12.0 This release

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page