Skip to main content

onebudgetspec

Register measurable budgets in YAML and gate on them. Each budget names a command that performs the measurement, a unit, a direction and a threshold; onebudgetspec check runs every selected command once and reports the actual value, the budget and the headroom.

It ships as a Rust SDK (onebudgetspec-core) and a command line (onebudgetspec), with Python and TypeScript SDKs released beside them at the same version (see SDKs).

Principles

  • Measure once. Each selected budget's command runs exactly once per check. There is no retry, repeat or sampling.
  • Report actual, budget and headroom. Every result carries all three, so even a result within budget shows how close it came.
  • Record host conditions beside each result. The load average, CPU count, available memory and any conditions the file declares are recorded with every measurement, so a person can judge an extreme circumstance from the result itself.
  • Over budget is a defect, never re-sampled. An over-budget result fails the check on any host. It is never re-run until it passes.
  • No baselines. A budget is the threshold written in the file, not a comparison with an earlier run.

Install

pip install onebudgetspec-cli         # or: uvx --from onebudgetspec-cli onebudgetspec
npm install --save-dev @onebudgetspec/cli
cargo install onebudgetspec

Each installs a native binary for Linux, macOS and Windows, on x86_64 and aarch64.

The budgets file

A file named budgets.yaml:

schema_version: 1
conditions:            # optional; recorded beside every result measured from this file
  - name: dispatches   # ^[a-z][a-z0-9_]*$, unique, never load1, cpus or mem_available_mib
    command: ["bash", "scripts/count-dispatches.sh"]  # run once per file per check; trimmed stdout recorded
budgets:
  - id: gate-time      # ^[a-z][a-z0-9-]*$, unique across every file one discovery finds
    description: "Wall clock of the full gate"  # optional
    labels: [ci]       # optional free tags, for selecting a subset
    measure: reported  # elapsed | reported
    command: ["bash", "scripts/budget-gate-time.sh"]  # argv, no shell, run from this file's directory
    unit: seconds      # a free label; `elapsed` requires seconds
    direction: max     # max: within when actual <= threshold; min: within when actual >= threshold
    threshold: 1800    # finite and non-negative
    timeout_seconds: 3600  # optional; past it the measurement is an error

Unknown keys are refused at every level, naming the key and the file.

A command is an argv run with no shell, from the directory holding its file; a program named by a relative path with more than one component is found from that directory too. On Linux and macOS an executable script may be named directly, by its #! line. Windows reads no #! line, and a bare name there resolves only to <name>.exe, so a script measured on Windows names its interpreter in the command, as in ["bash", "scripts/budget-gate-time.sh"], ["node", "measure.js"] or ["python", "measure.py"]; that form runs on every platform. A timeout_seconds ends everything the command started: its process group on Linux and macOS, its Job Object on Windows. A failed command is described by its exit status, which on Windows is the exit code (in hexadecimal, such as 0xC0000005, when it is a crash's NTSTATUS); on Linux and macOS a command ended by a signal is described by that signal. load1 is unknown (null) on Windows, which has no load average, and mem_available_mib is unknown on macOS.

elapsed times the command's wall clock; a non-zero exit is an error. reported sets ONEBUDGETSPEC_RESULT to the path of a fresh, empty file, and the command writes one JSON object there and exits 0:

{"value": 1395.0, "detail": "optional text", "conditions": {"runner": "large"}}

detail and conditions are optional. Returned conditions are recorded in that result's host conditions only; a returned name equal to a declared condition, load1, cpus or mem_available_mib makes the measurement an error rather than replacing a sampled value. A command's own stdout and stderr go to stderr, never into a report, with one exception: when a budget's command exits non-zero, is ended by a signal or its timeout, or exits 0 with a result that cannot be read, its result's error states that (for an unreadable result, why it could not be read and then the exit status), followed by ; its stderr: and the tail of what the command wrote there. That tail is decoded lossily, each line trimmed, blank lines dropped, the rest joined by | and other control characters made spaces, and it is bounded to at most the last 1000 characters, after a leading … when anything was cut. A command that wrote nothing but whitespace there gets no such suffix; a command that succeeds is reported without its stderr. A failing condition command is still recorded as unknown, and the same reason appears on the line onebudgetspec prints to stderr for it.

The command line

onebudgetspec check [PATH]... [--id ID]... [--label LABEL]... [--exclude-label LABEL]... [--recursive]
onebudgetspec validate [PATH]... [--recursive]
onebudgetspec list [PATH]... [--id ID]... [--label LABEL]... [--exclude-label LABEL]... [--recursive]
onebudgetspec schema

