Skip to main content

mercure-publisher

PRs Welcome

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.publish claim) from a typed config
  • ⚡ Optional Redis cache for the JWT (checked before minting a new token)
  • 🔁 Sync and async clients, both backed by httpx
  • 🧩 data accepts a dict and serializes it to JSON for you (or pass a str for 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

Metadata

Release files for mercure-publisher 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mercure-publisher 0.1.0
File Size Uploaded Provenance Actions
mercure_publisher-0.1.0.tar.gz 8.3 kB Without provenance Details for mercure_publisher-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mercure-publisher 0.1.0
File Interpreter ABI Platform Actions
mercure_publisher-0.1.0-py3-none-any.whl Python 3 none any Details for mercure_publisher-0.1.0-py3-none-any.whl

Total release size: 16.8 kB

Release files / mercure_publisher-0.1.0.tar.gz

Download URL mercure_publisher-0.1.0.tar.gz
Size 8.3 kB
Tags Source
SHA-256 checksum
How to use checksums
07c8dfd4e3490b2b210a30d270bde8cbc89959a5a8af7032dda0d66e843f9c41
BLAKE2b-256 checksum
How to use checksums
35e0f4595446ae0ca37ee6e3a699ffa7a40ded5b71314f597c03a914d9a41edd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / mercure_publisher-0.1.0-py3-none-any.whl

Download URL mercure_publisher-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f2f0d0c1b88e3d66d7042255bda5499ebd46f62a76dfaf217077440a67d49b7
BLAKE2b-256 checksum
How to use checksums
a1a98874c51b05b0f50851637e86c40ef897e8d226bdc332bc41aac52151b586
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for mercure-publisher 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page