Margay Gateway - toolkit
Provide set of tooling for building reliable websocket gateway system. Architecture part described in Margay Gateway core repository
Quickstart
- Install sdk
pip install margay - Deploy
Margay Gatewaywith RMQ locally part see instruction - Setup Subscriber or use example
examples/vanilla_worker.pyorexamples/vanilla_publisher.py - Setup client or use example
examples/vanilla_client.py- You can generate auth token by using cli
- By using sdk auth
- By using external indentety provider
- Connect your backend
- Basically that means:
- You subscribe RMQ topic with your
CustomQueueand listen for events - You are ready to publish new events for your clients
- You subscribe RMQ topic with your
- Basically that means:
- Connect websocket client to
Margay Gateway - That's it now you are ready to send/receive messages trough
Margay Gateway
Configure
You are able to setup sdk for your custom needs
Example of change of default subscriber queue name
from margay.sdk.config import Config
Config.set("queue", "VanillaWorkerQueue")
Subscriber
Example custom subscriber creation
from margay.sdk.subscriber import Subscriber
from margay.sdk.protocol import RawMessage
class JsonMessage(RawMessage):
""" Your message protocol """
class Router:
""" Your event router """
class Handler:
""" Your event handler """
class SimpleWorker(Subscriber):
Message = JsonMessage
resolve = Router.resolve
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def process(self, message: JsonMessage):
self.resolve(message)
Publisher
Example custom publisher creation
from margay.sdk.publisher import Publisher
class Event:
"""Your custom event protocol"""
class EventPublisher(Publisher):
origin = "MyAwsomeMss"
def publish(self, event: Event, recipient: str):
self.publish_raw(event.serialize(), self.origin, recipient)
Auth
JWT
from margay.sdk.auth import JWTAuth
user = "John Snow"
secret = "SuperSecret"
identity_provider = JWTAuth(secret)
token = identity_provider.issue_token(user)
payload = identity_provider.verify_token(token, user)
print(payload)
Debugging
Set debug for SDKLogger
import logging
from margay.sdk.logger import SDKLogger
import sys
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO,
handlers=[logging.StreamHandler(sys.stdout)]
)
SDKLogger.setLevel(logging.DEBUG)
Metadata
Release files for margay 0.2.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 |
|---|---|---|---|---|
| margay-0.2.0.tar.gz | 10.7 kB | Without provenance | Details for margay-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| margay-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for margay-0.2.0-py3-none-any.whl |
Total release size: 21.7 kB
Release files / margay-0.2.0.tar.gz
| Download URL | margay-0.2.0.tar.gz |
|---|---|
| Size | 10.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e016767253debbe23928b37e08bc5c651799e731b1efdd8d815a727eba8406ce
|
|
BLAKE2b-256 checksum How to use checksums |
8583809ab099472a051a7773dff1c7839bb7cd5138c4456a6b10dd6885a0cc57
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.10
|
Release files / margay-0.2.0-py3-none-any.whl
| Download URL | margay-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db5f7c057fe62784eb3d5078b4c8113a8a4d9519f85372d468258d7b214d82ab
|
|
BLAKE2b-256 checksum How to use checksums |
2d6f019e207c1f4562081189eadcc61ab1950dc6c2c17a6c4b7183aaf78ff095
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.10
|
Security for margay 0.2.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.