Skip to main content
incur

MIT License

Features · Install · Usage · Walkthrough · License

incur for Python: build CLIs for agents and humans, with output that matches the TypeScript package byte for byte.

Features

  • Agent discovery: built-in Skills and MCP sync (skills add, mcp add) so agents find your CLI automatically
  • Call-to-actions: suggest next commands to agents and humans after a run
  • TOON output: token-efficient default format, with JSON, YAML, Markdown, and JSONL alternatives
  • --llms flag: token-efficient command manifest in Markdown or JSON schema
  • Well-formed I/O: schema classes for arguments, options, environment variables, and output
  • Typed contexts: Context[Args, Options, Env, Vars, Globals] types handlers and middleware under strict pyright
  • Global options: --format, --full-output, --help, --json, --update, --version on every CLI for free
  • Mount APIs: fetch handlers, OpenAPI documents, and remote MCP servers as commands
  • Serve over HTTP: every CLI is an ASGI app with an MCP endpoint
  • Middleware: composable before/after hooks with typed variables via @cli.use
  • Async-native: handlers and middleware may be async def, and streams async generators
  • Zero dependencies: standard library only

Install

pip install incur-cli

Usage

Single-command CLI

Register a root command with @cli.root() for CLIs that do one thing.

from typing import Annotated

import incur


@incur.schema
class Args:
    name: Annotated[str, incur.field("Name to greet")]


cli = incur.Cli("greet", description="A greeting CLI")


@cli.root()
def greet(c: incur.Context[Args]) -> dict[str, str]:
    return {"message": f"hello {c.args.name}"}


if __name__ == "__main__":
    cli.serve()
$ greet world
# → message: hello world

Multi-command CLI

Decorate a function per subcommand.

from typing import Annotated

import incur


@incur.schema
class InstallArgs:
    package: Annotated[str | None, incur.field("Package name")] = None


@incur.schema(rename_all="camelCase")
class InstallOptions:
    save_dev: Annotated[bool | None, incur.field("Save as dev dependency", alias="D")] = None


cli = incur.Cli("my-cli", description="My CLI")


@cli.command("status", description="Show repo status")
def status(c: incur.Context) -> dict[str, bool]:
    return {"clean": True}


@cli.command("install", description="Install a package")
def install(c: incur.Context[InstallArgs, InstallOptions]) -> dict[str, int]:
    return {"added": 1, "packages": 451}


if __name__ == "__main__":
    cli.serve()
$ my-cli status
# → clean: true

$ my-cli install express -D
# → added: 1
# → packages: 451

Sub-command CLI

Create a separate Cli and mount it with cli.group(...) to nest command groups.

from typing import Literal

import incur

cli = incur.Cli("my-cli", description="My CLI")
pr = incur.Cli("pr", description="Pull request commands")


@incur.schema
class ListOptions:
    state: Literal["open", "closed", "all"] = "open"


@pr.command("list", description="List pull requests")
def list_prs(c: incur.Context[None, ListOptions]) -> dict[str, object]:
    return {"prs": [], "state": c.options.state}


cli.group(pr)

if __name__ == "__main__":
    cli.serve()
$ my-cli pr list --state closed
# → prs: []
# → state: closed

Walkthrough

Agent discovery

Agents can only use your CLI if they know it exists. incur ships three built-in discovery mechanisms:

# Generate and install agent skill files (recommended – lighter on tokens)
$ my-cli skills add

# Register as an MCP server for your agents
$ my-cli mcp add

# Print a machine-readable manifest
$ my-cli --llms

--mcp serves the commands as MCP tools over stdio. Set package= when the CLI's npm package differs from its name, mcp=incur.McpOptions(...) to configure the server, and sync=False to drop the skills commands. See Agent discovery.

Call-to-actions

Return incur.ok(data, cta=...) to tell agents which commands to run next. incur.Error(code, message, cta=...) carries suggestions too.

import incur

cli = incur.Cli("my-cli")


@cli.command("list")
def list_items(c: incur.Context) -> incur.Outcome:
    items = [{"id": 1, "title": "Fix bug"}]
    return incur.ok({"items": items}, cta=incur.CtaBlock([incur.Cta("get 1", "View item")]))
$ my-cli list
# → items[1]{id,title}:
# →   1,Fix bug
# → cta:
# →   description: "Suggested command:"
# →   commands[1]{command,description}:
# →     my-cli get 1,View item

Streaming

Generators and async generators stream chunks: one line each in TOON, one record each with --format jsonl.

from collections.abc import AsyncIterator

import incur

cli = incur.Cli("my-cli")


@cli.command("logs", description="Tail logs")
async def logs(c: incur.Context) -> AsyncIterator[str]:
    for line in ("connecting...", "streaming logs", "done"):
        yield line
$ my-cli logs
# → connecting...
# → streaming logs
# → done

Middleware and variables

@cli.use registers onion-style middleware that awaits next_(). Declare vars as a schema class whose fields have defaults: each run gets a fresh, typed instance as c.var.

import incur


@incur.schema
class Vars:
    user: str = "anonymous"


cli = incur.Cli("my-cli", vars=Vars)


@cli.use
async def authenticate(c: incur.MiddlewareContext[Vars], next_: incur.Next) -> None:
    c.var.user = "alice"
    await next_()


@cli.command("whoami")
def whoami(c: incur.Context[None, None, None, Vars]) -> dict[str, str]:
    return {"user": c.var.user}
$ my-cli whoami
# → user: alice

Raise incur.Error to stop the chain. See Middleware.

Global options

Every CLI accepts --filter-output, --format, --full-output, --help, --json, --llms, --mcp, --schema, --token-count, --token-limit, --token-offset, --update, and --version. Declare your own with globals=, a schema class every handler reads as c.globals.

Config file

config=incur.Config(flag="config", files=["my-cli.json"]) loads option defaults from {"commands": {"<name>": {"options": {...}}}}; a loader reads other formats. Precedence is argv, then config, then schema defaults. See Config file.

Mount APIs

cli.gateway(name, fetch) forwards curl-style arguments to a fetch handler: any function from incur.Request to incur.Response, plain or async def. incur.from_request(url) forwards to a hosted API.

import incur


def app(request: incur.Request) -> incur.Response:
    if request.method == "POST":
        return incur.Response.json({"created": True, **request.json()}, status=201)
    return incur.Response.json({"users": [{"id": 1, "name": "Alice"}]})


cli = incur.Cli("my-cli")
cli.gateway("api", app)
$ my-cli api users
# → users[1]{id,name}:
# →   1,Alice

$ my-cli api users -X POST -d '{"name":"Bob"}'
# → created: true
# → name: Bob

With openapi= (a document or its URL), each operation becomes a typed command; openapi_config=incur.OpenapiConfig(mode="namespace") nests them by path. cli.mcp_source turns a remote MCP server's tools into commands:

import incur

cli = incur.Cli("my-cli")
cli.gateway("pets", incur.from_request("https://petstore.example/v1/"), openapi="openapi.json")
cli.mcp_source("docs", "https://mcp.tempo.xyz/mcp")

See Mount APIs as CLIs.

Serve over HTTP

await cli.fetch(request) runs the command a path names, and cli.asgi is the same as an ASGI 3 app (uvicorn app:cli.asgi):

GET  /users?limit=5            → my-cli users --limit 5
POST /users {"name": "Bob"}    → my-cli users --name Bob
POST /mcp                      → MCP over HTTP
GET  /openapi.json             → the commands as an OpenAPI document
GET  /.well-known/agent-skills/index.json → Agent Skills discovery

Responses use the --full-output --format json envelope, and streams are NDJSON. See Serve CLIs as APIs.

Update notices

In a terminal, CLIs installed from npm check for updates once a day in a detached process and suggest my-cli --update. update=incur.Update(check=..., install=...) supplies custom checks and installers, and update=False disables both. See Update notices.

Filtering and token pagination

--filter-output prunes output to key paths, and --token-count, --token-limit, and --token-offset page through large outputs.

import incur

cli = incur.Cli("my-cli")


@cli.command("users")
def users(c: incur.Context) -> dict[str, object]:
    return {"users": [{"name": "Alice", "role": "admin"}, {"name": "Bob", "role": "user"}]}
$ my-cli users --filter-output users[0,2].name
# → users[2]{name}:
# →   Alice
# →   Bob

$ my-cli users --token-count
# → 14

Differences from TypeScript

  • Integers in data keep their exact value in every format, where JavaScript rounds beyond 2^53.
  • JSON Schema string formats other than date-time (such as email or uuid) are not validated.
  • Standalone binaries and file-based commands are not ported.

License

MIT

Metadata

Release files for incur-cli 0.10.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 incur-cli 0.10.0
File Size Uploaded Provenance Actions
incur_cli-0.10.0.tar.gz 159.3 kB Without provenance Details for incur_cli-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for incur-cli 0.10.0
File Interpreter ABI Platform Actions
incur_cli-0.10.0-py3-none-any.whl Python 3 none any Details for incur_cli-0.10.0-py3-none-any.whl

Total release size: 281.6 kB

Release files / incur_cli-0.10.0.tar.gz

Download URL incur_cli-0.10.0.tar.gz
Size 159.3 kB
Tags Source
SHA-256 checksum
How to use checksums
55d7966656117b99756fca923117b804df2163f0329b09e0708ff9f5ccb670ee
BLAKE2b-256 checksum
How to use checksums
5cc763cfe7187781bc6b6843eae7f155e1b18038e34fe03fe7f5437d8736d945
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / incur_cli-0.10.0-py3-none-any.whl

Download URL incur_cli-0.10.0-py3-none-any.whl
Size 122.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9be12a2479aaa012d61e525061d59aa1867ac5dc2c13c32c3e029f65f5a00c8b
BLAKE2b-256 checksum
How to use checksums
b79bc7489925e852d88e68cba897eb395396cc8fd9e8d63881438eb02c9e9a93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for incur-cli 0.10.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 release files No provenance

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