video sdk logo

Login

Python Video Calling Tutorial

Join and control real-time video meetings from Python with asyncio. Publish and subscribe to audio and video tracks server-side to build meeting bots, recorders, and AI participants that sit inside the call.
Python program built with VideoSDK joining a live video meeting as a server-side participant

Trusted by 300+ global business & tech leaders

Build a Video Room in Python with Async APIs

Learn how to join and control video rooms in Python using the VideoSDK Python SDK. This step-by-step tutorial covers pip installation, token setup, joining a meeting with asyncio, handling participant events, and publishing custom audio and video tracks.


Prerequisites

Before proceeding, ensure that your development environment meets the following requirements:

  • VideoSDK Developer Account (Not having one? Follow VideoSDK Dashboard)
  • Basic understanding of Python
  • Python installed on your device.
  • Python VideoSDK
  • Python asyncio (optional)

Important: You need a VideoSDK account to generate a token. Visit the VideoSDK dashboard to generate a token.

Getting Started with the Code!

Follow the steps to create the environment necessary to add video calls to your app. You can also find the code sample for quickstart here.

Create a New Python Project

Create a new Python project using the below command.

Terminal
1mkdir videosdk-python && cd videosdk-python
2

Install VideoSDK

Install the VideoSDK using the pip command below.

Terminal
1pip install videosdk
2

Project Structure

Your project structure should look like this:

Project Structure
1videosdk-python
2├── main.py
3├── meeting_events.py
4├── participant_events.py
5├── api.py
6

Step 1: Create an API Call

Before moving on, create an API request to generate a unique meetingId. You will need an authentication token, which you can create either through the videosdk-rtc-api-server-examples or directly from the VideoSDK Dashboard for developers.

api.py
1import requests
2
3# This is the Auth token, you will use it to generate a meeting and connect to it
4token = "<Your-Token>"
5
6# API call to create a meeting
7def create_meeting(token):
8    url = "https://api.videosdk.live/v2/rooms"
9    headers = {
10        "authorization": token,
11        "Content-Type": "application/json"
12    }
13    response = requests.post(url, headers=headers, json={})
14    response_data = response.json()
15    room_id = response_data.get("roomId")
16    return room_id
17
18# Example usage
19meeting_id = create_meeting(token)
20print("Meeting ID:", meeting_id)
21

Step 2: Join the Meeting

Join an existing meeting or a new meeting created above.

Add the following code to the main.py file.

main.py
1import asyncio
2from videosdk import MeetingConfig, VideoSDK
3
4VIDEOSDK_TOKEN = "<TOKEN>"
5MEETING_ID = "<MEETING_ID>"
6NAME = "<NAME>"
7loop = asyncio.get_event_loop()
8
9def main():
10    meeting_config = MeetingConfig(
11        meeting_id=MEETING_ID,
12        name=NAME,
13        mic_enabled=True,
14        webcam_enabled=True,
15        token=VIDEOSDK_TOKEN
16    )
17
18    # Initialize the meeting
19    meeting = VideoSDK.init_meeting(**meeting_config)
20
21    print("Joining the meeting...")
22
23    # Join the meeting
24    meeting.join()
25
26    print("Joined successfully")
27
28if __name__ == '__main__':
29    main()
30    loop.run_forever()
31

Step 3: Listen to Meeting Events

We can listen to meeting events as callbacks by inheriting the class MeetingEventHandler. We will use MyMeetingEventHandler class in step 5.

meeting_events.py
1from videosdk import Participant, MeetingEventHandler
2from participant_events import MyParticipantEventHandler
3
4class MyMeetingEventHandler(MeetingEventHandler):
5    def __init__(self):
6        super().__init__()
7
8    def on_meeting_joined(self, data):
9        print("Meeting joined:", data)
10
11    def on_meeting_left(self, data):
12        print("Meeting left:", data)
13
14    def on_participant_joined(self, participant: Participant):
15        print("Participant joined:", participant)
16        participant.add_event_listener(MyParticipantEventHandler(participant_id=participant.id))
17
18    def on_participant_left(self, participant: Participant):
19        print("Participant left:", participant)
20

Step 4: Listen to Participant Events

We can listen to participant events as callbacks by inheriting the class ParticipantEventHandler. We will use MyParticipantEventHandler class in step 5.

participant_events.py
1from videosdk import ParticipantEventHandler, Stream
2
3class MyParticipantEventHandler(ParticipantEventHandler):
4    def __init__(self, participant_id: str):
5        super().__init__()
6        self.participant_id = participant_id
7
8    def on_stream_enabled(self, stream: Stream):
9        print("Participant stream enabled:", self.participant_id, stream.kind)
10
11    def on_stream_disabled(self, stream: Stream):
12        print("Participant stream disabled:", self.participant_id, stream.kind)
13

Step 5: Add Event Listeners

Now that we have created the event listeners, let's add them to the meeting and participants in the existing main.py file.

Add the event listener before joining the meeting.

main.py
1from meeting_events import MyMeetingEventHandler
2
3# Add this line
4meeting.add_event_listener(MyMeetingEventHandler())
5
6# Before joining the meeting, add the event listener
7meeting.join()
8...
9

Listen for participant events when a participant joins the meeting in the existing meeting_events.py file.

meeting_events.py
1from participant_events import MyParticipantEventHandler
2
3# Rest of the code as is
4def on_participant_joined(self, participant):
5    print("Participant joined:", participant)
6    participant.add_event_listener(MyParticipantEventHandler(participant_id=participant.id))
7...
8

Step 6: Run your code

Run the example using the following command:

Terminal
1python main.py
2

Output

VideoSDK Python quickstart output showing the terminal logs and the joined participant video

Note: You have completed the implementation of audio-video call using VideoSDK in Python. To explore more features like transform participant video, vision ai go through upcoming detailed guide.

Tip: You can check out the complete quick start example here.

Summarize with

ChatGPTClaudePerplexityGoogleGrok
Prefer VideoSDK on Google

Table of Contents

Start Building Now With $20 Free Balance

No credit card required to start.

Documentation →Github Repo →

Share This Article

TwitterLinkedInFacebookHacker News

Get started for free today

Grab your API keys and start building with free $20 included in your account. Need enterprise-grade security or custom workloads? Talk to an expert!

Book a demo

Video SDK Logo

United States

28 Geary St, Suite 650,
San Francisco, CA 94108, United States

India flag

India

18th Floor, 1812, The Junomoneta Tower,
Adajan-Hazira Rd, Surat, Gujarat 395009, India

Video SDK Logo
Video SDK Logo
Video SDK Logo
Video SDK Logo
SOLUTIONS

Video KYC

Video Banking

Virtual Claim

Video MER

Telehealth

Astrology

Gaming

Dating

Live Commerce

Auto Proctoring

Interview-as-a-service

Virtual Events

Live Audio Streaming

Ed-Tech

PRODUCTS

AI-Agents

Real-time Audio & Video SDK

Interactive Live Streaming SDK

Real-time Transcription SDK

Character SDK

Open Source Examples

SUCCESS STORIES

Examedi

Coderschool

TYHO

ForagerOne

Immigo

DEVELOPERS

Documentation

Code Samples

Developer Updates

Developer Hub

TOP ARTICLES

What is WebRTC?

Build a React Native Video Calling App

Build a Flutter Video Calling App

RESOURCES

The Protocol by Video SDK

AI Apps

Creator Program

LEGAL

Terms Of Service

Privacy Policy

Cookie Notice

CCPA Notice

Subprocessors

DPA

RSS

COMPANY

Contact Us

Pricing

Support

Blog

Press Kit