Python client for the RunRL API
Project description
RunRL Python Client
A Python client library for interacting with the RunRL API.
Installation
It's recommended to use a virtual environment.
# Using pip
pip install runrl
# Using uv (recommended)
uv pip install runrl
Usage
import os
import asyncio
from runrl import RunRL, RunRLError
# Get API key from environment variable or replace directly
api_key = os.getenv("RUNRL_API_KEY", "rl-your_api_key_here")
client = RunRL(api_key=api_key)
try:
# List your runs
runs = client.list_runs()
print(f"Found {len(runs)} runs.")
if runs:
print(f"Latest run: {runs[0]}")
# Upload a reward file
# Create a dummy reward file first
with open("my_reward_function.py", "w") as f:
f.write("def reward_function(data):\n return 1.0")
reward_file_info = client.upload_reward_file("my_reward_function.py", friendly_name="My Test Reward")
print(f"Uploaded reward file: {reward_file_info}")
reward_file_id = reward_file_info['file_id']
# Create a run (replace with actual parameters)
# run_details = client.create_run(
# model_name="gpt2",
# reward_file=reward_file_id, # Use the ID from upload
# # ... other parameters like prompt_file, epochs, etc.
# )
# print(f"Created run: {run_details}")
# run_id = run_details['id'] # Or use job_name if available
# Example: Stream logs (needs an async context)
async def stream_example(run_id):
print(f"\nStreaming logs for run {run_id}...")
log_stream = client.stream_logs(run_id=run_id, follow=False) # Use async generator
async for log_entry in log_stream:
print(log_entry)
# Replace 'your_run_id_or_job_name' with an actual ID/name from a completed run
# asyncio.run(stream_example('your_run_id_or_job_name'))
# Example: Download a model (replace with actual job_name)
# client.download_model("your_job_name", "downloaded_model.zip")
# Clean up uploaded file
client.delete_reward_file(reward_file_id)
print(f"Deleted reward file: {reward_file_id}")
os.remove("my_reward_function.py")
except RunRLError as e:
print(f"An API error occurred: {e}")
except FileNotFoundError as e:
print(f"File error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
API Client Methods
See runrl_client/client.py
for available methods corresponding to the API endpoints.
Error Handling
The client raises specific exceptions found in runrl_client.exceptions
for different error conditions (e.g., AuthenticationError
, NotFoundError
, APIServerError
). All inherit from RunRLError
.
Contributing
[Details on contributing, if applicable]
License
MIT License
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
runrl-0.1.12.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file runrl-0.1.12.tar.gz
.
File metadata
- Download URL: runrl-0.1.12.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.6 Darwin/24.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d14944721d1aa176b5884ab66a4cefc233e0d10425c4abcbc1dc2d106a7ccff1
|
|
MD5 |
d26d05acf90dc38a23b539b0e4f9116a
|
|
BLAKE2b-256 |
d853f867091bf047b0a8d6809ca60f47d2b415e619398c6d9c74aa5d68fd4cb6
|
File details
Details for the file runrl-0.1.12-py3-none-any.whl
.
File metadata
- Download URL: runrl-0.1.12-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.11.6 Darwin/24.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
370c4d176237e573c5836efae9f22788a59373be9f44fec36c7abfe03ba95b09
|
|
MD5 |
ce2faaadec9948f153880f89098b8ae5
|
|
BLAKE2b-256 |
2edf0c3bf250e0b257e2f57be5adb1b1f3eb6ed5498bf7f931fc8ae27c015874
|