Skip to main content

Python bindings for the Media over QUIC Rust crates: real-time pub/sub with built-in caching, fan-out, and prioritization.

Project description

moq-rs

Python bindings for the Media over QUIC Rust crates: real-time pub/sub with built-in caching, fan-out, and prioritization, on top of QUIC.

moq-rs wraps the auto-generated moq-ffi UniFFI bindings with a Pythonic API: no Moq prefixes, async iterators, context managers, and simplified connection setup. At session setup it negotiates either the moq-lite or moq-transport wire protocol.

Installation

pip install moq-rs

The distribution is moq-rs; the import name is moq.

Quick Start

Subscribe to a stream

import asyncio
import moq

async def main():
    async with moq.Client("https://relay.quic.video") as client:
        async for announcement in client.announced():
            catalog = await announcement.broadcast.catalog()

            for name in catalog.audio:
                async for frame in announcement.broadcast.subscribe_media(name):
                    print(f"Got frame: {len(frame.payload)} bytes, ts={frame.timestamp_us}")

asyncio.run(main())

Publish a stream

import asyncio
import moq

async def main():
    async with moq.Client("https://relay.quic.video") as client:
        broadcast = moq.BroadcastProducer()

        # Publish an Opus audio track (init bytes from your encoder)
        audio = broadcast.publish_media("opus", opus_init_bytes)
        client.publish("my-stream", broadcast)

        # Write frames
        audio.write_frame(payload, timestamp_us=0)
        audio.write_frame(payload, timestamp_us=20000)

        # Clean up
        audio.finish()
        broadcast.finish()

asyncio.run(main())

Host a server

import asyncio
import moq_lite as moq

async def main():
    async with moq.Server("127.0.0.1:4443", tls_generate=["localhost"]) as server:
        broadcast = moq.BroadcastProducer()
        track = broadcast.publish_track("events")
        server.publish("hello", broadcast)
        print(f"listening on https://{server.local_addr}")

        sessions = []
        async for request in server:
            print(f"  + {request.transport} from {request.url}")
            sessions.append(await request.ok())

asyncio.run(main())

Reject a request instead of accepting it with await request.close(403).

Advanced: Manual origin wiring

For full control over the origin topology:

import moq

origin = moq.OriginProducer()
client = moq.Client(
    "https://relay.quic.video",
    publish=origin,
    subscribe=origin,
)

API

Connection

  • Client(url, *, tls_verify=True, bind=None, publish=None, subscribe=None). Async context manager for connecting to a relay.
  • Server(bind="[::]:443", *, tls_cert=(), tls_key=(), tls_generate=(), publish=None, subscribe=None). Async context manager + async iterator of incoming Requests.
    • .local_addr. The bound address (useful when binding to port 0).
    • .cert_fingerprints(). SHA-256 fingerprints of the configured TLS certificates, for serverCertificateHashes browser cert pinning.
    • .publish(path, broadcast). Publish a broadcast to be served.
  • Request. An incoming session, yielded by async for request in server.
    • .url, .transport. Properties.
    • .set_publish(origin), .set_consume(origin). Per-request overrides.
    • await .ok(). Complete the handshake, returns a session (hold it to keep the connection alive).
    • await .close(code). Reject with an HTTP status code.
    • .cancel(). Cancel an in-flight ok()/close() call.

Publishing

  • BroadcastProducer(). Create a broadcast to publish tracks into.
    • .publish_media(format, init) → MediaProducer
    • .finish()
  • MediaProducer. Write frames to a track.
    • .write_frame(payload, timestamp_us)
    • .finish()

Subscribing

  • BroadcastConsumer. Subscribe to tracks within a broadcast.
    • .subscribe_catalog() → CatalogConsumer
    • .subscribe_media(name, max_latency_ms=10000) → MediaConsumer
    • await .catalog() → Catalog (convenience)
  • CatalogConsumer. Async iterator of Catalog.
  • MediaConsumer. Async iterator of Frame.

Origin (advanced)

  • OriginProducer(). Manage broadcast announcements.
    • .consume() → OriginConsumer
    • .publish(path, broadcast)
  • OriginConsumer. Discover broadcasts.
    • .announced(prefix) → Announced (async iterator)
    • .announced_broadcast(path) → AnnouncedBroadcast (awaitable)

