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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file relay_jobs-0.1.1.tar.gz.
File metadata
- Download URL: relay_jobs-0.1.1.tar.gz
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bdc0fd32d87a5df2ff146f6cc3c3446efb69d7b4a9cd9f05c039782452e1818
|
|
| MD5 |
4e568c145c0e20d9cd535a3db0b994da
|
|
| BLAKE2b-256 |
f6970dba3ec750aed152b6d56b062b3c7a4eacb48399a93afd245d9bfcea19a8
|
Provenance
The following attestation bundles were made for relay_jobs-0.1.1.tar.gz:
Publisher:
release.yml on chadmv/relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relay_jobs-0.1.1.tar.gz -
Subject digest:
8bdc0fd32d87a5df2ff146f6cc3c3446efb69d7b4a9cd9f05c039782452e1818 - Sigstore transparency entry: 1589658540
- Sigstore integration time:
-
Permalink:
chadmv/relay@15b7953784e8422379b267aad824a9f8179d4782 -
Branch / Tag:
refs/tags/python-v0.1.1 - Owner: https://github.com/chadmv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@15b7953784e8422379b267aad824a9f8179d4782 -
Trigger Event:
push
-
Statement type:
File details
Details for the file relay_jobs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: relay_jobs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e42ab6b0dc6d72abbb793a89f5df91b09eb4101136c3c98c2045db430a77b978
|
|
| MD5 |
f2c81af5b1a3bdc73218efed3a65093d
|
|
| BLAKE2b-256 |
83d1526ca25d7bebf9b81ea838c414b2d9f39c62285d6e1d2280183920045498
|
Provenance
The following attestation bundles were made for relay_jobs-0.1.1-py3-none-any.whl:
Publisher:
release.yml on chadmv/relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
relay_jobs-0.1.1-py3-none-any.whl -
Subject digest:
e42ab6b0dc6d72abbb793a89f5df91b09eb4101136c3c98c2045db430a77b978 - Sigstore transparency entry: 1589658569
- Sigstore integration time:
-
Permalink:
chadmv/relay@15b7953784e8422379b267aad824a9f8179d4782 -
Branch / Tag:
refs/tags/python-v0.1.1 - Owner: https://github.com/chadmv
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@15b7953784e8422379b267aad824a9f8179d4782 -
Trigger Event:
push
-
Statement type: