Async Python toolkit for the Janus WebRTC Gateway, with typed protocol bindings, plugin abstractions, and production-ready ASGI service tooling.
Project description
janus-api
Async Python bindings and service tooling for the Janus WebRTC Gateway.
This repository now provides two things in one package:
- A core async Janus client (sessions, transport, typed requests/responses, plugin abstraction).
- A production-oriented ASGI service layer (manager/readiness APIs, admin monitoring, logs streaming, optional Kafka + Timescale integrations).
Package Metadata
- Name:
janus-api - Version:
2.0.0 - Python:
>=3.14 - Author:
Leydotpy <leydotpy.dev@gmail.com>
Core Capabilities
- Async Janus session lifecycle over WebSocket (
create,keepalive,destroy) - Typed protocol models with Pydantic
- Plugin runtime + registry with cached plugin handles
- Built-in plugin implementations:
publisher/subscriber(VideoRoom)audiobridgestreamingtextroomsippeer_to_peer(videocall)
- Event handling through callback and ReactiveX patterns
- ASGI app factory with lifespan orchestration
- Optional leader/follower coordination using Redis for multi-worker deployments
- Optional admin monitor + metrics persistence (Timescale/Postgres)
- Optional Janus EventHandler ingestion to Kafka
- REST and WebSocket endpoints for logs and operational status
Installation
# uv (recommended)
uv add janus-api
# pip
pip install janus-api
For local development in this repo:
uv sync
Quick Start (Client Runtime)
import asyncio
from janus_api.conf import Janus
from janus_api.servers import JanusSessionManager
from janus_api.lib import Plugin
async def main():
manager = JanusSessionManager()
Janus.set_manager(manager)
await manager.start()
try:
session = Janus.get_session()
publisher = await Plugin(
identifier="publisher",
session=session,
room="1234",
username="alice",
).attach()
# Example operation
await publisher.join()
await publisher.detach()
finally:
await manager.stop()
asyncio.run(main())
Quick Start (ASGI App)
from janus_api.servers import create_asgi_app
app = create_asgi_app(
debug=False,
routes=[],
mount_rest_api=True,
)
Run with:
uvicorn my_module:app --host 0.0.0.0 --port 8000
By default, internal Janus REST apps are mounted under /janus when MOUNT_REST_API=1.
VideoRoom Example
from janus_api.lib import Plugin
from janus_api.models.videoroom import SubscriberStreams
# Publisher
publisher = await Plugin(
identifier="publisher",
session=session,
room="1234",
username="alice",
).attach()
resp = await publisher.join_and_configure(
sdp="<offer-sdp>",
sdp_type="offer",
audio=True,
video=True,
)
# Subscriber
subscriber = await Plugin(
identifier="subscriber",
session=session,
room="1234",
username="bob",
).attach()
await subscriber.join(streams=[SubscriberStreams(feed="123456")])
await subscriber.watch(sdp="<answer-sdp>", sdp_type="answer")
REST Surface (when mounted)
Base prefix: /janus
/manager:GET /health detailsGET /readyreadiness check
/events:POST /janus-events(HTTP Basic auth, forwards events to Kafka)
/logs:GET /paginated logsGET /levelsGET /{idx}WS /ws/logs
/admin(if enabled):- Janus admin/monitor APIs and realtime websocket monitor
Configuration
Settings are loaded from janus_api.conf.settings and can be overridden by env vars.
Important variables:
JANUS_SESSION_URL(default:ws://localhost:8188/janus)LEADER_MODE(true/false, default enabled in local settings)REDIS_URL(leader election backend)JANUS_SESSION_LEADER_PROXY_HOSTJANUS_SESSION_LEADER_PROXY_PORTMOUNT_REST_APIMOUNT_LOGGING_APPJANUS_ENABLE_ADMINJANUS_ADMIN_URLJANUS_ADMIN_WS_URLJANUS_ADMIN_SECRETJANUS_ADMIN_API_KEYTIMESCALE_DSNJANUS_ENABLE_EVENTSKAFKA_BOOTSTRAPKAFKA_EVENT_HANDLER_TOPICEVENT_HANDLER_USEREVENT_HANDLER_PASS
Runtime Dependencies
From pyproject.toml:
websockets,aiohttp,httpxpydantic,pyee,reactivexasgiref,jinja2redis,aiokafkaasyncpg,psycopg[binary,pool]python-decouple
Project Layout
src/janus_api/
api/rest/ # FastAPI apps (manager, events, logs, admin)
conf/ # Global settings + runtime Janus accessor
contrib/admin/ # Janus admin monitor + storage integrations
core/ # Managers, logging, exceptions, utilities
lib/ # Plugin runtime, loader, registry, event bus
models/ # Typed Janus request/response payloads
servers/ # Session manager, proxy, ASGI app/lifespan
session/ # Session abstractions and websocket implementation
transport/ # Transport layer
Known Gaps
- Some plugin classes are scaffolds or partial implementations (
p2p, parts oftextroom/sip). - Public API exports at package root are intentionally minimal; most imports are from submodules.
- Current test assets include exploratory scripts; a formal automated test matrix is still limited.
Roadmap / TODO (Future Builds)
- Stabilize and document a single public import surface at
janus_apiroot. - Complete unimplemented plugin methods (especially P2P/TextRoom/SIP).
- Add HTTP transport mode alongside WebSocket transport.
- Provide first-class pytest suite with CI (unit, integration, failure-mode tests).
- Add typed examples for FastAPI, Django, and worker-style deployments.
- Harden leader election/proxy behavior with stronger distributed guarantees.
- Add OpenTelemetry tracing and richer metrics endpoints.
- Publish versioned API docs (MkDocs or Sphinx) with generated model references.
- Remove accidental runtime artifacts from source tree (
__pycache__, logs) during packaging.
Contributing
Contributions are welcome. Prioritize:
- clear reproduction steps for bug reports
- tests for behavior changes
- backward-compatibility notes for API changes
License
MIT
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 janus_api-2.0.2.tar.gz.
File metadata
- Download URL: janus_api-2.0.2.tar.gz
- Upload date:
- Size: 103.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d44c0fdb0e40bb9c1b4b9a12751f29f3c035c60470563bc6ab1600486fef0512
|
|
| MD5 |
c23c1b7a61c4c0dd3877409ea4b83cdd
|
|
| BLAKE2b-256 |
6576c9a1d99c4a2b75d136b16757d341b8d5ffb6a82da14ae84177e819fd5b59
|
File details
Details for the file janus_api-2.0.2-py3-none-any.whl.
File metadata
- Download URL: janus_api-2.0.2-py3-none-any.whl
- Upload date:
- Size: 127.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6f90375c28b692771919196ed0aa52b037700edda784291f39707fe63049705
|
|
| MD5 |
ed3e5f8616962c49683067aab66b421d
|
|
| BLAKE2b-256 |
c4850ec59443f77c35815a8f8a3eacb19b4e034d48d51c7be66109728715b60a
|