Stream Python Client
Client for getstream.io, enabling developers to build scalable newsfeeds and activity streams. The library provides functionality to interact with Stream's API for feed management, activity posting, and user token generation. Currently at version 5.4.0, it maintains an active development pace with several releases per year, including minor updates and occasional major feature additions.
Warnings
- breaking Version 5.0.0 dropped support for Python 3.5. Ensure your environment uses Python 3.6 or newer (3.7+ recommended).
- breaking Version 5.0.1 introduced a breaking change by bumping the `pyjwt` dependency to version 2.x. If you have other dependencies requiring `pyjwt==1.x`, this might cause conflicts.
- breaking In version 4.0.0, the `create_user_session_token` method was removed and replaced with `create_user_token`. Calls to the old method will fail.
- gotcha When handling JWT tokens, especially if generating them manually or interacting with older systems, be aware that `stream-python`'s token generation methods (e.g., `create_user_token`) now use `pyjwt` 2.x internally. This affects the default algorithms and parameters.
Install
-
pip install stream-python
Imports
- stream.connect
import stream client = stream.connect(...)
Quickstart
import stream
import os
# Get your API key and secret from getstream.io/dashboard
STREAM_API_KEY = os.environ.get('STREAM_API_KEY', 'YOUR_STREAM_API_KEY')
STREAM_API_SECRET = os.environ.get('STREAM_API_SECRET', 'YOUR_STREAM_API_SECRET')
# Connect to the Stream API
client = stream.connect(STREAM_API_KEY, STREAM_API_SECRET)
# Get a user feed
user_feed = client.feed('user', 'john-doe')
# Add an activity to the feed
activity_data = {
'actor': 'john-doe',
'verb': 'post',
'object': '1',
'foreign_id': 'post:1',
'message': 'Hello world from Stream!'
}
response = user_feed.add_activity(activity_data)
print(f"Activity added: {response['id']}")
# Read activities from the feed (optional, for demonstration)
activities = user_feed.get(limit=1)['results']
if activities:
print(f"Retrieved activity: {activities[0]['message']}")