Python SDK for R CLI - Local AI Agent Runtime
Project description
R SDK for Python
Official Python SDK for the R CLI API - Your Local AI Agent Runtime.
Installation
pip install r-sdk
Or install from source:
cd sdks/python
pip install -e .
Quick Start
from r_sdk import RClient
# Connect to local R CLI server
client = RClient(base_url="http://localhost:8000")
# Check server status
status = client.status()
print(f"Server: {status.status}, Skills: {status.skills_loaded}")
# Chat with AI
response = client.chat("Generate a Python hello world")
print(response.message)
Authentication
API Key (Recommended)
client = RClient(
base_url="http://localhost:8000",
api_key="your-api-key"
)
Username/Password
client = RClient(base_url="http://localhost:8000")
client.login("admin", "password")
JWT Token
client = RClient(
base_url="http://localhost:8000",
token="your-jwt-token"
)
Usage Examples
Chat
from r_sdk import RClient, ChatMessage
client = RClient(api_key="your-key")
# Simple chat
response = client.chat("What is 2 + 2?")
print(response.message)
# With conversation history
history = [
ChatMessage(role="user", content="My name is Alice"),
ChatMessage(role="assistant", content="Hello Alice!"),
]
response = client.chat("What's my name?", history=history)
# Force a specific skill
response = client.chat("Generate SQL query", skill="sql")
print(f"Used skill: {response.skill_used}")
print(f"Tools called: {response.tools_called}")
# Streaming
for chunk in client.chat("Write a poem", stream=True):
print(chunk, end="", flush=True)
Skills
# List all skills
skills = client.list_skills()
for skill in skills:
print(f"{skill.name}: {skill.description}")
for tool in skill.tools:
print(f" - {tool.name}")
# Get specific skill
skill = client.get_skill("code")
print(skill.description)
API Keys Management
# List your API keys
keys = client.list_api_keys()
for key in keys:
print(f"{key.name} - {key.scopes}")
# Create new API key
key_value, key_info = client.create_api_key(
name="My App",
scopes=["read", "write", "chat"]
)
print(f"Save this key: {key_value}") # Only shown once!
# Delete an API key
client.delete_api_key(key_info.key_id)
Audit Logs (Admin)
# Get recent audit logs
logs = client.get_audit_logs(limit=100)
for log in logs:
print(f"[{log.severity}] {log.action}: {log.success}")
# Filter by action
chat_logs = client.get_audit_logs(action="chat.request")
# Filter by success/failure
failures = client.get_audit_logs(success=False)
Async Client
import asyncio
from r_sdk import AsyncRClient
async def main():
async with AsyncRClient(api_key="your-key") as client:
# All methods are async
status = await client.status()
response = await client.chat("Hello!")
skills = await client.list_skills()
asyncio.run(main())
Error Handling
from r_sdk import RClient, AuthError, RateLimitError, APIError
client = RClient()
try:
response = client.chat("Hello")
except AuthError as e:
print(f"Auth failed: {e.message}")
except RateLimitError as e:
print(f"Rate limited. Retry after: {e.retry_after}s")
except APIError as e:
print(f"API error {e.status_code}: {e.message}")
Context Manager
# Client closes automatically
with RClient(api_key="your-key") as client:
response = client.chat("Hello!")
Type Safety
All responses are typed dataclasses:
from r_sdk import StatusResponse, ChatResponse, SkillInfo
status: StatusResponse = client.status()
response: ChatResponse = client.chat("Hi")
skills: list[SkillInfo] = client.list_skills()
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 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 r_cli_sdk-0.1.0.tar.gz.
File metadata
- Download URL: r_cli_sdk-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a687f77f4ba168a64856adf096ab0e8a047f927bf44c15e3e0e0a6d4ef3b2ae
|
|
| MD5 |
3b0efad199f8ad722c79ae0a0e4cf2b0
|
|
| BLAKE2b-256 |
f487d090ac5b9842b07a2393bce8c4aeebf60cf2f99a35fd79be3f2b693bf792
|
Provenance
The following attestation bundles were made for r_cli_sdk-0.1.0.tar.gz:
Publisher:
release.yml on raym33/r
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
r_cli_sdk-0.1.0.tar.gz -
Subject digest:
9a687f77f4ba168a64856adf096ab0e8a047f927bf44c15e3e0e0a6d4ef3b2ae - Sigstore transparency entry: 767634507
- Sigstore integration time:
-
Permalink:
raym33/r@565ec7a4b7d4c7e54571c09401e4f3abcc008603 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/raym33
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@565ec7a4b7d4c7e54571c09401e4f3abcc008603 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file r_cli_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: r_cli_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a88b95a926b79a3a1ea4102d3dbd23146e52bb38ae3329e9c99c3c448d283f7
|
|
| MD5 |
744df45ccb0b49ccf331427a052f250b
|
|
| BLAKE2b-256 |
2cfd2c4302a26b0cf53b78d47cbdaed85866bd3a11d0c0f441e844eeb772f96e
|
Provenance
The following attestation bundles were made for r_cli_sdk-0.1.0-py3-none-any.whl:
Publisher:
release.yml on raym33/r
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
r_cli_sdk-0.1.0-py3-none-any.whl -
Subject digest:
5a88b95a926b79a3a1ea4102d3dbd23146e52bb38ae3329e9c99c3c448d283f7 - Sigstore transparency entry: 767634509
- Sigstore integration time:
-
Permalink:
raym33/r@565ec7a4b7d4c7e54571c09401e4f3abcc008603 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/raym33
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@565ec7a4b7d4c7e54571c09401e4f3abcc008603 -
Trigger Event:
workflow_dispatch
-
Statement type: