Skip to main content

Python SDK for relay job submission

Project description

relay-jobs

Python SDK for relay job submission. See full quickstart below.

Install

pip install relay-jobs

Quickstart

The SDK reads its configuration from (in order) explicit kwargs, the environment variables RELAY_URL / RELAY_TOKEN, and the CLI config file at ~/.relay/config.json (or %APPDATA%\relay\config.json on Windows). The simplest path is to run relay login once, then import and go:

import relay

job = relay.Job(name="nightly-cook", priority=relay.Priority.HIGH)
cook = job.add_task("cook", commands=[["ue4-cook", "--map", "Main"]], retries=2)
job.add_task("test", commands=[["pytest"]], depends_on=[cook])

with relay.Client() as client:
    submitted = client.submit(job)
    print(f"submitted {submitted.id}")
    final = client.wait(submitted.id, timeout=600)
    if final.status != relay.JobStatus.DONE:
        raise RuntimeError(f"job ended {final.status}")

Authoring

relay.Job and relay.Task are Pydantic models that mirror the server's JobSpec exactly. You can use the add_task builder:

job = relay.Job(name="example")
job.add_task(
    "build",
    commands=[["make", "build"]],
    env={"GOOS": "linux"},
    requires={"gpu": "true"},
    timeout_seconds=3600,
    retries=1,
    source=relay.Source(
        type="perforce",
        stream="//depot/main",
        sync=[relay.Sync(path="//depot/main/...", rev="#head")],
        unshelves=[12345],
    ),
)

Or construct from a dict if you already have a JSON spec:

job = relay.Job.model_validate(spec_dict)

depends_on accepts Task instances or names:

a = job.add_task("a", commands=[["echo", "1"]])
b = job.add_task("b", commands=[["echo", "2"]], depends_on=[a])  # or ["a"]

Client API

Method Description
submit(job) POST /v1/jobs. Validates locally, returns the populated Job.
get_job(id) GET /v1/jobs/{id}.
list_jobs(status=, scheduled_job_id=) GET /v1/jobs with optional filters.
cancel_job(id, force=False) DELETE /v1/jobs/{id} — graceful by default; force=True requests an immediate kill on the agent.
get_tasks(job_id) GET /v1/jobs/{id}/tasks.
get_task(id) GET /v1/tasks/{id}.
task_logs(id) GET /v1/tasks/{id}/logs.
follow_job(id) Iterator over SSE Event objects until the job is terminal.
wait(id, timeout=None, poll_interval=1.0) Block (polling) until the job is terminal.
create_schedule(...) POST /v1/scheduled-jobs.
list_schedules() / get_schedule(id) / update_schedule(id, ...) / delete_schedule(id) Standard CRUD.
run_schedule_now(id) POST /v1/scheduled-jobs/{id}/run-now. Admin-only on the server.

Errors

All exceptions descend from relay.RelayError:

Class When
ValidationError Local Pydantic failure or server 400
AuthError Missing token, 401, or 403
NotFound 404
Conflict 409 (e.g. cancelling a terminal job)
ServerError 5xx
HTTPError Any other unexpected status
TimeoutError wait() exceeded its wall-clock limit

The original httpx.Response is attached as .response on each instance for debugging.

Compatibility

  • Python: 3.9, 3.10, 3.11, 3.12, 3.13.
  • Server: tested against relay-server master. The SDK only consumes the existing v1 REST + SSE surface — no server-side changes needed.

Development

From the python/ directory:

python -m venv .venv && .venv/Scripts/python -m pip install -e ".[dev]"
pytest tests/unit
RELAY_INTEGRATION=1 pytest tests/integration   # requires a running relay-server

Or run from the repo root via make python-test and make python-test-integration.

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

relay_jobs-0.1.2.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relay_jobs-0.1.2-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file relay_jobs-0.1.2.tar.gz.

File metadata

  • Download URL: relay_jobs-0.1.2.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for relay_jobs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b54842bfaa9450200992480530af5d5853eafcc0b5105c8b7e86d5545f8c17e2
MD5 b1953ea98ce7d57c85dc32a466fc5895
BLAKE2b-256 938896d6496a63d430503d5d867100974157ca71cbfdd12ca41e861d438e4cda

See more details on using hashes here.

Provenance

The following attestation bundles were made for relay_jobs-0.1.2.tar.gz:

Publisher: release.yml on chadmv/relay

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file relay_jobs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: relay_jobs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for relay_jobs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b781649b9777d3c88326094f534d470b41cde5ecc3730fe864968c3bccb0bf68
MD5 fbff32f669f395c1f376c8769f7e8863
BLAKE2b-256 0df2c01fc144cdcb53a8291dc6167097905d499b0cc2b8d311f1ec96c9095d62

See more details on using hashes here.

Provenance

The following attestation bundles were made for relay_jobs-0.1.2-py3-none-any.whl:

Publisher: release.yml on chadmv/relay

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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