Skip to main content

Distributed Python task execution via automatic function serialization

Project description

offwork

PyPI Python 3.11+ License: AGPL-3.0 Typed Zero Dependencies

Run any Python function on a remote worker with just two lines of code.

Put .connect() somewhere at the start of your script, add @offwork.task to your function, that's it. You can now run it remotely — no shared codebase, no deployment pipeline.

offwork captures its entire dependency graph (helpers, imports, closures, constants) and ships it to the worker as a self-contained payload. The worker doesn't need to have any prior knowledge of your code.

Quick start

pip install offwork
offwork worker --backend local://localhost:9748 --tmp  # start a worker in a temp venv
import asyncio, math, offwork

offwork.connect("local://localhost:9748")

def add(a: float, b: float) -> float:
    return a + b

@offwork.task  # only the entry point needs this - add() is captured automatically
def hypotenuse(a: float, b: float) -> float:
    return math.sqrt(add(a**2, b**2))

async def main():
    print(await hypotenuse.run(3.0, 4.0))  # 5.0

asyncio.run(main())

.run() serializes the function graph, submits it to the worker, and returns the result. The worker reconstructs source, installs any missing packages, and executes.

Multi-machine

Swap local:// for Redis or RabbitMQ to run on a remote worker:

pip install offwork[redis]
offwork worker --backend redis://other-machine:6379

See Features for the full API.

Features

Async-native .run(), .start(), .map(), asyncio.gather — all coroutines
Scheduling .run_in(delay), .run_at(datetime), .run_every(interval) with cancellation
Retry & timeout @offwork.task(timeout=30, retries=3) with exponential backoff
Throttling @offwork.task(throttle=timedelta(hours=24)/50) — rate-limit executions
Progress & cancellation offwork.progress(3, 10) inside tasks; await future.cancel() on client
Heartbeat & stall detection Workers heartbeat every second; clients raise TaskStalled on silence
Package auto-install Workers pip install missing packages before execution
Docker sandbox Optional container isolation, fully transparent to clients
Signed execution Pre-shared token or PIN pairing + HMAC-SHA256 task authentication

Security

Signing

To make sure your worker only executes trusted code, use --require-signing.
Configure a shared token or pair interactively with a PIN. See Signing & Pairing for details.

# Token (CI/CD)
offwork token generate
export OFFWORK_SIGNING_TOKEN=<token>                         # client & worker
offwork worker --backend redis://localhost:6379 --require-signing

# PIN pairing (interactive)
offwork worker --backend redis://localhost:6379 --pair       # shows 6-digit PIN
offwork pair --backend redis://localhost:6379                # client: enter PIN

After pairing, tasks are signed automatically with no client code changes. See Signing & Pairing.

Sandbox

To avoid side-effects on the worker machine, run tasks inside Docker containers:

offwork sandbox setup                                      # build image (once)
offwork worker --backend redis://localhost:6379 --sandbox  # run with isolation

See Sandbox for configuration.

Documentation

Features Full feature guide and API walkthrough
Technical Overview Architecture, serialization format, internals
Signing & Pairing Cryptographic task signing protocol
Sandbox Docker container isolation

Examples

offwork worker --backend local://localhost:9748 --tmp  # start worker
offwork run examples/remote_execution.py              # run any example

See examples/README.md for a guide to all examples.

License

AGPL-3.0

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

offwork-0.1.4.tar.gz (104.1 kB view details)

Uploaded Source

Built Distribution

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

offwork-0.1.4-py3-none-any.whl (123.8 kB view details)

Uploaded Python 3

File details

Details for the file offwork-0.1.4.tar.gz.

File metadata

  • Download URL: offwork-0.1.4.tar.gz
  • Upload date:
  • Size: 104.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for offwork-0.1.4.tar.gz
Algorithm Hash digest
SHA256 14bf8b175314ec8d5bd5f050281859c398dd57eab8a39d084c85cb2f865c3a42
MD5 4956b7f9260522db21a9fc07f7df4737
BLAKE2b-256 0404b8239bb7030ca435b908c6cdca937b36060538b0063dc36db4176306e317

See more details on using hashes here.

File details

Details for the file offwork-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: offwork-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 123.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for offwork-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c7442716931020a7b2c213c59ef34be16c3ef3d4eebe677b085d8cb8fdf65b74
MD5 64de00f8f3b7b72b3d857a927a4b0cd0
BLAKE2b-256 d75e81282ba73a328a403296a88c177dd59de2059c8ef475a70746eaf647ca20

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