Skip to main content

Python SDK for runqy-worker tasks

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

runqy-task

Python SDK for creating tasks that run on runqy-worker.

Installation

pip install git+https://github.com/Publikey/runqy-python.git

Usage

Simple Task

from runqy_task import task, run

@task
def process(payload: dict) -> dict:
    return {"message": "Hello!", "received": payload}

if __name__ == "__main__":
    run()

With Model Loading

For ML inference tasks, use @load to load models once at startup:

from runqy_task import task, load, run

@load
def setup():
    """Runs once before ready signal. Return value is passed to @task as ctx."""
    model = load_heavy_model()  # Load weights, etc.
    return {"model": model}

@task
def process(payload: dict, ctx: dict) -> dict:
    """Process tasks using the loaded model."""
    prediction = ctx["model"].predict(payload["input"])
    return {"prediction": prediction}

if __name__ == "__main__":
    run()

One-Shot Tasks

For lightweight tasks that don't need to stay loaded in memory, use run_once():

from runqy_task import task, run_once

@task
def process(payload: dict) -> dict:
    return {"result": payload["x"] * 2}

if __name__ == "__main__":
    run_once()  # Process one task and exit
Function Behavior Use case
run() Loops forever, handles many tasks ML inference (expensive load)
run_once() Handles ONE task, exits Lightweight tasks

Protocol

The SDK handles the runqy-worker stdin/stdout JSON protocol:

  1. Load phase: Calls @load function (if registered)
  2. Ready signal: Sends {"status": "ready"} after load completes
  3. Task input: Reads JSON from stdin: {"task_id": "...", "payload": {...}}
  4. Response: Writes JSON to stdout: {"task_id": "...", "result": {...}, "error": null, "retry": false}

Development

# Install in editable mode
pip install -e .

# Test
echo '{"task_id":"t1","payload":{"foo":"bar"}}' | python your_model.py

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

runqy_task-0.1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

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

runqy_task-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for runqy_task-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f71d625f67204caaee5f42c5583ec004487de156bf52ea0c52bac12b210ac9f3
MD5 6866ffdc55e8fa0e797d6d5f3608c06d
BLAKE2b-256 1e87808aa17b9ce951b5a393d626ed53fe018556d54342ffe10e1505326abf91

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for runqy_task-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bc424a07a9d6de3c795a381020a28eaf916e43be5201b47aba116e16d3dc5230
MD5 fb50c38c59ae8b48d213a2b6b22a8aac
BLAKE2b-256 8d489f03a5fcb459af3b20130db8822d7f9f6eebfe401ca0b925c2eeee772c58

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