Skip to main content

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

motion-0.1.3.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

motion-0.1.3-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file motion-0.1.3.tar.gz.

File metadata

  • Download URL: motion-0.1.3.tar.gz
  • Upload date:
  • Size: 5.6 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.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for motion-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8293fa2cd89250f87d4101366ec6ee67ce53986b64cfb22f84acbcb2927076d3
MD5 102e39e8d39c2396216e0b36768b4412
BLAKE2b-256 11a92d3211e2852e2ca3932134db1b182d3075801c53ee2011018674fabb3168

See more details on using hashes here.

File details

Details for the file motion-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: motion-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.1

File hashes

Hashes for motion-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5d0eb99daa385fab7882b06eb5ea5d2ebfc8c05eade9f9fa1b525c156d83903e
MD5 4aff479847a11e7753ea175a8991ffea
BLAKE2b-256 955163185210fc4b3e7daf4e3e73dc928d2112bf2a23c443a567fb4e6063fca7

See more details on using hashes here.

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