Rapidata Python Client
The `rapidata` package provides a Python client to easily interact with the Rapidata Web API, enabling users to programmatically request human annotation for their data. It simplifies creating and managing orders for various human-in-the-loop tasks. The current version is 3.8.0, and the library appears to be under active development with regular updates, supporting Python 3.10 and newer.
Common errors
-
from rapidata import RapidataClient ModuleNotFoundError: No module named 'rapidata'
cause The `rapidata` package is not installed in your current Python environment.fixRun `pip install -U rapidata` to install the package. -
Error: Could not authenticate. Please check your client_id and client_secret or log in interactively.
cause The provided `client_id` and/or `client_secret` are incorrect, expired, or have insufficient permissions. Alternatively, an interactive login attempt failed or timed out.fixVerify your `client_id` and `client_secret` in your Rapidata account settings. Ensure they are correct and have the necessary permissions. If using environment variables, double-check their values. For interactive login, ensure your browser opened and you successfully completed the authentication flow. -
rapidata.exceptions.RapidataAPIError: {'detail': 'Invalid input data: Missing required field "datapoints"'}cause An API call, such as `create_compare_order`, was made without providing all required parameters, or the parameters were incorrectly structured.fixReview the specific Rapidata API documentation for the method you are calling (e.g., `client.order.create_compare_order`). Ensure all `name`, `instruction`, `contexts`, and `datapoints` (or other method-specific parameters) are present and correctly formatted as per the API's expectations.
Warnings
- gotcha The `RapidataClient` can authenticate interactively by opening a browser window for login if `client_id` and `client_secret` are not provided. This is convenient for initial setup but unsuitable for automated scripts or server environments.
- breaking While specific details of breaking changes between major versions (e.g., 2.x to 3.x) are not readily available in public search results, API clients often introduce significant changes to method signatures, object structures, or authentication mechanisms. The documentation mentions versions 2.x and 3.x, implying such changes.
- gotcha Rapidata API calls, especially for creating orders, often require specific data formats (e.g., public URLs for images/videos, correctly structured contexts and datapoints). Incorrect formatting or inaccessible URLs will lead to API errors, which might not be immediately clear from the client-side error message.
Install
-
pip install -U rapidata
Imports
- RapidataClient
from rapidata import RapidataClient
- rapidata_config
from rapidata import rapidata_config
Quickstart
import os
from rapidata import RapidataClient
# Option 1: Interactive login (opens browser)
# client = RapidataClient()
# Option 2: Using client ID and secret (recommended for automation)
client_id = os.environ.get('RAPIDATA_CLIENT_ID', 'your_client_id_here')
client_secret = os.environ.get('RAPIDATA_CLIENT_SECRET', 'your_client_secret_here')
if client_id == 'your_client_id_here' or client_secret == 'your_client_secret_here':
print("Please set RAPIDATA_CLIENT_ID and RAPIDATA_CLIENT_SECRET environment variables or replace placeholders.")
# Fallback to interactive login for demonstration if env vars are not set
# client = RapidataClient() # Uncomment for interactive flow if env vars are missing
else:
client = RapidataClient(client_id=client_id, client_secret=client_secret)
# Example: Create a simple compare order (requires actual data and context)
# This is a placeholder as full order creation requires specific data inputs
try:
# This part is illustrative as it requires actual data (datapoints) and URLs
# order_name = "My Example Alignment Order"
# instruction = "Which image matches the description better?"
# contexts = ["A small blue book sitting on a large red book."]
# datapoints = [["https://example.com/image1.jpg", "https://example.com/image2.jpg"]]
# order = client.order.create_compare_order(
# name=order_name,
# instruction=instruction,
# contexts=contexts,
# datapoints=datapoints
# )
# print(f"Order created: {order.name} (ID: {order.id})")
print("RapidataClient initialized. You can now use client.order, client.validation, etc.")
except Exception as e:
print(f"Could not create order example (requires valid credentials and data): {e}")
# To reset credentials saved locally:
# client.reset_credentials()