Skip to main content

Client for Stream Chat.

Project description

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stream-chat-4.12.1.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stream_chat-4.12.1-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file stream-chat-4.12.1.tar.gz.

File metadata

  • Download URL: stream-chat-4.12.1.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/7.0.1 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.10.13

File hashes

Hashes for stream-chat-4.12.1.tar.gz
Algorithm Hash digest
SHA256 56ccd65d4862231c2cbd1bf6f21c73eb8125f664a33126fabedc829bafe11176
MD5 7d0736aac718108bc8764731d0fdf233
BLAKE2b-256 46cb2f902bbff42d083019947b464746208d1e8ef584f92ceef04afa396aa51f

See more details on using hashes here.

File details

Details for the file stream_chat-4.12.1-py3-none-any.whl.

File metadata

  • Download URL: stream_chat-4.12.1-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/7.0.1 pkginfo/1.9.6 requests/2.31.0 requests-toolbelt/1.0.0 tqdm/4.66.2 CPython/3.10.13

File hashes

Hashes for stream_chat-4.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2873726845a69b58325e0cf8ce36f26e4838490e4a2751d33ca6bc3445000f98
MD5 20a7ee18817aeadcfcfb48d9f8c60dfe
BLAKE2b-256 bd6ed61f93a58c9b5a2eca4e1f94145bac14cdb216710b143f74409d9e68195a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page