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

Uploaded Source

Built Distribution

runrl-0.1.13-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: runrl-0.1.13.tar.gz
  • Upload date:
  • Size: 6.4 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.13.tar.gz
Algorithm Hash digest
SHA256 b1f5871ea210ed9fbf82b0517522bc5ce450b65cc7ecd5c2c4e119524050ec48
MD5 e868a03e29375245801a5222435cf7ee
BLAKE2b-256 3d087b65e400400a644b394f93dd44db30d8340d45b45fb64b94de7f476bed35

See more details on using hashes here.

File details

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

File metadata

  • Download URL: runrl-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 18626639dc3798c13bb55ab2a417e0407cccdac917544c5b517c6111f1f42d07
MD5 f791ffe00e46509fd522cbf86ca375f4
BLAKE2b-256 db91eed807ff77174b6dcda82381ffb4bc421f5ff2def90af7afa90e0bf0ebec

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