Python server SDK for the Fishjam Cloud
Project description
Fishjam Python Server SDK
Python server SDK for the Fishjam Cloud.
Read the docs here
Installation
pip install fishjam-server-sdk
Usage
The SDK exports two main classes for interacting with Fishjam server:
FishjamClient
and FishjamNotifier
.
FishjamClient
wraps http REST api calls, while FishjamNotifier
is responsible for receiving real-time updates from the server.
FishjamClient
Create a FishjamClient
instance, providing the fishjam server address and api token
from fishjam import FishjamClient
fishjam_client = FishjamClient(fishjam_url="localhost:5002", management_token="development")
You can use it to interact with Fishjam Cloud to manage rooms and peers
# Create a room
options = RoomOptions(video_codec="h264", webhook_url="http://localhost:5000/webhook")
room = fishjam_client.create_room(options=options)
# Room(components=[], config=RoomConfig(max_peers=None, video_codec=<RoomConfigVideoCodec.H264: 'h264'>, webhook_url='http://localhost:5000/webhook'), id='1d905478-ccfc-44d6-a6e7-8ccb1b38d955', peers=[])
# Add peer to the room
peer, token = fishjam_client.create_peer(room.id)
# Peer(id='b1232c7e-c969-4450-acdf-ea24f3cdd7f6', status=<PeerStatus.DISCONNECTED: 'disconnected'>, type='webrtc'), 'M8TUGhj-L11KpyG-2zBPIo'
All methods in FishjamClient
may raise one of the exceptions deriving from fishjam.errors.HTTPError
. They are defined in fishjam.errors
.
FishjamNotifier
FishjamNotifier allows for receiving real-time updates from the Fishjam Server.
You can read more about notifications in the Fishjam Docs.
Create FishjamNotifier
instance
from fishjam import FishjamNotifier
fishjam_notifier = FishjamNotifier(fishjam_url='localhost:5002', management_token='development')
Then define a handler for incoming messages
@notifier.on_server_notification
def handle_notification(server_notification):
print(f'Received a notification: {server_notification}')
After that you can start the notifier
async def test_notifier():
notifier_task = asyncio.create_task(fishjam_notifier.connect())
# Wait for notifier to be ready to receive messages
await fishjam_notifier.wait_ready()
# Create a room to trigger a server notification
fishjam_client = FishjamClient()
fishjam_client.create_room()
await notifier_task
asyncio.run(test_notifier())
# Received a notification: ServerMessageRoomCreated(room_id='69a3fd1a-6a4d-47bc-ae54-0c72b0d05e29')
Testing
You can test the SDK by running
poetry run ci_test
In local development you can use
poetry run local_test
Format & Lint
You can format code by running
poetry run format
You can check linter by running
poetry run lint
Documentation
Documentation is generated via openapi-python-client.
To update documentation you need to:
- in
poetry_scripts.py
change branch from which openapi.yaml should be downloaded - run
poetry run update-client
License
Licensed under the Apache License, Version 2.0
Fishjam Cloud is created by Software Mansion
Since 2012 Software Mansion is a software agency with experience in building web and mobile apps. We are Core React Native Contributors and experts in dealing with all kinds of React Native issues. We can help you build your next dream product – Hire us.
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
File details
Details for the file fishjam_server_sdk-0.7.0.tar.gz
.
File metadata
- Download URL: fishjam_server_sdk-0.7.0.tar.gz
- Upload date:
- Size: 35.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e74028c6db6ce0286287c307b5e8abeeea17bda209ee8d8a9829051a036156ba |
|
MD5 | 4f19f3c5070304fa882e637bb1134693 |
|
BLAKE2b-256 | 0ca9f19e56b5ee32f26bf6a984f73ca50cdce9c4585324f59de732794bbaf45d |
File details
Details for the file fishjam_server_sdk-0.7.0-py3-none-any.whl
.
File metadata
- Download URL: fishjam_server_sdk-0.7.0-py3-none-any.whl
- Upload date:
- Size: 92.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.1 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d471984a9da3e176f401695546a8bcb5943ce7195d7ba184fc9228076531750 |
|
MD5 | 925370ec0112172eeb56c6574334047c |
|
BLAKE2b-256 | a383abc081c691d01eace799e7aa360c77979e55fecbd4c474b9eecc955b753d |