Skip to main content

Rayon Python SDK

Material-only clients for POST /v1/shape and GET /v1/usage. Requires Python 3.10+. Keep API keys on your server.

API documentation · Releases

Install

python -m pip install 'rayon-sdk-py>=1,<2'

Quickstart

Prepare JavaScript material from files you own or are authorized to use. URLs provide execution context; neither SDK nor API downloads them. Preserve script order.

import os
from pathlib import Path
from rayon_sdk_py import Client, ShapeRequest

shape: ShapeRequest = {
    "source_url": "https://example.com/page",
    "scripts": [{
        "url": "https://example.com/assets/owned.js",
        "source": Path("owned.js").read_text(encoding="utf-8"),
    }],
    "profile": {"user_agent": "your actual user agent", "language": "en-GB"},
    "request": {
        "url": "https://example.com/api/items",
        "method": "POST",
        "content_type": "application/json",
        "body": ' {"item": 1}\n',  # Exact target body, including whitespace.
    },
    "document_cookie": "session=current",  # Current JavaScript-visible cookies.
}
with Client(os.environ["RAYON_API_KEY"]) as client:
    result = client.generate(shape)
    usage = client.usage()
    # Explicitly access result.headers and result.profile_used for your target client.

Clients and cleanup

Client(api_key, *, base_url="https://api.rayonapi.com", timeout=45) owns a persistent ordinary-TLS session. Close it with with or client.close().

AsyncClient has the same operations using async with, await client.generate(shape), await client.usage(), and await client.aclose(). generate(shape, api_key, *, base_url=..., timeout=45) is a one-shot helper. API keys remain in the Bearer authorization header.

Request

Supply exactly one of scripts and material_ref. source_url, profile, and all four request fields are always required. Use body=None when the target request has no body; an empty string represents an explicit empty body. GET and HEAD require body=None; a supplied body requires a supported text content type. Bodies are never parsed, reformatted, or encoded as a JSON object by this SDK.

Material reuse

Persistent clients cache only material references, keyed by source URL and ordered script URLs and source. Each cache is scoped to one client, API key, and server, and uses the server's material_expires_at expiry. Repeating the same material uses its unexpired reference; profile, request, and document cookies are freshly copied for every call. Expired entries trigger a fresh upload on the next call with scripts. A failed reference request is never automatically retried. You may also explicitly supply a server-issued reference together with its original source URL.

Profiles

validate_profile(profile) is a public offline preflight helper. It enforces the same strict fields, alias conflicts, numeric ranges, and effective UTF-8 profile budget as generation, and returns a deep copy of the supplied fields. It neither fills defaults in the returned object nor sends a network request. Text limits count Unicode code points.

BrowserProfile accepts user_agent, platform, language, languages, screen, window, webgl, canvas, and navigator. Nested fields are strictly checked, and conflicting top-level/navigator aliases are rejected. {} selects server defaults. Screen/window dimensions, WebGL renderer/vendor, navigator identity, and a PNG canvas.data_url are supported. The response's effective profile_used omits canvas pixels.

Results

ShapeResult contains headers, request_id, generation_ms, profile_used, and required material_ref/material_expires_at. The six header names use the actual dynamic common prefix and suffixes a, b, c, d, f, z; d may be empty. Prefixes are HTTP tokens of at most 128 characters and header values contain visible ASCII only. Generation does not assert target acceptance. No cookies, status, or internal execution method are returned. Sensitive headers, profile data, and references are excluded from repr.

Limits and transport

Input or response Limit
Serialized request JSON 4 MiB
Scripts 16
UTF-8 script source 2 MiB per script; 3 MiB total
UTF-8 target body 256 KiB
Effective UTF-8 profile JSON 64 KiB, including defaults and alias expansion
Document cookies 16 KiB
Decoded API response 256 KiB; transfer stops when exceeded

Timeout covers the total API request, including async connection-pool waiting and response decoding.

TLS certificate verification stays enabled. Redirects and environment proxies are disabled. Custom bases require HTTPS except local HTTP on localhost, 127.0.0.1, or [::1]; credentials, fragments, and base queries are refused. API transport does not impersonate a browser.

Errors

All errors inherit RayonError. ValidationError precedes network access; TransportError covers network failures; InvalidResponseError covers malformed/oversized responses.

HTTP failures expose sanitized status_code, request_id, code, and retry_after; raw server messages and transport exception details are discarded. RedirectError and MigrationError inherit HTTPError. HTTP 410 requires migration; HTTP 429 exposes a validated Retry-After seconds or HTTP-date value. No request is retried automatically: admitted generations can consume quota.

Migration from 0.1

Version 1.0 removes the URL-only solve function and SolveResult. Replace it with generate and caller-prepared scripts (or a material reference), a fresh browser profile, and an exact target request context. Replace duration/status/method/cookie handling with generation_ms, headers, and profile_used. Existing published 0.1 distributions and tags remain unchanged; they target the retired API.

Development

python -m venv .venv
. .venv/bin/activate
python -m pip install -e '.[dev]'
python -m pytest
python -m build
python -m twine check dist/*

See RELEASE.md for release checks. Licensed under MIT.

Metadata

Release files for rayon-sdk-py 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rayon-sdk-py 1.0.2
File Size Uploaded
rayon_sdk_py-1.0.2.tar.gz 22.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rayon-sdk-py 1.0.2
File Interpreter ABI Platform
rayon_sdk_py-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 36.5 kB

Release files / rayon_sdk_py-1.0.2.tar.gz

Download URL rayon_sdk_py-1.0.2.tar.gz
Size 22.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3b0343a09c34d63193d451a1067d7253490815e0eded1c8be425bbb3961ceaa1
BLAKE2b-256 checksum
How to use checksums
c954c7d6e0a830e8d62f6ca92d689f9d23be9bf396c6b5180bde003d5e09ab99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / rayon_sdk_py-1.0.2-py3-none-any.whl

Download URL rayon_sdk_py-1.0.2-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
171eb23e9573cec89de2d0c0eec13785a451c04cd5b75452d281cd73a518a830
BLAKE2b-256 checksum
How to use checksums
152cb017de599151167a88dbf2fd1f3d3bf8fc19faff5e2db2503d290256a140
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page