Python server SDK for the Jellyfish media server
Project description
Jellyfish Python Server SDK
Python server SDK for the Jellyfish Media Server.
Read the docs here
Installation
You can install the latest version of the package from github:
pip install git+https://github.com/jellyfish-dev/python-server-sdk@v0.1.0
Usage
The SDK exports two main classes for interacting with Jellyfish server:
RoomApi
and Notifier
.
RoomApi
wraps http REST api calls, while Notifier
is responsible for receiving real-time updates from the server.
RoomApi
Create a RoomApi
instance, providing the jellyfish server address and api token
from jellyfish import RoomApi
room_api = RoomApi(server_address='localhost:5002', server_api_token='development')
You can use it to interact with Jellyfish, manage rooms, peers and components
# Create a room
jellyfish_address, room = room_api.create_room(video_codec='h264')
# 'localhost:5002', Room(components=[], config=RoomConfig(max_peers=None, video_codec='h264'), id='5a099a31-0eb2-4c28-84af-a1ec55c228af', peers=[]))
# Add peer to the room
from jellyfish import PeerOptionsWebRTC
peer_token, peer_webrtc = room_api.add_peer(room.id, options=PeerOptionsWebRTC())
# 'AgDYfrCSigFiAA', Peer(id='2869fb5', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc')
# Add component to the room
from jellyfish import ComponentOptionsHLS
component_hls = room_api.add_component(room.id, options=ComponentOptionsHLS())
# Component(actual_instance=ComponentHLS(id='c0dfab50-cafd-438d-985e-7b8f97ae55e3', metadata=ComponentMetadataHLS(low_latency=False, playable=False), type='hls'))
Notifier
Create Notifier
instance
from jellyfish import Notifier
notifier = Notifier(server_address='localhost:5002', server_api_token='development')
Then define handlers for incoming messages
@notifier.on_server_notification
def handle_notification(server_notification):
print(f'Received a notification: {server_notification}')
@notifier.on_metrics
def handle_metrics(metrics_report):
print(f'Received WebRTC metrics: {metrics_report}')
After that you can start the notifier
async def test_notifier():
notifier_task = asyncio.create_task(notifier.connect())
# Wait for notifier to be ready to receive messages
await notifier.wait_ready()
# Create a room to trigger a server notification
room_api = RoomApi()
room_api.create_room()
await notifier_task
asyncio.run(test_notifier())
# Received a notification: ServerMessageRoomCreated(room_id='69a3fd1a-6a4d-47bc-ae54-0c72b0d05e29')
# Received WebRTC metrics: ServerMessageMetricsReport(metrics='{}')
Testing
You can test the SDK against a local instance of Jellyfish by running
pytest
Make sure to use the default configuration for Jellyfish
Alternatively you can test using Docker
docker-compose -f docker-compose-test.yaml run test
Copyright and License
Copyright 2023, Software Mansion
Licensed under the Apache License, Version 2.0
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
Built Distribution
Hashes for jellyfish_server_sdk-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7be0ec6ce307ce017aa8c6930f0f18712dfb72de19be69116b7eef3cdd840f4f |
|
MD5 | c2bf1140b365042797a93fc6b9b84223 |
|
BLAKE2b-256 | b990760b331f6f3fb6448556a1ae9e0c8e8d9bb322fb37dcad701e4bba02fc9a |
Hashes for jellyfish_server_sdk-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fae75101b1ff0cadc8014b40094159854b743c529f280e8fe45df39b1e5d6ff6 |
|
MD5 | f2dc9a349cecf0b09ed89f66558177b3 |
|
BLAKE2b-256 | d77d881610bd0b3a1ad78fb8454edd1100a5efd4a94da74a37b2f8a046584dac |