With no PATH, ./budgets.yaml is read. --recursive searches a directory for files named budgets.yaml, honouring .gitignore. Every verb takes --output text|json (--json for short). schema prints the JSON Schema bundle for the budgets file and both reports.

A text result reads:

budget gate-time: actual 1395 seconds, budget 1800 seconds, headroom 405 seconds (22.5%) — within; host: load=2.1/8 mem_available=5120MiB dispatches=3
Exit Meaning
0 every selected budget is within
1 at least one is over, and none errored
2 the invocation or a file is invalid; nothing was run (the reason is on stderr)
3 at least one measurement errored (its reason is that result's error, in the report), or the report could not be written (that reason is on stderr)

The npm launcher adds three of its own, each with the reason on stderr: 64 on a platform no carrier is published for, 69 when the carrier package is missing or its binary cannot run, and 70 when the binary was ended by a signal.

SDKs

Three SDKs, released at the binary's version. The Rust SDK is the engine itself; the Python and TypeScript SDKs run the onebudgetspec binary once per call, parse the JSON it prints, and return the reports as types generated from onebudgetspec schema, so they never drift from it.

Rust Python TypeScript
Package onebudgetspec-core (crates.io) onebudgetspec-sdk (PyPI), imported as onebudgetspec_sdk @onebudgetspec/sdk (npm)
Install cargo add onebudgetspec-core pip install onebudgetspec-sdk, which installs onebudgetspec-cli at the same version npm install @onebudgetspec/sdk, which installs its optional dependency @onebudgetspec/cli at the same version
Calls load(paths, recursive), then .select(&Selection) and .check() or .list_report(), or .all().list_report() to validate; schema_bundle() check(paths=None, ids=None, labels=None, exclude_labels=None, recursive=False, cwd=None) -> CheckReport, validate(paths=None, recursive=False, cwd=None) -> ListReport, list_budgets(...) with check's arguments -> ListReport, schema() -> dict check({paths, ids, labels, excludeLabels, recursive, cwd}), validate({paths, recursive, cwd}), listBudgets({paths, ids, labels, excludeLabels, recursive, cwd}), schema(), each a promise of the generated type
Binary none: it measures in process the binary= argument, then ONEBUDGETSPEC_BIN, then the onebudgetspec the onebudgetspec-cli wheel installed (Scripts\onebudgetspec.exe on Windows), then onebudgetspec on PATH (onebudgetspec.exe on Windows) the binary option, then ONEBUDGETSPEC_BIN, then the launcher of the resolved @onebudgetspec/cli package
Tests and journeys it owes crates/onebudgetspec-core/tests/api.rs, crates/onebudgetspec-core/tests/schema.rs, and every CLI journey and conformance case, which drive it through the binary sdks/python/tests/test_conformance.py (every conformance case through check, list_budgets and validate), sdks/python/tests/test_binary.py (resolution order and refusals), sdks/python/tests/test_generate.py (the model generator), and the packaging journey crates/onebudgetspec-packaging-e2e/tests/packaging/sdk_python.rs sdks/typescript/tests/conformance.test.ts, sdks/typescript/tests/binary.test.ts, sdks/typescript/tests/errors.test.ts and sdks/typescript/tests/generator.test.ts (the same concerns), and the packaging journey crates/onebudgetspec-packaging-e2e/tests/packaging/sdk_typescript.rs

In Python and TypeScript, exit statuses 0, 1 and 3 return the report, since the verdicts are in it; status 2 (an invalid invocation or budgets file) raises OnebudgetspecError (Python) or rejects with it (TypeScript), carrying the CLI's own message and exit_code/exitCode 2.

from onebudgetspec_sdk import check

report = check(labels=["api"], exclude_labels=["slow"], cwd="services")
for result in report.results:
    print(result.id, result.verdict, result.actual, result.headroom, result.host.conditions)
import { check } from "@onebudgetspec/sdk";

const report = await check({ labels: ["api"], excludeLabels: ["slow"], cwd: "services" });
for (const result of report.results) {
  console.log(result.id, result.verdict, result.actual, result.headroom, result.host.conditions);
}

Nesting budgets files

Each project registers its own budgets beside its code, and only the budgets a change can affect run; the budgets that must always be checked go in the root file. With Nx as the worked example, a repository lays them out as:

budgets.yaml               # always checked
services/api/budgets.yaml  # checked when services/api is affected
services/api/project.json

The project's own file:

schema_version: 1
budgets:
  - id: api-cold-start
    description: "Seconds from process start to the first healthy response"
    measure: elapsed
    command: ["bash", "scripts/start-and-probe.sh"]
    unit: seconds
    direction: max
    threshold: 2
    timeout_seconds: 30
  - id: api-requests-per-second
    measure: reported
    command: ["bash", "scripts/load-test.sh"]
    unit: requests/s
    direction: min
    threshold: 500

checked by that project's budgets target in services/api/project.json:

{
  "targets": {
    "budgets": {
      "command": "onebudgetspec check services/api/budgets.yaml",
      "inputs": ["{projectRoot}/**/*"]
    }
  }
}

and run for the affected projects only:

nx affected -t budgets

The root file holds what every change must stay within:

schema_version: 1
conditions:
  - name: runner
    command: ["node", "-p", "process.arch"]
budgets:
  - id: gate-time
    description: "Wall clock of the full gate"
    measure: elapsed
    command: ["just", "check"]
    unit: seconds
    direction: max
    threshold: 1800
    timeout_seconds: 3600

checked on every change with onebudgetspec check budgets.yaml. To check every file at once, onebudgetspec check --recursive . discovers both.

Licence

MIT

Metadata

Release files for onebudgetspec-cli 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for onebudgetspec-cli 0.1.2
File
onebudgetspec_cli-0.1.2-py3-none-win_arm64.whl Python 3 none Windows ARM64 Details
onebudgetspec_cli-0.1.2-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details
onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_x86_64.whl Python 3 none Linux glibc 2.39+ x86-64 Details
onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_aarch64.whl Python 3 none Linux glibc 2.39+ ARM64 Details
onebudgetspec_cli-0.1.2-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details
onebudgetspec_cli-0.1.2-py3-none-macosx_10_12_x86_64.whl Python 3 none macOS 10.12+ x86-64 Details

Total release size: 8.7 MB

Release files / onebudgetspec_cli-0.1.2-py3-none-win_arm64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-win_arm64.whl
Size 1.4 MB
Tags Python 3 Windows ARM64
SHA-256 checksum
How to use checksums
d53cd499e3c727a46f5a9fa7641dc4893a5efe3a48bb92ac034336088bffcd23
BLAKE2b-256 checksum
How to use checksums
a6493c3d9f144e709d94d8b55d9bd54263fa654a2ff9315d668d95f96952c7a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / onebudgetspec_cli-0.1.2-py3-none-win_amd64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-win_amd64.whl
Size 1.5 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
58f020009f6a01854c52b4d1a447f4b5f742f2b9b5fda80e13ca90397286c341
BLAKE2b-256 checksum
How to use checksums
aa81241118b3a3b64e5686052de79b0a072b7eac8073bda375ac1ba24b359b3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_x86_64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_x86_64.whl
Size 1.6 MB
Tags Linux glibc 2.39+ x86-64 Python 3
SHA-256 checksum
How to use checksums
5b532d81f788a241b3d90e63529905f6c5c40201446e2b28284ef00ce2799c4f
BLAKE2b-256 checksum
How to use checksums
22a467fe9a0dfc8dff275b90811e99ce3e1424180c201c9ce22a97510a822297
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_aarch64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-manylinux_2_39_aarch64.whl
Size 1.5 MB
Tags Linux glibc 2.39+ ARM64 Python 3
SHA-256 checksum
How to use checksums
88664ef5ba110fd2b7fead00e048b0fced108a8073970c5dd7ab1cff350f83ee
BLAKE2b-256 checksum
How to use checksums
fc9be4dfd557a538c161df6bccfcf25ed0b199f9b5be6e1dd458af27d2420f03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / onebudgetspec_cli-0.1.2-py3-none-macosx_11_0_arm64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-macosx_11_0_arm64.whl
Size 1.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3c382b95fbdd49a6f5361c25224ba66fe03a4f86eaaad445add8f2053affd151
BLAKE2b-256 checksum
How to use checksums
9c082b82e82ce8a5dfd5a3fd25d709004df87d26f5a46a085a1ffe9c824e30f3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / onebudgetspec_cli-0.1.2-py3-none-macosx_10_12_x86_64.whl

Download URL onebudgetspec_cli-0.1.2-py3-none-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags Python 3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
58a685ba343fc492056a708816b71e300754a95f4316f6f51e8577e554495a50
BLAKE2b-256 checksum
How to use checksums
681d8cc1211b50d18dfdbbf6b0e746ddb8b05c35c3440f98bf0cea37bf90c1cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.23 {"installer":{"name":"uv","version":"0.12.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.1.5

6 release files

0.1.4

6 release files

0.1.3

6 release files

This release

0.1.2 This release

6 release files

0.1.1

4 release files

0.1.0

4 release 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