SDK for Margay Gateway - provide tooling and examples of usage.
Project description
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 Gateway
with RMQ locally part see instruction - Setup Subscriber or use example
examples/vanilla_worker.py
orexamples/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
CustomQueue
and 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
margay-0.2.0.tar.gz
(10.7 kB
view details)
Built Distribution
margay-0.2.0-py3-none-any.whl
(11.0 kB
view details)
File details
Details for the file margay-0.2.0.tar.gz
.
File metadata
- Download URL: margay-0.2.0.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e016767253debbe23928b37e08bc5c651799e731b1efdd8d815a727eba8406ce |
|
MD5 | de049323959c12485adcd3781325cc06 |
|
BLAKE2b-256 | 8583809ab099472a051a7773dff1c7839bb7cd5138c4456a6b10dd6885a0cc57 |
File details
Details for the file margay-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: margay-0.2.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db5f7c057fe62784eb3d5078b4c8113a8a4d9519f85372d468258d7b214d82ab |
|
MD5 | d5510e8b806bc73ad94eb60a11629dd7 |
|
BLAKE2b-256 | 2d6f019e207c1f4562081189eadcc61ab1950dc6c2c17a6c4b7183aaf78ff095 |