Official Python API client for Stream Feeds, a web service for building scalable newsfeeds and activity streams.
Explore the docs »
Django Code Sample
·
Report Bug
·
Request Feature
📝 About Stream
💡 Note: this is a library for the Feeds product. The Chat SDKs can be found here.
You can sign up for a Stream account at our Get Started page.
You can use this library to access feeds API endpoints server-side.
For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).
💡 We have a Django integration available here.
⚙️ Installation
$ pip install stream-python
📚 Full documentation
Documentation for this Python client are available at the Stream website.
✨ Getting started
import datetime
import stream
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET')
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET', location='us-east')
user_feed_1 = client.feed('user', '1')
result = user_feed_1.get(limit=5, offset=5)
result = user_feed_1.get(limit=5, id_lt="e561de8f-00f1-11e4-b400-0cc47a024be0")
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:1'}
activity_response = user_feed_1.add_activity(activity_data)
activity_data = {'actor': 1, 'verb': 'run', 'object': 1, 'foreign_id': 'run:1',
'course': {'name': 'Golden Gate park', 'distance': 10},
'participants': ['Thierry', 'Tommaso'],
'started_at': datetime.datetime.now()
}
user_feed_1.add_activity(activity_data)
user_feed_1.remove_activity("e561de8f-00f1-11e4-b400-0cc47a024be0")
user_feed_1.remove_activity(foreign_id='tweet:1')
user_feed_1.follow('flat', '42')
user_feed_1.unfollow('flat', '42')
following = user_feed_1.following(offset=0, limit=2)
followers = user_feed_1.followers(offset=0, limit=10)
follows = [
{'source': 'flat:1', 'target': 'user:1'},
{'source': 'flat:1', 'target': 'user:2'},
{'source': 'flat:1', 'target': 'user:3'}
]
client.follow_many(follows)
activities = [
{'actor': 1, 'verb': 'tweet', 'object': 1},
{'actor': 2, 'verb': 'watch', 'object': 3}
]
user_feed_1.add_activities(activities)
activity = {
"actor":"1",
"verb":"like",
"object":"3",
"to":["user:44", "user:45"]
}
user_feed_1.add_activity(activity)
client.get_activities(ids=[activity_id])
client.get_activities(foreign_id_times=[
(foreign_id, activity_time),
])
client.get_activities(ids=[activity_id], enrich=True, reactions={"counts": True})
set = {
'product.name': 'boots',
'colors': {
'red': '0xFF0000',
'green': '0x00FF00'
}
}
unset = [ 'popularity', 'details.info' ]
client.activity_partial_update(id=activity_id, set=set, unset=unset)
client.activity_partial_update(foreign_id=foreign_id, time=activity_time, set=set, unset=unset)
user_token = client.create_user_token("user-42")
impression = {
'content_list': ['tweet:1', 'tweet:2', 'tweet:3'],
'user_data': 'tommaso',
'location': 'email',
'feed_id': 'user:global'
}
engagement = {
'content': 'tweet:2',
'label': 'click',
'position': 1,
'user_data': 'tommaso',
'location': 'email',
'feed_id':
'user:global'
}
events = [impression, engagement]
redirect_url = client.create_redirect_url('http://google.com/', 'user_id', events)
Async code usage
import datetime
import stream
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET', use_async=True)
client = stream.connect('YOUR_API_KEY', 'API_KEY_SECRET', location='us-east', use_async=True)
user_feed_1 = client.feed('user', '1')
result = await user_feed_1.get(limit=5, offset=5)
result = await user_feed_1.get(limit=5, id_lt="e561de8f-00f1-11e4-b400-0cc47a024be0")
activity_data = {'actor': 1, 'verb': 'tweet', 'object': 1, 'foreign_id': 'tweet:1'}
activity_response = await user_feed_1.add_activity(activity_data)
activity_data = {'actor': 1, 'verb': 'run', 'object': 1, 'foreign_id': 'run:1',
'course': {'name': 'Golden Gate park', 'distance': 10},
'participants': ['Thierry', 'Tommaso'],
'started_at': datetime.datetime.now()
}
await user_feed_1.add_activity(activity_data)
await user_feed_1.remove_activity("e561de8f-00f1-11e4-b400-0cc47a024be0")
await user_feed_1.remove_activity(foreign_id='tweet:1')
await user_feed_1.follow('flat', '42')
await user_feed_1.unfollow('flat', '42')
following = await user_feed_1.following(offset=0, limit=2)
followers = await user_feed_1.followers(offset=0, limit=10)
follows = [
{'source': 'flat:1', 'target': 'user:1'},
{'source': 'flat:1', 'target': 'user:2'},
{'source': 'flat:1', 'target': 'user:3'}
]
await client.follow_many(follows)
activities = [
{'actor': 1, 'verb': 'tweet', 'object': 1},
{'actor': 2, 'verb': 'watch', 'object': 3}
]
await user_feed_1.add_activities(activities)
activity = {
"actor":"1",
"verb":"like",
"object":"3",
"to":["user:44", "user:45"]
}
await user_feed_1.add_activity(activity)
await client.get_activities(ids=[activity_id])
await client.get_activities(foreign_id_times=[
(foreign_id, activity_time),
])
await client.get_activities(ids=[activity_id], enrich=True, reactions={"counts": True})
set = {
'product.name': 'boots',
'colors': {
'red': '0xFF0000',
'green': '0x00FF00'
}
}
unset = [ 'popularity', 'details.info' ]
await client.activity_partial_update(id=activity_id, set=set, unset=unset)
await client.activity_partial_update(foreign_id=foreign_id, time=activity_time, set=set, unset=unset)
user_token = client.create_user_token("user-42")
impression = {
'content_list': ['tweet:1', 'tweet:2', 'tweet:3'],
'user_data': 'tommaso',
'location': 'email',
'feed_id': 'user:global'
}
engagement = {
'content': 'tweet:2',
'label': 'click',
'position': 1,
'user_data': 'tommaso',
'location': 'email',
'feed_id':
'user:global'
}
events = [impression, engagement]
redirect_url = client.create_redirect_url('http://google.com/', 'user_id', events)
JS client.
✍️ Contributing
=======
We welcome code changes that improve this library or fix a problem, please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github. We are very happy to merge your code in the official repository. Make sure to sign our Contributor License Agreement (CLA) first. See our license file for more details.
🧑💻 We are hiring!
We've recently closed a $38 million Series B funding round and we keep actively growing.
Our APIs are used by more than a billion end-users, and you'll have a chance to make a huge impact on the product within a team of the strongest engineers all over the world.
Check out our current openings and apply via Stream's website.