A declarative expression language for financial indicators, scoring, and screening over security panels
Project description
trail-py
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 period 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file trail_lang-0.1.0.tar.gz.
File metadata
- Download URL: trail_lang-0.1.0.tar.gz
- Upload date:
- Size: 74.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f003ff6ab23b7ca9b55eaf9b51b0df691a12bdb876c269309a070d4ff48dcd09
|
|
| MD5 |
fca137e963143f86d427fdb06b5f9b1a
|
|
| BLAKE2b-256 |
057f7ae02461a2ab778172adc0f0a2c4ad689453f4ccaec97fbe7b8fc4c3abcf
|
Provenance
The following attestation bundles were made for trail_lang-0.1.0.tar.gz:
Publisher:
release.yml on trail-language/trail-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trail_lang-0.1.0.tar.gz -
Subject digest:
f003ff6ab23b7ca9b55eaf9b51b0df691a12bdb876c269309a070d4ff48dcd09 - Sigstore transparency entry: 2168486467
- Sigstore integration time:
-
Permalink:
trail-language/trail-py@be1a47ea2a85acd3d1e553a4fc9b4443afb0474a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trail-language
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@be1a47ea2a85acd3d1e553a4fc9b4443afb0474a -
Trigger Event:
push
-
Statement type:
File details
Details for the file trail_lang-0.1.0-py3-none-any.whl.
File metadata
- Download URL: trail_lang-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90c5c07f9118ce3f5b5541b709f15b7a00998e3a8e798b2370e83a6ed3557d96
|
|
| MD5 |
3c596e71c7141042516c5ae9689804c4
|
|
| BLAKE2b-256 |
8b21c138b88af047c84ba51779b0b14a668cea7fbe2d55bb414d0743b8ddbb22
|
Provenance
The following attestation bundles were made for trail_lang-0.1.0-py3-none-any.whl:
Publisher:
release.yml on trail-language/trail-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
trail_lang-0.1.0-py3-none-any.whl -
Subject digest:
90c5c07f9118ce3f5b5541b709f15b7a00998e3a8e798b2370e83a6ed3557d96 - Sigstore transparency entry: 2168486649
- Sigstore integration time:
-
Permalink:
trail-language/trail-py@be1a47ea2a85acd3d1e553a4fc9b4443afb0474a -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/trail-language
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@be1a47ea2a85acd3d1e553a4fc9b4443afb0474a -
Trigger Event:
push
-
Statement type: