cli-to-py
Turn CLI binaries into Python APIs for applications and LLM agents.
cli-to-py reads a command's help output, builds a callable Python wrapper, and
lets you run subcommands with keyword arguments instead of hand-built shell
strings.
Full documentation: https://oneryalcin.github.io/cli-to-py/
Install
pip install cli-to-py
or:
uv add cli-to-py
Requires Python 3.11 or newer.
Quick Start
import asyncio
from cli_to_py import convert
async def main():
git = await convert("git")
result = await git.status(short=True)
print(result.stdout)
branch = await git.branch(show_current=True).text()
changed = await git("diff", name_only=True, _=["HEAD~1"]).lines()
print(branch)
print(changed)
asyncio.run(main())
Flags use Python names and are converted to CLI flags:
await git.commit(message="fix", all=True)
# runs: git commit --message=fix --all
Flag values render as two arguments (--output file.txt), the form
hand-rolled parsers like curl and jq require. git is the exception: its
long flags bind inline (--format=%s), because git's revision options
(--format, --pretty, --color) accept nothing else. Single-letter flags
always keep the space form (-C /path). Opt another git-style binary in with
convert("tool", inline_values=True).
Use _ for positional arguments:
await git("diff", name_only=True, _=["HEAD~1"])
# runs: git diff --name-only HEAD~1
Use _global for options that must come before the subcommand
(git -C, docker --context, kubectl --namespace):
await git("log", _global={"C": "/path/to/repo"}, max_count=15)
# runs: git -C /path/to/repo log --max-count=15
Nested command trees dispatch fluently, or as a space-separated string:
uv = await convert("uv")
await uv.pip.install(upgrade=True, _=["httpx"])
# runs: uv pip install --upgrade httpx
await uv("pip install", upgrade=True, _=["httpx"]) # equivalent
Why It Exists
Traditional tool calling makes agents call tools one step at a time. That is awkward when a task needs loops, branching, arithmetic, retries, filtering, or many repeated CLI calls.
cli-to-py gives those CLIs a function-shaped Python interface. An agent can
write code that coordinates commands directly:
git = await convert("git")
changed = await git("diff", name_only=True, _=["HEAD~1"]).lines()
for path in changed:
if path.endswith(".py"):
print(await git("log", oneline=True, n=1, _=["--", path]).text())
That pairs naturally with code-mode interpreters such as Monty, where host applications expose a controlled set of functions and the agent writes Python to orchestrate them.
Why Use It
- Convert CLIs into async Python APIs with no runtime dependencies.
- Expose command-line tools as functions for agent code-mode workflows.
- Validate flags and arguments before spawning a subprocess.
- Keep subprocess output ergonomic with
.text(),.lines(), and.json(). - Stream output, inherit stdio, set timeouts, pass env/cwd, and cancel work.
- Generate standalone wrapper modules for tools you want to check into a project.
Documentation
- Installation
- Quick start
- Agent code mode
- Validation
- Runtime control
- Code generation
- Parser limits
- Public API
CLI Wrapper Generation
Generate a dependency-free Python wrapper from a CLI:
cli-to-py git -o git_wrapper.py
The generated .py module and .pyi stub can be committed to another project
without depending on cli-to-py at runtime.
Development
make test # unit and integration tests
make ci # full CI path, including package build
make docs # strict MkDocs build
make build # source distribution and wheel
See the release checklist for publishing steps.
Status
This project parses common --help formats pragmatically. It is useful for many
CLIs, but it is not a formal parser for every help style. See
parser limits
before relying on generated wrappers for unusual CLIs.
Metadata
Release files for cli-to-py 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cli_to_py-0.2.1.tar.gz | 66.0 kB | Without provenance | Details for cli_to_py-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cli_to_py-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for cli_to_py-0.2.1-py3-none-any.whl |
Total release size: 108.9 kB
Release files / cli_to_py-0.2.1.tar.gz
| Download URL | cli_to_py-0.2.1.tar.gz |
|---|---|
| Size | 66.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cf6b7d419a5782df6b68419d6229a3d4c8b79b7f95224f1e154bcf870a91d4aa
|
|
BLAKE2b-256 checksum How to use checksums |
7a3637118500011a3c9c58085453308ab841f905cdd90b60eb8512931d140c55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Release files / cli_to_py-0.2.1-py3-none-any.whl
| Download URL | cli_to_py-0.2.1-py3-none-any.whl |
|---|---|
| Size | 42.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
97aeab559f3aa6c2abbe96bff9a03d328b5a973765cc996b2ea3903825afea48
|
|
BLAKE2b-256 checksum How to use checksums |
ec7affc1a91c80e708e6d5eae9351107169856abce75780e3135b0f701eef7ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.6
|
Security for cli-to-py 0.2.1
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.