Skip to main content

cordon-emit (Python)

The Python reference emitter for Cordon. Where the bash toolchain declares a surface in a DSL, a Python CLI already has an argparse parser — so you don't declare anything twice: this introspects that parser and projects it to the one Cordon v4 contract. --describe becomes a machine-readable view of the exact parser that produces --help, so the two can't drift.

Pure stdlib, zero dependencies, published to PyPI as cordon-emit on the same version as cordon. Add it as a dependency; never copy it, since a copy drifts from the schema it targets.

So easy — one line

Add the parser you already build, then one line. That's the whole integration:

import argparse
from cordon_emit import describe_main, set_effect

def build_parser():
    p = argparse.ArgumentParser(prog="hq", description="Operate the deploy.")
    sub = p.add_subparsers(dest="command")

    logs = sub.add_parser("logs", help="Show app container logs")
    logs.add_argument("-f", "--follow", action="store_true", help="Stream live output")
    set_effect(logs, "read", network=True)

    set_effect(sub.add_parser("restart", help="Restart the app"), "deploy", network=True)
    return p

def main():
    parser = build_parser()
    describe_main(parser, group="Integrations", order=130)  # ← handles --describe / --pretty, exits
    args = parser.parse_args()
    ...

Now hq --describe emits a valid contract and hq --help reads from the same parser. The only thing you add by hand is the one fact a parser can't tell you: each command's blast radius, via set_effect() on the effect ladder (read < local_write < vault_write < remote_write < deploy, plus network / interactive). Unannotated commands default to read, and the emitter warns on stderr for each one so a forgotten blast radius isn't a silent fail-open. Pass --effect-required (or effect_required=True) to make an undeclared command a hard error instead — the strict, multi-tenant posture.

So powerful — zero-touch on any parser

Don't even need to edit the tool. Point the module at any importable factory that returns an ArgumentParser (module:attribute) and pipe it straight into cordon's validator:

python -m cordon_emit myapp.cli:build_parser -g Integrations -o 130
python -m cordon_emit myapp.cli:build_parser -g X -o 1 \
  | npx --yes --package cordon-spec@2 cordon-validate -      # exit 0 = conformant

That's a contract — and a conformance check — for an existing Python CLI with no code change.

API

symbol does
describe_main(parser, *, group, order, **kw) drop-in --describe handler: emit + SystemExit(0) when requested, else return. Honors --effect-required in argv. The one-liner.
describe_parser(parser, *, group, order, effect=None, paras=None, examples=None) -> dict the pure projection — returns the full {ok, schema_version, …} document.
set_effect(parser, effect, *, network=False, interactive=False) annotate a (sub)parser's blast radius; returns it so it nests in add_parser(...).
undeclared_effects(parser, *, tool_effect_override=None) -> list[str] the surfaces whose blast radius defaulted instead of being declared (command names, or the tool itself for a leaf). Empty means every effect was an explicit choice.
emit(parser, *, pretty=False, effect_required=False, **kw) print(json.dumps(describe_parser(...))); compact by default, --pretty indents. Warns on any command whose effect defaulted; effect_required=True makes that a hard error.

describe_parser returns the canonical, byte-deterministic document (no timestamps, stable order) — a guard can diff it.

Install

uv add cordon-emit

Verify

python3 emitters/python/selftest.py            # structural + byte-parity with the bash leaf fixture
python3 emitters/python/selftest.py --emit | node ../../conformance/validate.ts -

The selftest also proves convergence: introspecting an encrypt-shaped parser yields a contract byte-identical to the bash-DSL-emitted fixtures/valid/leaf-tool.json — same schema, two emitters, one output.

Metadata

Release files for cordon-emit 2.1.0

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

Source distribution (sdist)

Source distribution for cordon-emit 2.1.0
File Size Uploaded Provenance Actions
cordon_emit-2.1.0.tar.gz 11.0 kB With provenance Details for cordon_emit-2.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cordon-emit 2.1.0
File Interpreter ABI Platform Actions
cordon_emit-2.1.0-py3-none-any.whl Python 3 none any Details for cordon_emit-2.1.0-py3-none-any.whl

Total release size: 20.5 kB

Release files / cordon_emit-2.1.0.tar.gz

Download URL cordon_emit-2.1.0.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
afc6db194750a25f106675057afce23585e159f0f598b8dfa38ec95a042e9abf
BLAKE2b-256 checksum
How to use checksums
9567366c54f95a6a3cd1e68ea3a17c55520bb0b6c8a02710b7fb27830b5fd63c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / cordon_emit-2.1.0-py3-none-any.whl

Download URL cordon_emit-2.1.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aec6145a33409205e3c44f7dc30f0404b46b29be5d76a64a321f9e7ec7ea2b91
BLAKE2b-256 checksum
How to use checksums
24f9a9a2f2bde28a227b8b617e1a302dc361ade0fd03f8a189754163608e76ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Security for cordon-emit 2.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cordon_emit-2.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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