All Projects → vitorluis → python-mercure

vitorluis / python-mercure

Licence: BSD-2-Clause license
Python library to publish messages to Mercure Hub!

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to python-mercure

ternary-logic
Support for ternary logic in SSE, XOP, AVX2 and x86 programs
Stars: ✭ 21 (+16.67%)
Mutual labels:  sse
HLML
Auto-generated maths library for C and C++ based on HLSL/Cg
Stars: ✭ 23 (+27.78%)
Mutual labels:  sse
penguinV
Simple and fast C++ image processing library with focus on heterogeneous systems
Stars: ✭ 110 (+511.11%)
Mutual labels:  sse
simd-byte-lookup
SIMDized check which bytes are in a set
Stars: ✭ 23 (+27.78%)
Mutual labels:  sse
redis-subscribe-sse
Stream Redis "SUBSCRIBE" or "PSUBSCRIBE" events to browsers using HTML5 Server-Sent Events (SSE)
Stars: ✭ 45 (+150%)
Mutual labels:  sse
restio
HTTP Client for Dart inspired by OkHttp
Stars: ✭ 46 (+155.56%)
Mutual labels:  sse
Eventsource
A simple Swift client library for the Server Sent Events (SSE)
Stars: ✭ 241 (+1238.89%)
Mutual labels:  sse
SSE-Github
This repository contains the demo app for the blog
Stars: ✭ 17 (-5.56%)
Mutual labels:  sse
go-sse
Fully featured, spec-compliant HTML5 server-sent events library
Stars: ✭ 165 (+816.67%)
Mutual labels:  sse
KaoYan 807
北京邮电大学软件学院考研专业课笔记(2019年)
Stars: ✭ 31 (+72.22%)
Mutual labels:  sse
async-messenger-mercure
Demo for Symfony Messenger + Mercure
Stars: ✭ 27 (+50%)
Mutual labels:  mercure
distfit
distfit is a python library for probability density fitting.
Stars: ✭ 250 (+1288.89%)
Mutual labels:  sse
hpc
Learning and practice of high performance computing (CUDA, Vulkan, OpenCL, OpenMP, TBB, SSE/AVX, NEON, MPI, coroutines, etc. )
Stars: ✭ 39 (+116.67%)
Mutual labels:  sse
mu-server
A lightweight modern webserver for Java
Stars: ✭ 31 (+72.22%)
Mutual labels:  sse
laravel-mercure-broadcaster
Laravel broadcaster for Mercure
Stars: ✭ 73 (+305.56%)
Mutual labels:  mercure
Mipp
MIPP is a portable wrapper for SIMD instructions written in C++11. It supports NEON, SSE, AVX and AVX-512.
Stars: ✭ 253 (+1305.56%)
Mutual labels:  sse
hasses
Hyper's Asynchronous Server Sent event (SSE) notification Server
Stars: ✭ 18 (+0%)
Mutual labels:  sse
sse-avx-rasterization
Triangle rasterization routines accelerated by SSE and AVX
Stars: ✭ 53 (+194.44%)
Mutual labels:  sse
lasse
SSE handler for Cowboy
Stars: ✭ 44 (+144.44%)
Mutual labels:  sse
react-native-sse
Event Source implementation for React Native. Server-Sent Events (SSE) for iOS and Android 🚀
Stars: ✭ 51 (+183.33%)
Mutual labels:  sse

Python Mercure (pymercure)

The goal of this library is to provide a quick way to publish and consume messages on Mercure. If you don't know what Mercure is, take a look here: (https://github.com/dunglas/mercure).

This library is currently under development, so if you find any bug or chance of improvement, please open an issue to us. :)

Installing the library

The library is available on PyPi, so you can install using pip:

 pip3 install pymercure

Publishing Messages

As mentioned before, the goal is to provide a quick way to publish messages. And to do so, it's provided the Sync and Async classes.

Sync publisher

import json
from pymercure.publisher.sync import SyncPublisher
from pymercure.message import Message

data = json.dumps({'status': 'test'})
msg = Message(['mytopicname'], data)
publisher = SyncPublisher(
     'http://127.0.0.1:3000/hub',
     'your.Token.Here'
)
publisher.publish(msg)

Async publisher

import json
from pymercure.publisher.async import AsyncPublisher
from pymercure.message import Message

data = json.dumps({'status': 'test'})
msg = Message(['mytopicname'], data)
publisher = AsyncPublisher(
     'http://127.0.0.1:3000/.well-known/mercure',
     'your.Token.Here'
)
publisher.publish(msg)

In the async case, the request will be done using the gevent library.

Consuming messages

To consume messages it's also pretty straight forward. as the consumer runs in a new thread you don't have to worry about it, you just need to pass a callback function to it:

from pymercure.consumer import Consumer

def callback(message):
    print(message.data)


c = Consumer('http://127.0.0.1:3000/.well-known/mercure', ['mytopicname'], callback)
c.start_consumption()

In your callback you will always receive the Message object, with the message data and metadata.

Credits

Created and maintained by Vitor Villar [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].