High-level library for dispatching and responding to tasks via AWS Kinesis
Project description
Motion
Motion is a high-level task dispatch & response framework for Amazon Kinesis. It is built on top of the low-level kinesis-python library and inspired by the task definition of Celery.
Motion is still under heavy development. Things here may change
Usage
Create a Motion
object:
from motion import Motion
tasks = Motion(stream_name='my-kinesis-stream')
Responding to tasks
@tasks.respond_to('my-event')
def my_event_handler(payload):
# do something with payload...
Dispatching tasks
# dispatch an event 'my-event' with the specified payload
tasks.dispatch('my-event', {'foo': 'bar'})
Running workers
Marshalling
Events and Payloads are converted into byte streams suitable for transport on a Kinesis stream via the process of Marshalling. Motion ships with a default JSON Marshalling class that simply converts a Python object into its JSON equivalent, wrapped with the event name, but the Marshalling operations can be extended to support any type of serialization that is desired (i.e. protobuf, avro, etc)
To implement a custom Marshal you must satisfy the following method signature:
class MyMarshal(object):
def to_native(self, payload):
# de-serialize payload
return event_name, event_payload
def to_bytes(self, event_name, payload):
# serialize payload
return serialized_payload
Then pass an instance of your marshalling class when you create your Motion
instance via the marshal=
keyword.
Event names
In the basic example the .respond_to
decorator is used with a string, since that's what the default JSON Marshal
returns, but since custom marshalling can return anything for the event_name during the .to_native
call then you
can use whatever symbol you choose in the .respond_to
decorator.
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
Built Distribution
File details
Details for the file motion-0.1.4.tar.gz
.
File metadata
- Download URL: motion-0.1.4.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa681dfbb92547ed0351a66005384af4024c24bfaf0213de215dcde2f9602f88 |
|
MD5 | 3030392dc38cece9037d52314656e65c |
|
BLAKE2b-256 | f0f4309836cc9264a146d85900815ffdd5c021e4444a963a889ca2ee5f5ac427 |
File details
Details for the file motion-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: motion-0.1.4-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab4af16bd07859c08cfcb67ce4928dd87878b8cf5b0adfef5c6e64b977b212af |
|
MD5 | e905098d6f05926f2dff8e1c140c0189 |
|
BLAKE2b-256 | a623e29256cfa5ccd7bc48df32e1d99fa9f7464a560436d230bcd644ac7ad502 |