Skip to main content

Distributed Python task execution via automatic function serialization

Project description

offwork

Run any Python function on a remote worker — zero setup, zero deployment.

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

Add @offwork.task to a function. offwork captures its source, all dependencies, and all imports automatically. Workers reconstruct and execute everything from scratch — no shared filesystem, no deployment pipeline. Missing packages are installed on the fly.

Quick start

pip install offwork
import asyncio, math, offwork
import offwork

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

def add(a, b):
    return a + b

@offwork.task
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())

Only the entry point needs @offwork.task — everything it calls is captured automatically.

offwork worker --backend local://localhost:9748 --tmp   # start a worker
python my_script.py                                    # → 5.0

For multi-machine, swap local:// for redis:// or an https:// managed broker URL.

Features

Auto dependency capture Functions, classes, constants, closures — recursive AST analysis
Package auto-install Workers pip install missing packages before execution
Async-native .run(), .start(), .map(), asyncio.gather
Retry & timeout @offwork.task(timeout=30, retries=3) with exponential backoff
Scheduling .run_in(delay), .run_at(datetime), .run_every(freq) with cancellation
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; clients raise TaskStalled on silence
Content-hash caching Same code = cache hit, regardless of client
Pluggable backends local:// (TCP), redis://, amqp:// (RabbitMQ), https:// (hosted)
Docker sandbox Container isolation, transparent to clients
Signed execution Pre-shared token or PIN pairing + HMAC-SHA256 task authentication
Graceful shutdown Ctrl+C drains in-flight tasks; second Ctrl+C force-quits

Sandbox

Run tasks inside Docker containers for isolation — transparent to clients:

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

See Sandbox for configuration.

Signing

Pre-shared token or PIN-based pairing + HMAC-SHA256 — workers reject untrusted or tampered tasks:

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

# PIN-based pairing (interactive)
offwork worker --backend redis://localhost:6379 --pair       # displays a 6-digit PIN
offwork pair --backend redis://localhost:6379                # on client: enter the PIN

After setup, tasks are signed automatically. No client-side code changes. See Signing & Pairing.

Documentation

Quick Start Tutorial 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
offwork run examples/remote_execution.py

remote_execution.py · async_execution.py · package_installation.py · progress_reporting.py · cancellation.py · scheduling.py · throttling_and_retry.py · large_module.py

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.2.tar.gz (95.7 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.2-py3-none-any.whl (113.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: offwork-0.1.2.tar.gz
  • Upload date:
  • Size: 95.7 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.2.tar.gz
Algorithm Hash digest
SHA256 b57381f6de47afb97638741c2ad234d140ee2bc2ede19601b851d94e72b7d4b3
MD5 2e3200ad98a76400ffdb76a715c2dfcd
BLAKE2b-256 64d385f38cc8ce6afb12ea6a2484f0d73a02ec8d2f4401857cbe20bc9c2921af

See more details on using hashes here.

File details

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

File metadata

  • Download URL: offwork-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 113.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.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 60f9dab7aa1940dea18542d975ba69d1cbf18b7107e05d37480fd6167331b657
MD5 66d50b99d0c364838dd0815c5a1a4013
BLAKE2b-256 6828ded3f0709b3bc0b21189405576313bb362937d01a6f2748081b9a8e9e5e1

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