Skip to main content

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.15.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

runrl-0.1.15-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file runrl-0.1.15.tar.gz.

File metadata

  • Download URL: runrl-0.1.15.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.6 Darwin/24.1.0

File hashes

Hashes for runrl-0.1.15.tar.gz
Algorithm Hash digest
SHA256 92ea8bb4ac14d07c6f3c6c00cb6e413612313b081d3bbf9ba7632bfe99baece3
MD5 3a225bf4939fae59f879d440319e3ea4
BLAKE2b-256 dd1eaf4939d2db0ab2ee1e0c629d62dc50dec14a6cf90c4ac43846e2337bd78d

See more details on using hashes here.

File details

Details for the file runrl-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: runrl-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 8.2 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

Hashes for runrl-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 1ee4f2beeb1f68ea9a130b0aaa82023cd15994855eecaee5f71bacbb7a761d73
MD5 2498d781de7f770d789360416f869f73
BLAKE2b-256 27ac46d656d0858125582e772be2c30ec4868d941fc6b62cb771188b43125d84

See more details on using hashes here.

Supported by

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