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

Features

Async-native .run(), .submit(), .map(), asyncio.gather — all coroutines
Scheduling submit(run_in=delay), submit(run_at=dt), submit(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; fut.cancel() / await fut.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
... See Features for more information.

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.2.1.tar.gz (109.5 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.2.1-py3-none-any.whl (130.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for offwork-0.2.1.tar.gz
Algorithm Hash digest
SHA256 eb81a30d4326f959ad440e42e15876c143ed15c7360d914d0346e16f971a10a8
MD5 69082c6e6bfed380ec6d01b05b00b78b
BLAKE2b-256 6c945bd3a31fce7e2b23730668a536872c1d40be941e4f824f1f4666c11b751c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: offwork-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 130.1 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.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8ff09b817f34fa110e308f0303d5aec3c6c89a42ddf09bccc16ab284faf38f9e
MD5 12eef7ee197d6f245dae1b7ad98eed2d
BLAKE2b-256 62f6338bb585ca934d05bf03219f72cd710a6a577fea3ad8a8b702a19611a7e0

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