how to connect to python server skd
# ask-ai
b
how to connect to python server skd
t
Thanks for reaching out, Punith. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
b
did you find?
t
To connect to the LiveKit Python Server SDK, follow these steps: 1. Install the SDK using pip:
pip install livekit-api
2. Configure your credentials. Either set the following environment variables:Or pass credentials directly when initializing the API object. ◦ `LIVEKIT_API_KEY`: your API key ◦ `LIVEKIT_API_SECRET`: your API secret ◦ `LIVEKIT_URL`: your server URL (e.g.,
<https://your-project.livekit.cloud>
or
<wss://your-project.livekit.cloud>
) 1. Connect to the server and perform actions, such as creating a room, with code like:`from livekit import api import asyncio async def main(): lkapi = api.LiveKitAPI("https://my-project.livekit.cloud") room_info = await lkapi.room.create_room(api.CreateRoomRequest(name="my-room")) print(room_info) await lkapi.aclose() asyncio.run(main())` The Server API uses
asyncio
and functions must be called in an async context. The SDK can read credentials from the environment or you can supply them programmatically. Be sure to close the client with
await lkapi.aclose()
when done. For more specific usage, let me know which LiveKit service or operation you need to perform. Sources: livekit-api/livekit/api/livekit_api.py | complex-agents/nova-sonic/nova-sonic-form-agent/.env.example
To connect to the LiveKit Python Server SDK, follow these steps: 1. Install the package using pip:
pip install livekit-api
2. Set your environment variables: ◦ `LIVEKIT_API_KEY`: your API key ◦ `LIVEKIT_API_SECRET`: your API secret ◦ `LIVEKIT_URL`: your LiveKit server URL (e.g.
<https://your-project.livekit.cloud>
) 1. Create a connection in your Python code:
Copy code
from livekit import api

lkapi = api.LiveKitAPI("<https://your-project.livekit.cloud>")
2. Use the connection to access LiveKit services, like room or egress management:
Copy code
# Example: Creating a room
import asyncio
async def main():
    room_info = await lkapi.room.create_room(api.CreateRoomRequest(name="my-room"))
    print(room_info)
    await lkapi.aclose()
asyncio.run(main())
The SDK uses
asyncio
, so make sure to run your API calls inside an asynchronous context. The SDK will use your environment variables by default, but you can also pass API credentials directly in your code. Let me know if you need an example for a specific operation.