Types

  • Catalog. .audio: dict[str, Audio], .video: dict[str, Video], .display, .rotation, .flip.
  • Frame. .payload: bytes, .timestamp_us: int, .keyframe: bool.
  • Audio. .codec, .sample_rate, .channel_count, .bitrate, .description.
  • Video. .codec, .coded: Dimensions, .display_ratio, .bitrate, .framerate, .description.
  • Dimensions. .width: int, .height: int.

See Also

  • moq-ffi. The Rust crate that produces the UniFFI bindings vendored as moq._uniffi.
  • MoQ project. Full monorepo with Rust server, TypeScript browser lib, and more.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moq_rs-0.2.15.tar.gz (399.8 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

moq_rs-0.2.15-py3-none-win_amd64.whl (5.4 MB view details)

Uploaded Python 3Windows x86-64

moq_rs-0.2.15-py3-none-manylinux_2_28_aarch64.whl (7.1 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

moq_rs-0.2.15-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

moq_rs-0.2.15-py3-none-macosx_11_0_arm64.whl (6.3 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

moq_rs-0.2.15-py3-none-macosx_10_12_x86_64.whl (6.7 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file moq_rs-0.2.15.tar.gz.

File metadata

  • Download URL: moq_rs-0.2.15.tar.gz
  • Upload date:
  • Size: 399.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for moq_rs-0.2.15.tar.gz
Algorithm Hash digest
SHA256 ecee35170b9ba0f123dd360a01f999f0be86ab508e2da8d118e65ba7ae53ed37
MD5 14d98e9b3b16df4cff1f852f59604065
BLAKE2b-256 b010ff7c4b2f8a5bbf0ac1a245b43618f3310b4c7787b2b6c533e3cab7d110a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15.tar.gz:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moq_rs-0.2.15-py3-none-win_amd64.whl.

File metadata

  • Download URL: moq_rs-0.2.15-py3-none-win_amd64.whl
  • Upload date:
  • Size: 5.4 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for moq_rs-0.2.15-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 7698a001f95bef02aa19a1686f0b2d9c938450c5e76d46b47d1294427b84b017
MD5 1353ef149bb1093349ad3897314ee79c
BLAKE2b-256 8bc5ed875392da46eb795264d22839cccd9b9ca0f0f6e7b4132dcc0cfa1ed73b

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15-py3-none-win_amd64.whl:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moq_rs-0.2.15-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for moq_rs-0.2.15-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d2a32e73f098392aada75afeffc003d94453cf197de6c48a868cd63f96278cad
MD5 43a73a4ec19d5ae85c37c4729cbbe2c4
BLAKE2b-256 e3f7e9a711e324cdd0f350067a36face3c6436861da20f7eb272ff958d0d5600

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15-py3-none-manylinux_2_28_aarch64.whl:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moq_rs-0.2.15-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for moq_rs-0.2.15-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05e87638bb63e70538e6b1adfe43f8f00c1a7df4e812e86aeda4d452975dbbb7
MD5 4db4d6d39aa3d0e2eef60543ba685a5c
BLAKE2b-256 c3e7a28449226024e24c2264547618effbc2dccf8066f2cd71dd35af79cac500

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moq_rs-0.2.15-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for moq_rs-0.2.15-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 432c29b540e5d148fa34bd36afbe4bc82c9b7fd2f22a7ae2ac60c2042bd23eec
MD5 5662211455e799e1f9a0e86dc1f8f092
BLAKE2b-256 aacc0541cfb8b8e6c5a348e2076bd27fbec448e90306ab9fddc51b86d18d0dbf

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15-py3-none-macosx_11_0_arm64.whl:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file moq_rs-0.2.15-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for moq_rs-0.2.15-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 74c2014bb0c3593c72e1705113bb2dbedb308b87516bcf769067ce2a7c63741d
MD5 4e4e6d7a30b317974ce9802f0c2623c9
BLAKE2b-256 6f62d567bed01455ad064042c1f160d82d555bef59fccafd894a266ef18b911b

See more details on using hashes here.

Provenance

The following attestation bundles were made for moq_rs-0.2.15-py3-none-macosx_10_12_x86_64.whl:

Publisher: release-py.yml on moq-dev/moq

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page