pyclaudecli
A Python library that wraps the Claude Code CLI (claude) so you can drive it from Python instead of shelling out by hand: one-shot prompts, JSON/streaming output, background agents, authentication, MCP servers, plugins, and the rest of the CLI's surface.
It's a thin wrapper, not a reimplementation — every call runs the real claude binary, so it always reflects whatever version, auth, and config you have installed locally.
Install
pip install pyclaudecli
Requires the claude CLI itself to be installed and on PATH (see the Claude Code docs).
Quickstart
from pyclaudecli import ClaudeCLI
claude = ClaudeCLI()
# One-shot prompt
print(claude.prompt("Summarize this repo's README.", model="haiku"))
# Structured result (cost, session id, etc.)
result = claude.prompt_json("What's 2+2?", model="haiku")
print(result["result"], result["total_cost_usd"])
# Live streaming events
for event in claude.prompt_stream("Write a haiku about tests.", model="haiku"):
print(event["type"])
Background agents
session_id = claude.start_background("Refactor the auth module", model="sonnet")
claude.list_agents()
claude.logs(session_id, strip_ansi=True)
claude.stop(session_id)
claude.rm(session_id)
Auth
claude.auth_status() # {"loggedIn": True, "email": "...", ...}
# Prints the sign-in URL, then forwards the pasted code to finish login
claude.auth_login()
MCP servers and plugins
claude.mcp_add("sentry", "https://mcp.sentry.dev/mcp", transport="http")
claude.mcp_list()
claude.plugin_install("some-plugin", yes=True)
claude.plugin_list(as_json=True)
See ClaudeCLI's docstrings for the full method list — it covers every top-level claude command (auth, mcp, plugin, project, agents/background sessions, auto-mode, doctor, update, install, import, ultrareview, gateway) plus the main prompt flags. Anything not exposed as a named parameter can still be passed through via each method's extra_flags dict.
Errors
All CLI failures raise ClaudeCLIError (or ClaudeNotFoundError / ClaudeTimeoutError), carrying returncode, stdout, and stderr.
License
MIT
Release files for pyclaudecli 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyclaudecli-1.0.0.tar.gz | 12.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyclaudecli-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.4 kB
Release files / pyclaudecli-1.0.0.tar.gz
| Download URL | pyclaudecli-1.0.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65d7e8159ade9c9266704eb6196c56ffa4a784464bf3d2695cef42bcd4677e30
|
|
BLAKE2b-256 checksum How to use checksums |
50325d68e33204d1ad372b1a92637235bf7ee4eb7dd1d37905be21a59bb52afd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.14 {"installer":{"name":"uv","version":"0.12.14","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":null}
|
Release files / pyclaudecli-1.0.0-py3-none-any.whl
| Download URL | pyclaudecli-1.0.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d151fe43d613fdeaa7bdae180c12ec9edb4dba32b7213406af97d8945134eca1
|
|
BLAKE2b-256 checksum How to use checksums |
7d2d25ae9ca867eb8a79c20b1485052db6c02b51bc469584498162af01a1ec1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.14 {"installer":{"name":"uv","version":"0.12.14","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":null}
|