Skip to main content

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=True and auto_print=False: Returns a subprocess.Popen object for manual streaming.
  • If stream=True and auto_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=True and auto_print=False: Returns a subprocess.Popen object.
  • If stream=True and auto_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codesys-0.1.0.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codesys-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file codesys-0.1.0.tar.gz.

File metadata

  • Download URL: codesys-0.1.0.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for codesys-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1010415f75611d798d0b1f8979daafdb73fa83fefed8c8378d7616b0ada07b5a
MD5 1dc2850a54ffd398133a47e2290475b8
BLAKE2b-256 59951c9f041dbecb02aa219924febcd6377f6bd5ad41f753a1ec8ba861102db6

See more details on using hashes here.

File details

Details for the file codesys-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: codesys-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.9

File hashes

Hashes for codesys-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 17bd05ae4297587b5cdda45a4ec13ec4ac4cafecfd9140724fb88c22fbea2701
MD5 b334ccbcc3a93ca43f5bc6f21dc4d665
BLAKE2b-256 1022bd78873572dddb1bb55f841a7587472cc746459fc8a7b8549c3d47642032

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page