Skip to main content

Note: getstream is the new full-product SDK for Stream, covering Chat, Video, Moderation, and Feeds with long-term support.

stream-chat is now in maintenance mode. It will continue to receive critical fixes and requested features, so it is safe to keep using. However, we encourage existing users to migrate when convenient and strongly recommend that new projects start with getstream.

Check out the Migration Guide for side-by-side examples covering common use cases.

Official Python SDK for Stream Chat

build PyPI version PyPI - Python Version Checked with mypy

Official Python API client for Stream Chat, a service for building chat applications.
Explore the docs »

Code Samples · Report Bug · Request Feature


:bulb: Major update in v4.0 <

The returned response objects are instances of StreamResponse class. It inherits from dict, so it's fully backward compatible. Additionally, it provides other benefits such as rate limit information (resp.rate_limit()), response headers (resp.headers()) or status code (resp.status_code()).


📝 About Stream

You can sign up for a Stream account at our Get Started page.

You can use this library to access chat API endpoints server-side.

For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries (docs).

⚙️ Installation

$ pip install stream-chat

✨ Getting started

:bulb: The library is almost 100% typed. Feel free to enable mypy for our library. We will introduce more improvements in the future in this area.

from stream_chat import StreamChat

chat = StreamChat(api_key="STREAM_KEY", api_secret="STREAM_SECRET")

# add a user
chat.upsert_user({"id": "chuck", "name": "Chuck"})

# create a channel about kung-fu
channel = chat.channel("messaging", "kung-fu")
channel.create("chuck")

# add a first message to the channel
channel.send_message({"text": "AMA about kung-fu"}, "chuck")

# we also expose some response metadata through a custom dictionary
resp = chat.deactivate_user("bruce_lee")

print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'>
print(resp["user"]["id"]) # bruce_lee

rate_limit = resp.rate_limit()
print(f"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}") # 60 / 59 /2022-01-06 12:35:00+00:00

headers = resp.headers()
print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }

status_code = resp.status_code()
print(status_code) # 200

Async

import asyncio
from stream_chat import StreamChatAsync


async def main():
    async with StreamChatAsync(api_key="STREAM_KEY", api_secret="STREAM_SECRET") as chat:
        # add a user
        await chat.upsert_user({"id": "chuck", "name": "Chuck"})

        # create a channel about kung-fu
        channel = chat.channel("messaging", "kung-fu")
        await channel.create("chuck")

        # add a first message to the channel
        await channel.send_message({"text": "AMA about kung-fu"}, "chuck")

        # we also expose some response metadata through a custom dictionary
        resp = await chat.deactivate_user("bruce_lee")
        print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'>
        print(resp["user"]["id"]) # bruce_lee

        rate_limit = resp.rate_limit()
        print(f"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}") # 60 / 59 / 2022-01-06 12:35:00+00:00

        headers = resp.headers()
        print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }

        status_code = resp.status_code()
        print(status_code) # 200


if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(main())
    finally:
        loop.run_until_complete(loop.shutdown_asyncgens())
        loop.close()

✍️ 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.

Head over to CONTRIBUTING.md for some development tips.

🧑‍💻 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.

Metadata

Release files for stream-chat 4.33.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stream-chat 4.33.0
File Size Uploaded
stream_chat-4.33.0.tar.gz 52.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for stream-chat 4.33.0
File Interpreter ABI Platform
stream_chat-4.33.0-py3-none-any.whl Python 3 none any Details

Total release size: 111.4 kB

Release files / stream_chat-4.33.0.tar.gz

Download URL stream_chat-4.33.0.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
f99e43e179eedaf0daf92eb940d8b0a4ce7e1a888a1a312a25bd8d1798456a70
BLAKE2b-256 checksum
How to use checksums
2d12d63823cc7ead4f19ab58b9c6adc39b376495586215e486b1e28fd4dec944
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/9.0.1 pkginfo/1.13 requests/2.34.2 requests-toolbelt/1.0.0 tqdm/4.70.0 CPython/3.10.21

Release files / stream_chat-4.33.0-py3-none-any.whl

Download URL stream_chat-4.33.0-py3-none-any.whl
Size 58.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d3ba1a94dee45d49bd5880f321e133bfcdb6f1ea3175476f6b18b3d0d809ac97
BLAKE2b-256 checksum
How to use checksums
325d66e7c49c3a0da61d16fe928587ccc4849b282e2be363e64c8314d2f37b50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/9.0.1 pkginfo/1.13 requests/2.34.2 requests-toolbelt/1.0.0 tqdm/4.70.0 CPython/3.10.21

Release history Release notifications | RSS feed

This release

4.33.0 This release

2 release files

4.32.0

2 release files

4.31.0

2 release files

4.30.1

2 release files

4.29.0

2 release files

4.28.0

2 release files

4.27.0

2 release files

4.25.0

2 release files

4.23.0

2 release files

4.22.0

2 release files

4.21.0

2 release files

4.17.0

2 release files

4.16.0

2 release files

4.15.0

2 release files

4.12.1

2 release files

4.12.0

2 release files

4.11.0

2 release files

4.10.0

2 release files

4.9.0

2 release files

4.8.0

2 release files

4.7.0

2 release files

4.6.0

2 release files

4.5.0

2 release files

4.4.2

2 release files

4.4.1

2 release files

4.4.0

2 release files

4.3.0

2 release files

4.2.2

2 release files

4.2.1

2 release files

4.2.0

2 release files

4.1.0

2 release files

4.0.0

2 release files

3.15.0

1 release file

3.14.0

1 release file

3.13.1

1 release file

3.13.0

1 release file

3.12.2

1 release file

3.12.1

1 release file

3.12.0

1 release file

3.11.2

1 release file

3.11.1

1 release file

3.11.0

1 release file

3.10.0

1 release file

3.9.0

1 release file

3.8.0

1 release file

3.7.0

1 release file

3.6.0

1 release file

3.5.0

1 release file

3.4.0

1 release file

3.3.0

1 release file

3.2.1

1 release file

3.2.0

1 release file

3.1.1

1 release file

3.1.0

1 release file

3.0.1

1 release file

3.0.0

1 release file

2.0.0

1 release file

1.7.1

1 release file

1.7.0

2 release files

1.6.0

1 release file

1.5.0

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.2

1 release file

1.1.0

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.0

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page