Skip to main content

LiveKit Python Client SDK for LiveKit

Project description

The LiveKit icon, the name of the repository and some sample code in the background.

pypi-v

📹🎙️🐍 Python Client SDK for LiveKit

The Livekit Python Client provides a convenient interface for integrating Livekit's real-time video and audio capabilities into your Python applications. With this library, developers can easily leverage Livekit's WebRTC functionalities, allowing them to focus on building their AI models or other application logic without worrying about the complexities of WebRTC.

Official LiveKit documentation: https://docs.livekit.io/

Installation

$ pip install livekit

Connecting to a room

async def main():
    room = livekit.Room()

    # participants and tracks that are already available in the room
    # participant_connected and track_published events will *not* be emitted for them
    for participant in room.participants.items():
        for publication in participant.tracks.items():
            print("track publication: %s", publication.sid)

    @room.on("participant_connected")
    def on_participant_connected(participant: livekit.RemoteParticipant):
        logging.info(
            "participant connected: %s %s", participant.sid, participant.identity)

    async def receive_frames(stream: livekit.VideoStream):
        async for frame in video_stream:
            # received a video frame from the track, process it here
            pass

    # track_subscribed is emitted whenever the local participant is subscribed to a new track
    @room.on("track_subscribed")
    def on_track_subscribed(track: livekit.Track, publication: livekit.RemoteTrackPublication, participant: livekit.RemoteParticipant):
        logging.info("track subscribed: %s", publication.sid)
        if track.kind == livekit.TrackKind.KIND_VIDEO:
            video_stream = livekit.VideoStream(track)
            asyncio.ensure_future(receive_frames(video_stream))

    # By default, autosubscribe is enabled. The participant will be subscribed to
    # all published tracks in the room
    await room.connect(URL, TOKEN)
    logging.info("connected to room %s", room.name)

Examples

Getting help / Contributing

Please join us on Slack to get help from our devs / community members. We welcome your contributions(PRs) and details can be discussed there.


LiveKit Ecosystem
Client SDKsComponents · JavaScript · iOS/macOS · Android · Flutter · React Native · Rust · Python · Unity (web) · Unity (beta)
Server SDKsNode.js · Golang · Ruby · Java/Kotlin · PHP (community) · Python (community)
ServicesLivekit server · Egress · Ingress
ResourcesDocs · Example apps · Cloud · Self-hosting · CLI

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

livekit-0.4.5.tar.gz (32.5 kB view hashes)

Uploaded Source

Built Distributions

livekit-0.4.5-py3-none-win_amd64.whl (6.5 MB view hashes)

Uploaded Python 3 Windows x86-64

livekit-0.4.5-py3-none-manylinux_2_28_x86_64.whl (7.3 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.28+ x86-64

livekit-0.4.5-py3-none-manylinux_2_28_aarch64.whl (6.7 MB view hashes)

Uploaded Python 3 manylinux: glibc 2.28+ ARM64

livekit-0.4.5-py3-none-macosx_11_0_arm64.whl (8.1 MB view hashes)

Uploaded Python 3 macOS 11.0+ ARM64

livekit-0.4.5-py3-none-macosx_10_9_x86_64.whl (9.5 MB view hashes)

Uploaded Python 3 macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page