Getting Started

The official Python SDK for Stream covers Chat, Video, Moderation, and Feeds. This page takes you from installing the SDK to your first API call.

Start here

How the pieces fit together

This SDK calls the Stream API from your backend, authenticated with your API secret. Your users connect from your app with a client SDK, using a token your backend signs. Anything that needs a connected user or a live WebSocket lives in the client: initialization, guest and anonymous sessions, typing indicators and presence.

flowchart LR
  app[Your app] <-->|WebSocket| api[Stream API]
  backend[Your backend] -->|REST| api
  backend -. user token .-> app

Stream CLI and Agent Skills

Manage Stream from your terminal with the Stream CLI, including scripting and AI-agent workflows. Install the CLI and the default Agent Skills:

curl -fsSL https://getstream.io/cli.sh | bash
getstream skills

Then ask your agent in plain English, for example:

/stream List recent channels in my app.

See the CLI docs and Agent Skills docs for more.

Setup

Install the SDK:

pip install getstream

Initialize the client with your API key and secret (available on the Dashboard):

from getstream import Stream

client = Stream(api_key="your-api-key", api_secret="your-api-secret")

The client also reads STREAM_API_KEY and STREAM_API_SECRET from environment variables, so you can construct it with no arguments:

client = Stream()

Server-side token

Your backend generates a user token that the client SDKs use to authenticate. A typical place to issue this token is during login or registration.

token = client.create_token(user_id="user-id")
# return the token to the client app

Tokens with an expiry (in seconds):

token = client.create_token(user_id="user-id", expiration=3600)

For token expiry and revocation details, see Authentication and tokens.

Making your first API call

Create a user, open a channel, and send a message:

from getstream.models import UserRequest, ChannelInput, MessageRequest

# Upsert a user
client.upsert_users(
    UserRequest(id="john", name="John")
)

# Create or join a channel
channel = client.chat.channel("messaging", "hello-world")
channel.get_or_create(data=ChannelInput(created_by_id="john"))

# Send a message
channel.send_message(
    MessageRequest(text="Hello, Stream!", user_id="john")
)

What's next

Once your first message is through, these are good places to go deeper: