Skip to main content

Machinery Python SDK

PyPI

This is a subset Python implementation of a worker for RichardKnop/machinery.

Limitations

  • Broker is strictly only for Redis
  • BackendResult is strictly only for MongoDB

Development Environment

Use venv with python 3.

# ---- Setup
$ sudo apt install python3 python3-venv
$ python3 -m venv ~/.venv/simcel
# ---- Activate venv
$ source ~/.venv/simcel/bin/activate
(simcel) $ pip3 install -r requirements.txt
# ---- Running
(simcel) $ python3 main.py

Usage

To start up machinery instance for Python:

from machinery import Value, Machinery

def add(a: Value, b: Value):
    return (Value("int64", a.value() + b.value()))

def multiply(a: Value, b: Value):
    return (Value("int64", a.value() * b.value()))

def worker(name: Value, delayms: Value):
    return (
        Value("string", f"hello {name.value()}"),
        Value("int64", delayms),
    )

machinery = Machinery(
    broker_uri="redis://:helloworld@localhost:6379",
    backend_uri="mongodb://mongo:moonbucks@localhost:27017/?authSource=admin",
    queue="machinery_tasks",
)
machinery.register_callback("add", add)
machinery.register_callback("multiply", multiply)
machinery.register_callback("hello", worker)
# Note that start() is a blocking function.
machinery.start()

To send a machinery task and receive its results:

task = machinery.send_task(queue, "add", [
    Value("int64", 30),
    Value("int64", 50)
])
# Note that wait_for_results() is a blocking function.
results = machinery.wait_for_results(task)
print(results)      # [ Value("int64", 80) ]

Creating a Worker

Workers have these restrictions:

  • Inputs should be of type pymachinery.Value
  • Outputs should be of type pymachinery.Value, or a tuple of pymachinery.Value

Metadata

Release files for pymachinery 0.1.3

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

Source distribution (sdist)

Source distribution for pymachinery 0.1.3
File Size Uploaded
pymachinery-0.1.3.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pymachinery 0.1.3
File Interpreter ABI Platform
pymachinery-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.0 kB

Release files / pymachinery-0.1.3.tar.gz

Download URL pymachinery-0.1.3.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
49aee5a4887c7661ab4db48b8bc97a3b69d9148e169fa58cb8f782ba80ed2836
BLAKE2b-256 checksum
How to use checksums
0fe1399f29f9ab3a22e7e8e8a401053be677b4ae9e15ef3f7f35cc35becd039a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3

Release files / pymachinery-0.1.3-py3-none-any.whl

Download URL pymachinery-0.1.3-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4fbf60a91b5acc679317dd44b2cc48a551136e20ba9e2bc0a49b5be83ba88329
BLAKE2b-256 checksum
How to use checksums
195eebbfbdf626331fa43d0bfe800c20dfc279948502d2e41f45854b0b4952ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.3

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

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