Skip to content

livepeer/livepeer-python

Repository files navigation

Livepeer Python Library

The Livepeer Python library provides convenient access to the Livepeer Studio API from applications written in Python

Documentation

For full documentation and examples, please visit docs.livepeer.org.

SDK Installation

pip install git+https://github.com/livepeer/livepeer-python.git

SDK Example Usage

Example

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

Available Resources and Operations

  • get_all - Retrieve Multistream Targets
  • create - Create a multistream target
  • get - Retrieve a multistream target
  • update - Update Multistream Target
  • delete - Delete a multistream target
  • create - Create a room ⚠️ Deprecated
  • get - Retrieve a room ⚠️ Deprecated
  • delete - Delete a room ⚠️ Deprecated
  • start_egress - Start room RTMP egress ⚠️ Deprecated
  • stop_egress - Stop room RTMP egress ⚠️ Deprecated
  • create_user - Create a room user ⚠️ Deprecated
  • get_user - Get user details ⚠️ Deprecated
  • update_user - Update a room user ⚠️ Deprecated
  • delete_user - Remove a user from the room ⚠️ Deprecated
  • create - Create a signing key
  • get_all - Retrieves signing keys
  • delete - Delete Signing Key
  • get - Retrieves a signing key
  • update - Update a signing key
  • get - Retrieve Playback Info

Error Handling

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 /

Example

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

Server Selection

Select Server by Index

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

Example

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://live.my-service.tv/channel/secretKey',
                    name='My target',
                ),
            ),
        ],
    ),
))

if res.stream is not None:
    # handle response
    pass

Override Server URL Per-Client

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://live.my-service.tv/channel/secretKey',
                    name='My target',
                ),
            ),
        ],
    ),
))

if res.stream is not None:
    # handle response
    pass

Custom HTTP Client

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)

Authentication

Per-Client Security Schemes

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://live.my-service.tv/channel/secretKey',
                    name='My target',
                ),
            ),
        ],
    ),
))

if res.stream is not None:
    # handle response
    pass

SDK Installation

pip install git+https://github.com/livepeer/livepeer-python.git

SDK Example Usage

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://live.my-service.tv/channel/secretKey',
                    name='My target',
                ),
            ),
        ],
    ),
))

if res.stream is not None:
    # handle response
    pass

Available Resources and Operations

  • get_all - Retrieve Multistream Targets
  • create - Create a multistream target
  • get - Retrieve a multistream target
  • update - Update Multistream Target
  • delete - Delete a multistream target
  • create - Create a room ⚠️ Deprecated
  • get - Retrieve a room ⚠️ Deprecated
  • delete - Delete a room ⚠️ Deprecated
  • start_egress - Start room RTMP egress ⚠️ Deprecated
  • stop_egress - Stop room RTMP egress ⚠️ Deprecated
  • create_user - Create a room user ⚠️ Deprecated
  • get_user - Get user details ⚠️ Deprecated
  • update_user - Update a room user ⚠️ Deprecated
  • delete_user - Remove a user from the room ⚠️ Deprecated
  • create - Create a signing key
  • get_all - Retrieves signing keys
  • delete - Delete Signing Key
  • get - Retrieves a signing key
  • update - Update a signing key
  • get - Retrieve Playback Info

About

Python library for the Livepeer API.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages