Skip to main content

PyPI Downloads Downloads License: MIT

Distributed Compute

A Python library for distributing computational workloads across multiple devices on a local network. Allows you to utilize your spare computers into a computing cluster to perform complex tasks that would require a lot of computing power and making it easy to connect devices locally.

Features

  • Interactive CLI - For monitoring worker health (CPU usage, task counts, active workers), and trigger Python script runs.
  • Load Balancing - Tasks distributed to least-loaded workers
  • Fault Tolerance - Automatic task redistribution on worker failure
  • Authentication - Coordinator can now create a password that is required for the workers to connect to.
  • Task Retry - Configurable automatic retries for failed tasks before giving up

Installation

Install via pip (Python 3.7+):

pip install distributed-compute-locally

Quick Start

1. Start the Coordinator

On your main machine:

distcompute coordinator

This starts an interactive coordinator with a beautiful CLI where you can run commands, check status, and execute tasks directly.

2. Connect Workers

On each worker machine (laptops, desktops, etc.):

distcompute worker <coordinator-ip>

Or on the same machine for local testing:

distcompute worker
# Defaults to localhost

Example with remote coordinator:

distcompute worker 192.168.1.100

3. Run Your Computation

from distributed_compute import Coordinator

# Initialize coordinator
coordinator = Coordinator(port=5555)
coordinator.start()

# Define your compute function
def heavy_computation(x):
    return x ** 2

# Distribute work across all connected workers
results = coordinator.map(heavy_computation, range(1000))
print(results)  # [0, 1, 4, 9, 16, ...]

That's it! Your computation is now running across all connected machines.

CLI Commands

The distcompute command provides several options:

# Start coordinator (with interactive mode)
distcompute coordinator [port]

# Connect worker (host defaults to localhost)
distcompute worker [host] [port] [name]

# Run demo
distcompute demo

When you start the coordinator, it now launches an interactive terminal with a beautiful CLI interface (powered by Rich and prompt_toolkit):

distcompute coordinator

You'll see a prompt where you can run commands:

distcompute> help

Available Commands:
  run <file.py>  - Execute a task file across workers
  status         - Show cluster status with worker stats
  help           - Show this help message
  exit           - Shutdown coordinator

Example task file:

def monte_carlo_pi(num_samples):
    import random
    inside = 0
    for _ in range(num_samples):
        x, y = random.random(), random.random()
        if x*x + y*y <= 1.0:
            inside += 1
    return inside

TASK_FUNC = monte_carlo_pi
ITERABLE = [1_000_000 for _ in range(20)]  # 20 tasks, each with 1 million samples

Running tasks interactively:

distcompute> status
┌─────────────────────────────────────┐
│         Cluster Status              │
├────────────────┬────────────────────┤
│ Metric         │ Value              │
├────────────────┼────────────────────┤
│ Workers        │ 2                  │
│ Tasks Pending  │ 0                  │
│ Tasks Completed│ 20                 │
└────────────────┴────────────────────┘

┌────────────────────────────────────────────────────────┐
│              Worker Details                            │
├──────────────┬────────────┬─────────────┬──────────────┤
│ Worker       │ CPU %      │ Tasks Done  │ Active       │
├──────────────┼────────────┼─────────────┼──────────────┤
│ worker-1     │ 25.4%      │ 12          │ 0            │
│ worker-2     │ 18.7%      │ 8           │ 0            │
└──────────────┴────────────┴─────────────┴──────────────┘

distcompute> run my_task.py
Running my_task.py across 2 worker(s)...
✓ Results: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, ...]

distcompute> exit
Shutting down coordinator...

Task Retry

Failed tasks can be automatically retried with the max_retries parameter:

# Retry each failed task up to 3 times before giving up
results = coordinator.map(heavy_computation, range(1000), max_retries=3)

When a task fails:

  • If max_retries > 0 and retries remain, the task is re-queued and sent to an available worker
  • If all retries are exhausted, the result for that task is None
  • With the default max_retries=0, behavior is unchanged from previous versions

This is useful for transient failures (network hiccups, temporary resource exhaustion, etc.).

Requirements

  • Python 3.7 or higher
  • Network connectivity between machines
  • Same Python environment on all workers (recommended)
  • prompt_toolkit>=3.0.0 and rich>=13.0.0 (auto-installed for interactive CLI)

Troubleshooting

Workers not connecting?

  • Ensure port 5555 (default) is open on the coordinator machine
  • Check firewall settings
  • Verify machines are on the same network
  • Try specifying IP explicitly: distcompute worker 192.168.1.100

Tasks failing?

  • Ensure all workers have required dependencies installed
  • Check worker logs for error messages
  • Verify functions are serializable (no lambdas with external state)

Contributing

Contributions are welcome! This project aims to make distributed computing accessible to everyone.

License

MIT License - see LICENSE file for details.

Changelog

v0.1.7

  • Task Retry - Added max_retries parameter to coordinator.map() for automatic retry of failed tasks
  • Bug Fix - Fixed version mismatch across __init__.py, pyproject.toml, and setup.py
  • Bug Fix - Fixed default port inconsistency (now consistently 5555 everywhere)
  • Bug Fix - Fixed .gitignore incorrectly excluding the tests/ directory from git tracking

v0.1.6

  • Large payload handling with chunked transmission and zlib compression

v0.1.5

  • Password authentication for coordinator-worker connections

v0.1.4

  • Interactive CLI with Rich UI and worker statistics

v0.1.2

  • Progress callbacks (on_progress, on_task_complete)

Acknowledgments

This project is heavily inspired by Dask, and powered by Python's cloudpickle for function serialization, psutil for resource monitoring, Rich and prompt_toolkit for providing a live cluster dashboard (CPU/Memory/Task stats).

Metadata

Release files for distributed-compute-locally 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for distributed-compute-locally 0.1.7
File Size Uploaded Provenance Actions
distributed_compute_locally-0.1.7.tar.gz 44.1 kB Without provenance Details for distributed_compute_locally-0.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for distributed-compute-locally 0.1.7
File Interpreter ABI Platform Actions
distributed_compute_locally-0.1.7-py3-none-any.whl Python 3 none any Details for distributed_compute_locally-0.1.7-py3-none-any.whl

Total release size: 70.3 kB

Release files / distributed_compute_locally-0.1.7.tar.gz

Download URL distributed_compute_locally-0.1.7.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
746d55d4e48a95c5795f5fd5b566cb52fbeeafb09be160c489759239fdc67a7e
BLAKE2b-256 checksum
How to use checksums
246369e9b4bf897e6f531b744f63b2c3bce0720165b71b7c0366994026f4b1ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Release files / distributed_compute_locally-0.1.7-py3-none-any.whl

Download URL distributed_compute_locally-0.1.7-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af22c0381a9273aaaab8e280da16a636e7cc855b5af01c9467ca62df97df290c
BLAKE2b-256 checksum
How to use checksums
28062960f057f49a71ad4fa29afa6f719082a7819f23844759b04ff22c5694e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.2

Security for distributed-compute-locally 0.1.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page