Skip to main content

A python remote communications library

Project description

kiwipy

Travis CI Latest Version https://img.shields.io/pypi/wheel/kiwipy.svg https://img.shields.io/pypi/pyversions/kiwipy.svg https://img.shields.io/pypi/l/kiwipy.svg

kiwipy is a library that makes remote messaging using RabbitMQ (and any other protocol for which a backend is written) EASY. I don’t know about you but I find RabbitMQ HARD. It’s all too easy to make a configuration mistake which is then difficult to debug. With kiwipy, there’s none of this, just messaging, made simple, with all the nice properties and guarantees of AMQP.

Here’s what you get:

  • RPC

  • Broadcast (with filters)

  • Task queue messages

Let’s dive in, with some examples taken from the rmq tutorial.

RPC

The client:

from kiwipy import rmq

communicator = rmq.RmqThreadCommunicator.connect(connection_params={'url': 'amqp://localhost'})

# Send an RPC message
print(" [x] Requesting fib(30)")
response = communicator.rpc_send('fib', 30).result()
print((" [.] Got %r" % response))

(rmq_rpc_client.py source)

The server:

import threading

from kiwipy import rmq


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

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


communicator = rmq.RmqThreadCommunicator.connect(connection_params={'url': 'amqp://localhost'})

# Register an RPC subscriber with the name square
communicator.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

from kiwipy import rmq

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

with rmq.RmqThreadCommunicator.connect(connection_params={'url': 'amqp://localhost'}) as communicator:
    communicator.task_send(message)

(rmq_new_task.py source)

And the worker:

import time
import threading

from kiwipy import rmq

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 rmq.RmqThreadCommunicator.connect(connection_params={'url': 'amqp://localhost'}) as communicator:
        communicator.add_task_subscriber(callback)
        threading.Event().wait()
except KeyboardInterrupt:
    pass

(rmq_worker.py source)

Versioning

This software follows Semantic Versioning

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.5.4.tar.gz (36.3 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.5.4-py2.py3-none-any.whl (21.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: kiwipy-0.5.4.tar.gz
  • Upload date:
  • Size: 36.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8

File hashes

Hashes for kiwipy-0.5.4.tar.gz
Algorithm Hash digest
SHA256 253fa005e0c07fa2ab33a46a2a1284f020da59d584bfe5d954d1c757e88aee2e
MD5 892bf3496a743839a9a04bf6b7d9d0f5
BLAKE2b-256 55d97df9f4aa66dc0edb3c7441cec1497d5776d184a28ff9a1da061ae632e0b2

See more details on using hashes here.

File details

Details for the file kiwipy-0.5.4-py2.py3-none-any.whl.

File metadata

  • Download URL: kiwipy-0.5.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8

File hashes

Hashes for kiwipy-0.5.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 d53972c3c5261e433adbe2ca24d60e45ac3090c21b3cf3cc1dd1af84c20d0faf
MD5 25670830194f5746a142accc57f7995b
BLAKE2b-256 ee328e7e0ae5bf5b0d6f16e60bb29377994419451afaac4b1ff90c2e8a330eb5

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