A Python SDK for interacting with the Claude CLI tool
Project description
LMSYS SDK
A Python SDK for interacting with the Claude CLI tool.
Installation
pip install lmsys
Requirements
- Python 3.8+
- Claude CLI tool must be installed and available in your PATH
Quick Start
from lmsys import Agent
# Initialize with a working directory
agent = Agent(working_dir="/path/to/your/project")
# Run Claude with a prompt
result = agent.run("Your prompt here")
print(result)
# Auto-streaming output (prints automatically)
lines = agent.run("Generate a story", stream=True)
# Manual streaming (if you need more control)
process = agent.run("Another prompt", stream=True, auto_print=False)
for line in process.stdout:
print(line, end="")
Features
- Simple interface to the Claude CLI tool
- Support for all Claude CLI options
- Automatic or manual streaming output
- Customizable tool access
API Reference
Agent Class
Agent(working_dir=None, allowed_tools=None)
Parameters:
working_dir(str, optional): The working directory for Claude to use. Defaults to current directory.allowed_tools(list, optional): List of tools to allow Claude to use. Defaults to ["Edit", "Bash", "Write"].
Methods
run
run(prompt, stream=False, output_format=None, additional_args=None, auto_print=True)
Run Claude with the specified prompt.
Parameters:
prompt(str): The prompt to send to Claude.stream(bool): If True, handles streaming output. If False, returns the complete output.output_format(str, optional): Optional output format (e.g., "stream-json").additional_args(dict, optional): Additional arguments to pass to the Claude CLI.auto_print(bool): If True and stream=True, automatically prints output. If False, you need to handle streaming manually.
Returns:
- If
stream=False: Returns the complete output as a string. - If
stream=Trueandauto_print=False: Returns a subprocess.Popen object for manual streaming. - If
stream=Trueandauto_print=True: Automatically prints output and returns collected lines as a list.
run_with_tools
run_with_tools(prompt, tools, stream=False, auto_print=True)
Run Claude with specific allowed tools.
Parameters:
prompt(str): The prompt to send to Claude.tools(list): List of tools to allow Claude to use.stream(bool): If True, handles streaming output.auto_print(bool): If True and stream=True, automatically prints output.
Returns:
- If
stream=False: Returns the complete output as a string. - If
stream=Trueandauto_print=False: Returns a subprocess.Popen object. - If
stream=Trueandauto_print=True: Automatically prints output and returns collected lines.
Example: Automatic Streaming
from lmsys import Agent
agent = Agent()
# This will automatically print the output line by line
lines = agent.run("Generate a short story", stream=True)
Example: Manual Streaming with JSON parsing
from lmsys import Agent
import json
agent = Agent()
process = agent.run("Generate a short story", stream=True, output_format="stream-json", auto_print=False)
for line in process.stdout:
if line.strip():
try:
data = json.loads(line)
print(data.get("content", ""))
except json.JSONDecodeError:
print(f"Error parsing JSON: {line}")
License
MIT
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
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
asys-0.1.0-py3-none-any.whl
(4.3 kB
view details)
File details
Details for the file asys-0.1.0-py3-none-any.whl.
File metadata
- Download URL: asys-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0a88d220caa607e8f76e169f1c7bfb36e8a8090704793b967515b73d8ef6dfa
|
|
| MD5 |
2dfe3a05eb93b093eef430ccdd0abc84
|
|
| BLAKE2b-256 |
a3ef5741af067db837a1f1f56e228f85f747b72404009c27b018dfc505b797cf
|