Skip to main content

Robust, high-volume, message based communication made easy.

Project description

kiwiPy

kiwiPy Coveralls Github Actions Latest Version https://img.shields.io/pypi/pyversions/kiwipy.svg https://img.shields.io/pypi/l/kiwipy.svg https://joss.theoj.org/papers/10.21105/joss.02351/status.svg

kiwiPy is a library that makes remote messaging using RabbitMQ (and possibly other message brokers) EASY. It was designed to support high-throughput workflows in big-data and computational science settings and is currently used by AiiDA for computational materials research around the world. That said, kiwiPy is entirely general and can be used anywhere where high-throughput and robust messaging are needed.

Here’s what you get:

  • RPC

  • Broadcast (with filters)

  • Task queue messages

Let’s dive in, with some examples taken from the rmq tutorial. To see more detail head over to the documentation.

RPC

The client:

import kiwipy

with kiwipy.connect('amqp://localhost') as comm:
    # Send an RPC message
    print(" [x] Requesting fib(30)")
    response = comm.rpc_send('fib', 30).result()
    print((" [.] Got %r" % response))

(rmq_rpc_client.py source)

The server:

import threading
import kiwipy

def fib(comm, num):
    if num == 0:
        return 0
    if num == 1:
        return 1

    return fib(comm, num - 1) + fib(comm, num - 2)

with kiwipy.connect('amqp://127.0.0.1') as comm:
    # Register an RPC subscriber with the name 'fib'
    comm.add_rpc_subscriber(fib, 'fib')
    # Now wait indefinitely for fibonacci calls
    threading.Event().wait()

(rmq_rpc_server.py source)

Worker

Create a new task:

import sys
import kiwipy

message = ' '.join(sys.argv[1:]) or "Hello World!"

with rmq.connect('amqp://localhost') as comm:
    comm.task_send(message)

(rmq_new_task.py source)

And the worker:

import time
import threading
import kiwipy

print(' [*] Waiting for messages. To exit press CTRL+C')


def callback(_comm, task):
    print((" [x] Received %r" % task))
    time.sleep(task.count(b'.'))
    print(" [x] Done")


try:
    with kiwipy.connect('amqp://localhost') as comm:
        comm.add_task_subscriber(callback)
        threading.Event().wait()
except KeyboardInterrupt:
    pass

(rmq_worker.py source)

Citing

If you use kiwiPy directly or indirectly (e.g. by using AiiDA) then please cite:

Uhrin, M., & Huber, S. P. (2020). kiwiPy : Robust , high-volume , messaging for big-data and computational science workflows, 5, 4–6. http://doi.org/10.21105/joss.02351

This helps us to keep making community software.

Versioning

This software follows Semantic Versioning

Contributing

Want a new feature? Found a bug? Want to contribute more documentation or a translation perhaps?

Help is always welcome, get started with the contributing guide.

Development

This package utilises tox for unit test automation, and pre-commit for code style formatting and test automation.

To install these development dependencies:

pip install tox pre-commit

To run the unit tests:

tox

For the rmq tests you will require a running instance of RabbitMQ. One way to achieve this is using Docker and launching test/rmq/docker-compose.yml.

To run the pre-commit tests:

pre-commit run --all

To build the documentation:

tox -e docs-clean

Changes should be submitted as Pull Requests (PRs) to the develop branch.

Publishing Releases

  1. Create a release PR/commit to the develop branch, updating kiwipy/version.py and CHANGELOG.md.

  2. Fast-forward merge develop into the master branch

  3. Create a release on GitHub (https://github.com/aiidateam/kiwipy/releases/new), pointing to the release commit on master, named v.X.Y.Z (identical to version in kiwipy/version.py)

  4. This will trigger the continuous-deployment GitHub workflow which, if all tests pass, will publish the package to PyPi. Check this has successfully completed in the GitHub Actions tab (https://github.com/aiidateam/kiwipy/actions).

(if the release fails, delete the release and tag)

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

kiwipy-0.9.0.tar.gz (242.1 kB view details)

Uploaded Source

Built Distribution

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

kiwipy-0.9.0-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file kiwipy-0.9.0.tar.gz.

File metadata

  • Download URL: kiwipy-0.9.0.tar.gz
  • Upload date:
  • Size: 242.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for kiwipy-0.9.0.tar.gz
Algorithm Hash digest
SHA256 3dc5a2cbe4bf7127da2c8a6c20476ddad30849b32fa12b495c622059c633db4f
MD5 1e915a34ac43c65a7f68d19762b3ded7
BLAKE2b-256 41d1a56aea1ee27c9aa73c7c6c785f4eb0539799392566b758fc920397afea91

See more details on using hashes here.

File details

Details for the file kiwipy-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: kiwipy-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 41.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for kiwipy-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d861310d64dc15de50667c1c7b7295f2dba50a5561284e8a889e3a6c2b197f9
MD5 74224d84734227d4ee7d6af3453acb71
BLAKE2b-256 c0c02ed83a3b88048db2504ddd67a419148e23a1cf2bc64ee0bbaacb46c80bbb

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