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

Uploaded Source

Built Distribution

runrl-0.1.14-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: runrl-0.1.14.tar.gz
  • Upload date:
  • Size: 6.8 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.14.tar.gz
Algorithm Hash digest
SHA256 9829e946baf74e17ae88b0c76df208e95e0a0f981a426380b214beb1e31e5549
MD5 5d65f4efbbe74f1c0f116efa50d4f409
BLAKE2b-256 2556934c0104fb6fab590176c071f9e36a48cd1fb660da68e60802d9691f76bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: runrl-0.1.14-py3-none-any.whl
  • Upload date:
  • Size: 8.0 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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 91d64f571a14d06bd1db031dadcef397c13c0079261b9471b17353515eaad255
MD5 a0fe82062e3e23562ceae5f470462acf
BLAKE2b-256 6611ed1e3d1c89752952f4b23728facee87ae1de7a3fec7bc23e06ac5f76f5f8

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