kiu

Kiu is a python package that provides a simple way to push jobs to a queue tube. Initially focused on Pusher.

Usage

First step is intall from private repository: bash pip install --extra-index-url https://api.packagr.app/OJDhXySqK kiu or pip install --extra-index-url https://api.packagr.app/OJDhXySqK kiu==0.0.1

Code example

Pusher Callback

Push a callback job to a pusher ```python from kiu import Kiu, CallbackAuth

host = 'localhost' port = 11300

k = Kiu(host=host, port=port) k.connect()

Pusher works with a queue name "pusher_requests" but you can change it if you set pusher with another queue name.

tube_name = 'another_tube_name_because_i_changed_it' url = 'http://localhost:8000/callback' method = 'POST' payload = { "data": "Hello, World!" }

Adding a HMAC signaturek to the callback

callback_auth = CallbackAuth( auth_type=CallbackAuth.AuthType.HMAC, secret_key='my_secret_key', )

job_id = k.queue_pusher_callback( tube_name=tube_name, url=url, method=method, payload=payload, proxy='https://proxy.com', callback_auth=callback_auth, origin='domain.com', result_queue_name='webhook_results_queue', ) print(f'Inserted job ID: {job_id}') ```

Pusher SMS

Push an SMS job to a pusher ```python from kiu import Kiu

host = 'localhost' port = 11300

k = Kiu(host=host, port=port) k.connect()

Pusher works with a queue name "pusher_requests" but you can change it if you set pusher with another queue name.

tube_name = 'another_tube_name_because_i_changed_it' to = '1234567890' message = 'Hello, World!'

originator is optional and its the text that you will see on the SMS sender

originator = 'Kiu'

job_id = k.queue_pusher_sms( tube_name=tube_name, originator=originator, to=to, message=message, result_queue_name='sms_results_queue', ) print(f'Inserted job ID: {job_id}') ```

Pusher Email

Push an Email job to a pusher ```python from kiu import Kiu

host = 'localhost' port = 11300

k = Kiu(host=host, port=port) k.connect()

Pusher works with a queue name "pusher_requests" but you can change it if you set pusher with another queue name.

tube_name = 'another_tube_name_because_i_changed_it' to = 'test@email.com' subject = 'Hello, World!' message = 'Hello, World!'

job_id = k.queue_pusher_email( tube_name=tube_name, send_to=to, subject=subject, message=message, result_queue_name='email_results_queue', )

print(f'Inserted job ID: {job_id}') ```

kiu as consumer

```python import json

from kiu import Kiu

k = Kiu(host='localhost', port=11300) tube_name = 'webhook_results_queue'

while True: k.connect(tube_name) job = k.reserve(timeout=60)

if not job:
    print('No job found')
    continue

try:
    data = json.loads(job.body)
    k.delete(job)
except json.decoder.JSONDecodeError:
    print(f"Error decoding job body. {job.body}")  # I'm not a json
    continue

print(f"Processing job: {data}")

```

Develop

Build

bash export CI_TAG=0.0.1 pip install build installer python update_version.py python -m build

Install

bash pip install dist/kiu-0.0.1-py3-none-any.whl

Links for kiu