Skip to main content

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 0.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 pyclaudecli 0.1.0
File Size Uploaded
pyclaudecli-0.1.0.tar.gz 12.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyclaudecli 0.1.0
File Interpreter ABI Platform
pyclaudecli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 25.4 kB

Release files / pyclaudecli-0.1.0.tar.gz

Download URL pyclaudecli-0.1.0.tar.gz
Size 12.5 kB
Tags Source
SHA-256 checksum
How to use checksums
edb4a67192c979feada0b8f3c78e77996c0283653566c4c16d47f64b8f69294b
BLAKE2b-256 checksum
How to use checksums
18cb936b28c918d7d9621a3183672a258d0cecd27788035394248f8b7bac7837
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-0.1.0-py3-none-any.whl

Download URL pyclaudecli-0.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7fc13fd6f128332cbd662545c88245f3514f6b7f69f999993e990c8884cc996e
BLAKE2b-256 checksum
How to use checksums
86e25b285adf1ee21fa8c00454e6af8eede30e583e8818c9484c2f008e2d1cd5
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 history Release notifications | RSS feed

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

This release

0.1.0 This release

2 release files

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