Morp
Simple message processing without really thinking about it. Morp can use dropfiles (simple text files), Postgres, and Amazon SQS.
Installation
Use pip to install the latest stable version:
pip install morp
Morp only supports the dropfiles interface out of the box, you'll need to install certain dependencies depending on what interface you want to use:
pip install morp[sqs]
pip install morp[postgres]
To install the development version:
pip install -U "git+https://github.com/Jaymon/morp#egg=morp"
1 Minute Getting Started
Send and receive a Foo message.
First, let's set our environment variable to use dropfiles (local files suitable for development and prototyping) interface:
export MORP_DSN=dropfile:${TMPDIR}
Then, let's create three files in our working directory:
tasks.py- We'll define ourMessageclasses here.send.py- We'll send messages from this script.recv.py- We'll receive messages from this script.
Let's create our Message class in tasks.py:
# tasks.py
from morp import Message
class Foo(Message):
some_field: int
some_other_field: str
def handle(self):
# this will be run when a Foo message is consumed
print(self.fields)
Now, let's flesh out our recv.py file:
# recv.py
import asyncio
# import our Foo message class from our tasks.py file
from tasks import Foo
# Foo's `process` method will call `Foo.handle` for each Foo instance received
asyncio.run(Foo.process())
And start it up:
$ python recv.py
Finally, let's send some messages by fleshing out send.py:
# send.py
import asyncio
from tasks import Foo
async def send_messages():
# create a message and send it manually
f = Foo()
f.some_field = 1
f.some_other_field = "one"
f.ignored_field = True
await f.send()
# quickly send a message
await Foo.create(
some_field=2,
some_other_field="two",
)
asyncio.run(send_messages())
And running it in a separate shell from the shell running our recv.py script (it should send two messages):
$ python send.py
That's it! Our running recv.py script should've received the messages we sent when we ran our send.py script.
DSN
You configure your connection using a dsn in the form:
InterfaceName://username:password@host:port/path?param1=value1¶m2=value2
So, to connect to Amazon SQS, you would do:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@
You can also override some default values like region and read_lock:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@?region=${AWS_DEFAULT_REGION}&read_lock=120
Serializers
pickle(default)json
MORP_DSN="sqs://x:x@?serializer=json"
Encryption
You might need to install some dependencies:
pip install morp[encryption]
If you would like to encrypt all your messages, you can pass in a key argument to your DSN and Morp will take care of encrypting and decrypting the messages for you transparently.
Let's just modify our DSN to pass in our key:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@?key=jy4XWRuEsrH98RD2VeLG62uVLCPWpdUh
That's it, every message will now be encrypted on send and decrypted on receive. If you're using SQS you can also use Amazon's key management service to handle the encryption for you.
Environment configuration
MORP_DISABLED
By default every message will be sent, if you just want to test functionality without actually sending the message you can set this environment variable to turn off all the queues.
MORP_DISABLED = 1 # queue is off
MORP_DISABLED = 0 # queue is on
MORP_PREFIX
If you would like to have your queue names prefixed with something (eg, prod or dev) then you can set this environment variable and it will be prefixed to the queue name.
MORP_DSN
Set this environment variable with your connection DSN so Morp can automatically configure itself when the interface is first requested.
FAQ
I would like to have multiple queues
By default, Morp will send any message from any morp.Message derived class to Message.get_name(), you can override this behavior by giving your child class a ._name property:
from morp import Message
class childMsg(Message):
_name = "custom-queue-name"
Metadata
Release files for morp 7.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| morp-7.0.0.tar.gz | 23.4 kB | Without provenance | Details for morp-7.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| morp-7.0.0-py3-none-any.whl | Python 3 | none | any | Details for morp-7.0.0-py3-none-any.whl |
Total release size: 48.1 kB
Release files / morp-7.0.0.tar.gz
| Download URL | morp-7.0.0.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4d2069243cde5b1de9ebee9fda5aba0bec0a99af988da35774e2d8391f8328a
|
|
BLAKE2b-256 checksum How to use checksums |
b0383624e593d5b709289f4120b0fcd41ad3c8d2f8acc2dfc5eca9709056d635
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / morp-7.0.0-py3-none-any.whl
| Download URL | morp-7.0.0-py3-none-any.whl |
|---|---|
| Size | 24.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a6a2ebb4eaa21682799815281202cf832db900ba0dac811613a2583ab3b4bece
|
|
BLAKE2b-256 checksum How to use checksums |
27cffc40dff347d046a4cba9fe45b5727c77e87edd5a0b0ce11f8ac9d1647014
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Security for morp 7.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.