Turn any CLI into a Python API, automatically.
Project description
cli-to-py
Turn CLI binaries into Python APIs.
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
Use _ for positional arguments:
await git("diff", name_only=True, _=["HEAD~1"])
# runs: git diff --name-only HEAD~1
Why Use It
- Convert CLIs into async Python APIs with no runtime dependencies.
- 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
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.
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 cli_to_py-0.1.0.tar.gz.
File metadata
- Download URL: cli_to_py-0.1.0.tar.gz
- Upload date:
- Size: 56.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69a9ef5fce281d29fd50287ec79a3d4f0ba18229ca7e67b79b3e718ee5be8ba2
|
|
| MD5 |
306fea19733f2c86eca6e28f9d19e9f8
|
|
| BLAKE2b-256 |
0c754c41b3bc08e89332e5603c52885466111a4d7dd71ad255e9ad5dcb7a0469
|
File details
Details for the file cli_to_py-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cli_to_py-0.1.0-py3-none-any.whl
- Upload date:
- Size: 38.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f372e263866ab80055e1e5a7ac583cdc8f5db3cc18fecb0573c6531f9b23e2f
|
|
| MD5 |
c0a3a4c1a663a86c666fea2aa2a757ab
|
|
| BLAKE2b-256 |
48d9626533994a9b8eab9272bb6164dfed7230afb84b53712a9683304aae71eb
|