Skip to main content

A python remote communications library

Project description



# kiwipy

| master | [![Build Status](https://travis-ci.org/muhrin/kiwipy.svg?branch=master)](https://travis-ci.org/muhrin/kiwipy)|
|--|--|
| dev |[![Build Status](https://travis-ci.org/muhrin/kiwipy.svg?branch=develop)](https://travis-ci.org/muhrin/kiwipy)|

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](https://www.rabbitmq.com/getstarted.html).

## RPC

The client:
```python
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)](https://raw.githubusercontent.com/muhrin/kiwipy/develop/examples/rmq_rpc_client.py)


The server:
```python
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'}) # pylint: disable=invalid-name

# 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)](https://raw.githubusercontent.com/muhrin/kiwipy/develop/examples/rmq_rpc_server.py)


## Worker

Create a new task:
```python
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)](https://raw.githubusercontent.com/muhrin/kiwipy/develop/examples/rmq_new_task.py)


And the worker:
```python
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)](https://raw.githubusercontent.com/muhrin/kiwipy/develop/examples/rmq_worker.py)


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.3.1.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

kiwipy-0.3.1-py2.py3-none-any.whl (20.0 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: kiwipy-0.3.1.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for kiwipy-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8af6685da82321cb68c21cee39d4e45bf4b88be64d0643ccdabb96214b6c91f8
MD5 b90f40364d5cdae73f8d9270d7ed8999
BLAKE2b-256 92eab8697ea0c7196989f776f02e67a2b02daddb7d9adfdd9907459f630662e9

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: kiwipy-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.6

File hashes

Hashes for kiwipy-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 68201a77386958edcae881f06eb2ae859b20a629d063e518b25677d96acea4ff
MD5 101ec420a98b30393e672abb64a20c99
BLAKE2b-256 961f96193629380f96019bec220493e26a2256763cfef225a622eb6320fee3ca

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page