Skip to main content

Janus WebRTC gateway Python async client.

Project description

Python Janus Client

Janus WebRTC gateway Python async client.

PyPI - License PyPI - Status PyPI - Downloads Code Coverage


Install

pip install janus-client

Requires Python >=3.8 <3.14


Description

Easily send and share WebRTC media through Janus WebRTC server.

This client is using aiortc for WebRTC communication and subsequently PyAV for media stack.

✅ Features ✅

  • Connect to Janus server using:
    • Websocket
    • HTTP
  • Authentication with shared static secret (API key) and/or stored token
  • Support Admin/Monitor API:
    • Generic requests
    • Configuration related requests
    • Token related requests
  • Support Janus plugins:
  • Simple interface
  • Minimum dependency
  • Extendable Janus transport

Examples

Simple Connect And Disconnect

import asyncio
from janus_client import JanusSession, JanusEchoTestPlugin, JanusVideoRoomPlugin

# Protocol will be derived from base_url
base_url = "wss://janusmy.josephgetmyip.com/janusbasews/janus"
# OR
base_url = "https://janusmy.josephgetmyip.com/janusbase/janus"

session = JanusSession(base_url=base_url)

plugin_handle = JanusEchoTestPlugin()

# Attach to Janus session
await plugin_handle.attach(session=session)

# Destroy plugin handle
await plugin_handle.destroy()

This will create a plugin handle and then destroy it.

Notice that we don't need to call connect or disconnect explicitly. It's managed internally.

Make Video Calls

import asyncio
from janus_client import JanusSession, JanusVideoCallPlugin
from aiortc.contrib.media import MediaPlayer, MediaRecorder

async def main():
    # Create session
    session = JanusSession(
        base_url="wss://janusmy.josephgetmyip.com/janusbasews/janus",
    )

    # Create plugin
    plugin_handle = JanusVideoCallPlugin()

    # Attach to Janus session
    await plugin_handle.attach(session=session)

    # Prepare username and media stream
    username = "testusernamein"
    username_out = "testusernameout"

    player = MediaPlayer(
        "desktop",
        format="gdigrab",
        options={
            "video_size": "640x480",
            "framerate": "30",
            "offset_x": "20",
            "offset_y": "30",
        },
    )
    recorder = MediaRecorder("./videocall_record_out.mp4")

    # Register myself as testusernameout
    result = await plugin_handle.register(username=username_out)

    # Call testusernamein
    result = await plugin_handle.call(
        username=username, player=player, recorder=recorder
    )

    # Wait awhile then hangup
    await asyncio.sleep(30)

    result = await plugin_handle.hangup()

    # Destroy plugin
    await plugin_handle.destroy()

    # Destroy session
    await session.destroy()


if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

This example will register to the VideoCall plugin using username testusernameout. It will then call the user registered using the username testusernamein.

A portion of the screen will be captured and sent in the call media stream. The incoming media stream will be saved into videocall_record_out.mp4 file.

Documentation

The project documentation is built with Material for MkDocs and deployed to GitHub Pages.

Documentation Development

Setup

Install development dependencies:

hatch env create

Local Development

To serve the documentation locally with live reload:

hatch run docs-serve

The documentation will be available at http://127.0.0.1:8000/

Building Documentation

To build the documentation for production:

hatch run docs-build

The built documentation will be in the site/ directory.

Important: The documentation build uses the --strict flag to catch warnings as errors. This ensures documentation quality and prevents deployment of documentation with issues.

For local development without strict mode:

hatch run mkdocs build
hatch run +py=3.8 mkdocs build  # to build in a specific python environment only, not all

Documentation Structure

  • docs/index.md - Main documentation page
  • docs/session.md - Session API documentation
  • docs/plugins.md - Plugin API documentation
  • docs/transport.md - Transport API documentation
  • mkdocs.yml - MkDocs configuration file

Experiments

FFmpeg support for VideoRoom plugin has now been moved to experiments folder, together with GStreamer support.

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

janus_client-0.8.0.tar.gz (77.5 kB view details)

Uploaded Source

Built Distribution

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

janus_client-0.8.0-py3-none-any.whl (47.5 kB view details)

Uploaded Python 3

File details

Details for the file janus_client-0.8.0.tar.gz.

File metadata

  • Download URL: janus_client-0.8.0.tar.gz
  • Upload date:
  • Size: 77.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for janus_client-0.8.0.tar.gz
Algorithm Hash digest
SHA256 11beaf434ab11392423574be7dd9c7b58f07413b8a2c1246ab6805dc14c119d9
MD5 95e1d61a031efba10836828c11c568e5
BLAKE2b-256 9899e6f38a35bcb6831df8453c3a21bdbb9db56a9f2c06344c4e07906584be52

See more details on using hashes here.

File details

Details for the file janus_client-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: janus_client-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 47.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.28.1

File hashes

Hashes for janus_client-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9e6e1addb4fb5a9ab09258c969b183c2950d147207574c824e07c9b45a8b509
MD5 63606223a61155fdd41a6aee9308cd72
BLAKE2b-256 f37985ca26bcd528637cf533d91742a0d5bf4a1e188c96023eb2ff867edd4e11

See more details on using hashes here.

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