Typed Python client to publish updates to a Mercure Hub, with Redis-backed JWT caching support
Project description
mercure-publisher
mercure-publisher is a typed Python client to publish updates to a Mercure Hub, with Redis-backed caching of the generated publisher JWT so it isn't re-created on every publish call.
Features:
- 🔐 Builds the publisher JWT (
mercure.publishclaim) from a typed config - ⚡ Optional Redis cache for the JWT (checked before minting a new token)
- 🔁 Sync and async clients, both backed by
httpx - 🧩
dataaccepts adictand serializes it to JSON for you (or pass astrfor a raw payload) - 📦 Fully typed with dataclasses and type hints
Installation
pip install mercure-publisher
Requires a reachable Redis instance (used to cache the publisher JWT); pass
redis_config=None to disable caching without removing the dependency.
Usage
Configure
from mercure_publisher import MercureConfig, RedisConfig
config = MercureConfig(
hub_url="https://hub.example.com/.well-known/mercure",
publisher_jwt_key="!ChangeThisMercureHubJWTSecretKey!",
publish_topics=["https://example.com/books/{id}"], # or ["*"] for any topic
jwt_ttl_seconds=3600,
redis_config=RedisConfig(
host="localhost",
port=6379,
key_prefix="mercure_publisher:",
),
)
redis_config=None (the default) disables token caching — a new JWT is
generated on every publish.
Publish (sync)
from mercure_publisher import MercurePublisher
with MercurePublisher(config) as publisher:
event_id = publisher.publish(
topic="https://example.com/books/1",
data={"status": "published"},
)
Publish (async)
from mercure_publisher import AsyncMercurePublisher
async with AsyncMercurePublisher(config) as publisher:
event_id = await publisher.publish(
topic="https://example.com/books/1",
data={"status": "published"},
)
Publishing to multiple topics / private updates
publisher.publish(
topic=["https://example.com/books/1", "https://example.com/authors/1"],
data='{"status": "published"}',
private=True,
id="event-123",
type="book.updated",
retry=1000,
)
License
MIT © Not Empty
Not Empty Foundation - Free codes, full minds
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mercure_publisher-0.1.0.tar.gz.
File metadata
- Download URL: mercure_publisher-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07c8dfd4e3490b2b210a30d270bde8cbc89959a5a8af7032dda0d66e843f9c41
|
|
| MD5 |
2faefdc54c9da791ef50c64ccbe26acd
|
|
| BLAKE2b-256 |
35e0f4595446ae0ca37ee6e3a699ffa7a40ded5b71314f597c03a914d9a41edd
|
File details
Details for the file mercure_publisher-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mercure_publisher-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f2f0d0c1b88e3d66d7042255bda5499ebd46f62a76dfaf217077440a67d49b7
|
|
| MD5 |
10d8c43e5832f25f00b173cfc9d594ca
|
|
| BLAKE2b-256 |
a1a98874c51b05b0f50851637e86c40ef897e8d226bdc332bc41aac52151b586
|