The Livepeer Python library provides convenient access to the Livepeer Studio API from applications written in Python
For full documentation and examples, please visit docs.livepeer.org.
pip install git+https://github.com/livepeer/livepeer-python.git
import livepeer
from livepeer.models import components
s = livepeer.Livepeer(
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
req = components.NewStreamPayload(
name='test_stream',
)
res = s.stream.create(req)
if res.stream is not None:
# handle response
pass
- create - Create a stream
- get_all - Retrieve streams
- get - Retrieve a stream
- update - Update a stream
- delete - Delete a stream
- terminate - Terminates a live stream
- start_pull - Start ingest for a pull stream
- create_clip - Create a clip
- get_clips - Retrieve clips of a livestream
- add_multistream_target - Add a multistream target
- remove_multistream_target - Remove a multistream target
- get_all - Retrieve Multistream Targets
- create - Create a multistream target
- get - Retrieve a multistream target
- update - Update Multistream Target
- delete - Delete a multistream target
- get_all - Retrieve a Webhook
- create - Create a webhook
- get - Retrieve a webhook
- update - Update a webhook
- delete - Delete a webhook
- get_logs - Retrieve webhook logs
- get_log - Retrieve a webhook log
- resend_log - Resend a webhook
- get_all - Retrieve assets
- create - Upload an asset
- create_via_url - Upload asset via URL
- get - Retrieves an asset
- update - Patch an asset
- delete - Delete an asset
- get_clips - Retrieve clips of a session
- get_all - Retrieve sessions
- get - Retrieve a session
- get_recorded - Retrieve Recorded Sessions
create- Create a room⚠️ Deprecatedget- Retrieve a room⚠️ Deprecateddelete- Delete a room⚠️ Deprecatedstart_egress- Start room RTMP egress⚠️ Deprecatedstop_egress- Stop room RTMP egress⚠️ Deprecatedcreate_user- Create a room user⚠️ Deprecatedget_user- Get user details⚠️ Deprecatedupdate_user- Update a room user⚠️ Deprecateddelete_user- Remove a user from the room⚠️ Deprecated
- get_viewership - Query viewership metrics
- get_creator_viewership - Query creator viewership metrics
- get_public_viewership - Query public total views metrics
- get_usage - Query usage metrics
- create - Create a signing key
- get_all - Retrieves signing keys
- delete - Delete Signing Key
- get - Retrieves a signing key
- update - Update a signing key
- create - Transcode a video
- get - Retrieve Playback Info
Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type.
Error Object | Status Code | Content Type |
---|---|---|
errors.Error | 404 | application/json |
errors.SDKError | 4xx-5xx | / |
import livepeer
from livepeer.models import errors
s = livepeer.Livepeer(
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
res = None
try:
res = s.playback.get(id='<value>')
except errors.Error as e:
# handle exception
raise(e)
except errors.SDKError as e:
# handle exception
raise(e)
if res.playback_info is not None:
# handle response
pass
You can override the default server globally by passing a server index to the server_idx: int
optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the indexes associated with the available servers:
# | Server | Variables |
---|---|---|
0 | https://livepeer.studio/api |
None |
import livepeer
from livepeer.models import components
s = livepeer.Livepeer(
server_idx=0,
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.stream.create(request=components.NewStreamPayload(
name='test_stream',
pull=components.Pull(
source='https://myservice.com/live/stream.flv',
headers={
'Authorization': 'Bearer 123',
},
location=components.Location(
lat=39.739,
lon=-104.988,
),
),
playback_policy=components.PlaybackPolicy(
type=components.Type.WEBHOOK,
webhook_id='1bde4o2i6xycudoy',
webhook_context={
'streamerId': 'my-custom-id',
},
refresh_interval=600,
),
profiles=[
components.FfmpegProfile(
width=1280,
name='720p',
height=486589,
bitrate=3000000,
fps=30,
fps_den=1,
quality=23,
gop='2',
profile=components.Profile.H264_BASELINE,
),
],
record=False,
recording_spec=components.NewStreamPayloadRecordingSpec(
profiles=[
components.TranscodeProfile(
bitrate=3000000,
width=1280,
name='720p',
quality=23,
fps=30,
fps_den=1,
gop='2',
profile=components.TranscodeProfileProfile.H264_BASELINE,
encoder=components.TranscodeProfileEncoder.H_264,
),
],
),
multistream=components.Multistream(
targets=[
components.Target(
profile='720p',
video_only=False,
id='PUSH123',
spec=components.TargetSpec(
url='rtmps:https://live.my-service.tv/channel/secretKey',
name='My target',
),
),
],
),
))
if res.stream is not None:
# handle response
pass
The default server can also be overridden globally by passing a URL to the server_url: str
optional parameter when initializing the SDK client instance. For example:
import livepeer
from livepeer.models import components
s = livepeer.Livepeer(
server_url="https://livepeer.studio/api",
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.stream.create(request=components.NewStreamPayload(
name='test_stream',
pull=components.Pull(
source='https://myservice.com/live/stream.flv',
headers={
'Authorization': 'Bearer 123',
},
location=components.Location(
lat=39.739,
lon=-104.988,
),
),
playback_policy=components.PlaybackPolicy(
type=components.Type.WEBHOOK,
webhook_id='1bde4o2i6xycudoy',
webhook_context={
'streamerId': 'my-custom-id',
},
refresh_interval=600,
),
profiles=[
components.FfmpegProfile(
width=1280,
name='720p',
height=486589,
bitrate=3000000,
fps=30,
fps_den=1,
quality=23,
gop='2',
profile=components.Profile.H264_BASELINE,
),
],
record=False,
recording_spec=components.NewStreamPayloadRecordingSpec(
profiles=[
components.TranscodeProfile(
bitrate=3000000,
width=1280,
name='720p',
quality=23,
fps=30,
fps_den=1,
gop='2',
profile=components.TranscodeProfileProfile.H264_BASELINE,
encoder=components.TranscodeProfileEncoder.H_264,
),
],
),
multistream=components.Multistream(
targets=[
components.Target(
profile='720p',
video_only=False,
id='PUSH123',
spec=components.TargetSpec(
url='rtmps:https://live.my-service.tv/channel/secretKey',
name='My target',
),
),
],
),
))
if res.stream is not None:
# handle response
pass
The Python SDK makes API calls using the requests HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with a custom requests.Session
object.
For example, you could specify a header for every request that this sdk makes as follows:
import livepeer
import requests
http_client = requests.Session()
http_client.headers.update({'x-custom-header': 'someValue'})
s = livepeer.Livepeer(client=http_client)
This SDK supports the following security scheme globally:
Name | Type | Scheme |
---|---|---|
api_key |
http | HTTP Bearer |
To authenticate with the API the api_key
parameter must be set when initializing the SDK client instance. For example:
import livepeer
from livepeer.models import components
s = livepeer.Livepeer(
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.stream.create(request=components.NewStreamPayload(
name='test_stream',
pull=components.Pull(
source='https://myservice.com/live/stream.flv',
headers={
'Authorization': 'Bearer 123',
},
location=components.Location(
lat=39.739,
lon=-104.988,
),
),
playback_policy=components.PlaybackPolicy(
type=components.Type.WEBHOOK,
webhook_id='1bde4o2i6xycudoy',
webhook_context={
'streamerId': 'my-custom-id',
},
refresh_interval=600,
),
profiles=[
components.FfmpegProfile(
width=1280,
name='720p',
height=486589,
bitrate=3000000,
fps=30,
fps_den=1,
quality=23,
gop='2',
profile=components.Profile.H264_BASELINE,
),
],
record=False,
recording_spec=components.NewStreamPayloadRecordingSpec(
profiles=[
components.TranscodeProfile(
bitrate=3000000,
width=1280,
name='720p',
quality=23,
fps=30,
fps_den=1,
gop='2',
profile=components.TranscodeProfileProfile.H264_BASELINE,
encoder=components.TranscodeProfileEncoder.H_264,
),
],
),
multistream=components.Multistream(
targets=[
components.Target(
profile='720p',
video_only=False,
id='PUSH123',
spec=components.TargetSpec(
url='rtmps:https://live.my-service.tv/channel/secretKey',
name='My target',
),
),
],
),
))
if res.stream is not None:
# handle response
pass
pip install git+https://github.com/livepeer/livepeer-python.git
import livepeer
from livepeer.models import components
s = livepeer.Livepeer(
api_key="<YOUR_BEARER_TOKEN_HERE>",
)
res = s.stream.create(request=components.NewStreamPayload(
name='test_stream',
pull=components.Pull(
source='https://myservice.com/live/stream.flv',
headers={
'Authorization': 'Bearer 123',
},
location=components.Location(
lat=39.739,
lon=-104.988,
),
),
playback_policy=components.PlaybackPolicy(
type=components.Type.WEBHOOK,
webhook_id='1bde4o2i6xycudoy',
webhook_context={
'streamerId': 'my-custom-id',
},
refresh_interval=600,
),
profiles=[
components.FfmpegProfile(
width=1280,
name='720p',
height=486589,
bitrate=3000000,
fps=30,
fps_den=1,
quality=23,
gop='2',
profile=components.Profile.H264_BASELINE,
),
],
record=False,
recording_spec=components.NewStreamPayloadRecordingSpec(
profiles=[
components.TranscodeProfile(
bitrate=3000000,
width=1280,
name='720p',
quality=23,
fps=30,
fps_den=1,
gop='2',
profile=components.TranscodeProfileProfile.H264_BASELINE,
encoder=components.TranscodeProfileEncoder.H_264,
),
],
),
multistream=components.Multistream(
targets=[
components.Target(
profile='720p',
video_only=False,
id='PUSH123',
spec=components.TargetSpec(
url='rtmps:https://live.my-service.tv/channel/secretKey',
name='My target',
),
),
],
),
))
if res.stream is not None:
# handle response
pass
- create - Create a stream
- get_all - Retrieve streams
- get - Retrieve a stream
- update - Update a stream
- delete - Delete a stream
- terminate - Terminates a live stream
- start_pull - Start ingest for a pull stream
- create_clip - Create a clip
- get_clips - Retrieve clips of a livestream
- add_multistream_target - Add a multistream target
- remove_multistream_target - Remove a multistream target
- get_all - Retrieve Multistream Targets
- create - Create a multistream target
- get - Retrieve a multistream target
- update - Update Multistream Target
- delete - Delete a multistream target
- get_all - Retrieve a Webhook
- create - Create a webhook
- get - Retrieve a webhook
- update - Update a webhook
- delete - Delete a webhook
- get_logs - Retrieve webhook logs
- get_log - Retrieve a webhook log
- resend_log - Resend a webhook
- get_all - Retrieve assets
- create - Upload an asset
- create_via_url - Upload asset via URL
- get - Retrieves an asset
- update - Patch an asset
- delete - Delete an asset
- get_clips - Retrieve clips of a session
- get_all - Retrieve sessions
- get - Retrieve a session
- get_recorded - Retrieve Recorded Sessions
create- Create a room⚠️ Deprecatedget- Retrieve a room⚠️ Deprecateddelete- Delete a room⚠️ Deprecatedstart_egress- Start room RTMP egress⚠️ Deprecatedstop_egress- Stop room RTMP egress⚠️ Deprecatedcreate_user- Create a room user⚠️ Deprecatedget_user- Get user details⚠️ Deprecatedupdate_user- Update a room user⚠️ Deprecateddelete_user- Remove a user from the room⚠️ Deprecated
- get_realtime_viewership - Query realtime viewership
- get_viewership - Query viewership metrics
- get_creator_viewership - Query creator viewership metrics
- get_public_viewership - Query public total views metrics
- get_usage - Query usage metrics
- create - Create a signing key
- get_all - Retrieves signing keys
- delete - Delete Signing Key
- get - Retrieves a signing key
- update - Update a signing key
- create - Transcode a video
- get - Retrieve Playback Info