metered-realtime
Async Python SDK for the Metered Realtime Messaging service. The Python counterpart to the JavaScript SDK — a Python peer can share a room with browser peers.
Built for server-side and edge use cases the browser can't reach: AI voice agents that join a room to run STT→LLM→TTS, IoT camera/telemetry bridges, recording bots, and headless automation.
Building with AI? Point Claude Code, Cursor, or Copilot at the SDK reference file —
llms-realtime-messaging-python-sdk.txt— and describe what you want to build. More prompts: Build with AI.
Install
pip install metered-realtime # pub/sub only (SignallingClient)
pip install "metered-realtime[webrtc]" # + the WebRTC peer layer (MeteredPeer)
Requires Python 3.10+.
Quick start — rooms with WebRTC (MeteredPeer)
import asyncio
from metered_realtime import MeteredPeer, PeerJoined, Data, Track
async def main() -> None:
async with MeteredPeer(api_key="pk_live_...") as peer:
@peer.on(PeerJoined)
def _(ev: PeerJoined) -> None:
print("peer joined:", ev.peer.id)
@ev.peer.on(Track)
def _(t: Track) -> None:
print("receiving", t.track.kind, "stream:", [s.id for s in t.streams])
@peer.on(Data)
def _(ev: Data) -> None:
print(ev.sender_peer_id, "says", ev.data)
await peer.join("room-42")
await peer.send({"hello": True}) # broadcast to the room
# Attach media to every peer (current + future). add_track takes a track;
# add_stream takes a MediaStream grouping. Any aiortc track works, e.g.:
# from aiortc.contrib.media import MediaPlayer
# peer.add_track(MediaPlayer("clip.mp3").audio)
await asyncio.sleep(30)
asyncio.run(main())
Quick start — pub/sub only (SignallingClient)
import asyncio
from metered_realtime import SignallingClient, Message
async def main() -> None:
async with SignallingClient(api_key="pk_live_...") as client:
@client.on(Message)
def _(ev: Message) -> None:
print(ev.sender_peer_id, ev.data)
await client.subscribe("room-42")
await client.publish("room-42", {"hello": True})
await asyncio.sleep(5)
asyncio.run(main())
Media input
Pass any aiortc-compatible track to add_track, or use the built-in helpers
(metered-realtime[webrtc]):
from metered_realtime import AudioSource, from_file, from_rtsp, iter_frames
# Push synthesized audio (e.g. an AI agent's speech) into the room:
source = AudioSource(input_rate=16_000) # 16 kHz mono PCM in
peer.add_track(source)
await source.push(pcm_bytes) # emitted as real-time 48 kHz audio
source.end()
# Or feed from a file / IP camera (.audio / .video is None if the source lacks it):
peer.add_track(from_file("clip.mp4").audio)
peer.add_track(from_rtsp("rtsp://cam:554/stream").video)
# Consume a peer's incoming media (e.g. for speech-to-text):
async for frame in iter_frames(track): # ends cleanly when the track stops
...
from_camera / from_microphone / screen_share capture from local devices
(platform-dependent). See the
documentation for auth (publishable keys vs.
token providers), presence, direct messages, media, and data channels.
Provisional: the media-input helpers (
AudioSource,iter_frames,from_file/from_rtsp/from_camera/from_microphone/screen_share) may change in a minor release. The core media API onMeteredPeer—add_stream/add_track/replace_track, andMediaStream— is stable.
Documentation
Full Python SDK docs: metered.ca/docs/realtime-messaging/sdk-python
- Getting started — install, auth, your first peer
- API reference —
MeteredPeer,RemotePeer,DataChannel, media, every event/error/code - Guides — authentication, reconnect best-practices, AI agent communication, IoT telemetry
- Errors & codes — close codes, exception types, how to react
Examples
Runnable end-to-end demos, each walked through in the examples docs (each takes METERED_KEY=pk_live_…):
data_channel_echo.py— open a peer-to-peer data channel and echo messages.audio_agent.py— stream synthesized audio into a room and consume a peer's audio (the "agent in the call" shape).
License
MIT — see LICENSE.
Metadata
Release files for metered-realtime 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| metered_realtime-1.0.2.tar.gz | 69.6 kB | Without provenance | Details for metered_realtime-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| metered_realtime-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for metered_realtime-1.0.2-py3-none-any.whl |
Total release size: 149.6 kB
Release files / metered_realtime-1.0.2.tar.gz
| Download URL | metered_realtime-1.0.2.tar.gz |
|---|---|
| Size | 69.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f667ff3ed17a0c8eecd33b27fe741af8b0f3ed806c9679eee83273c95498a96
|
|
BLAKE2b-256 checksum How to use checksums |
1ea3c3c318cdefd351aba50661bc99c6150d0c1a8e7472bc79a14d3b3e67691f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / metered_realtime-1.0.2-py3-none-any.whl
| Download URL | metered_realtime-1.0.2-py3-none-any.whl |
|---|---|
| Size | 80.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f319c5c9ebc2e57c9989902a5dc98a43f66a9267db7861fdd8872525d6a0d534
|
|
BLAKE2b-256 checksum How to use checksums |
af48e7682596411318a6c8c6172043578d8ab241fb2d13f447052ddcb703ed8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for metered-realtime 1.0.2
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.