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.0.tar.gz (16.9 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.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: relay_jobs-0.1.0.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for relay_jobs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac45da9f58c3ac3781eafd382419dd57831dde0b3958850a3fa66b97f8343bd8
MD5 b47ff0b81ceb30e6067f30236a29e027
BLAKE2b-256 253caf4aa2a9de861637a633af37b3d9fe20151e76cfdad7e93e2379230654d3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: relay_jobs-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for relay_jobs-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4349bbd232db5ff2085c935d4521b61e194c2be8d59070828e2f7d4557384ffe
MD5 d559e91d7bba8a8bb56699a8272e393f
BLAKE2b-256 d05a1d68abb3ee4ad7433c05683ee8079710471a39502152b76723fe8a025a7c

See more details on using hashes here.

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