stream-chat


Namestream-chat JSON
Version 4.20.0 PyPI version JSON
download
home_pagehttps://github.com/GetStream/stream-chat-python
SummaryClient for Stream Chat.
upload_time2024-12-07 08:46:04
maintainerNone
docs_urlNone
authorTommaso Barbugli
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # Official Python SDK for [Stream Chat](https://getstream.io/chat/)

[![build](https://github.com/GetStream/stream-chat-python/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-python/actions) [![PyPI version](https://badge.fury.io/py/stream-chat.svg)](http://badge.fury.io/py/stream-chat) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stream-chat.svg) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)

<p align="center">
    <img src="./assets/logo.svg" width="50%" height="50%">
</p>
<p align="center">
    Official Python API client for Stream Chat, a service for building chat applications.
    <br />
    <a href="https://getstream.io/chat/docs/"><strong>Explore the docs »</strong></a>
    <br />
    <br />
    <a href="https://github.com/GetStream/python-chat-example">Code Samples</a>
    ·
    <a href="https://github.com/GetStream/stream-chat-python/issues">Report Bug</a>
    ·
    <a href="https://github.com/GetStream/stream-chat-python/issues">Request Feature</a>
</p>

---
> ### :bulb: Major update in v4.0 <
> The returned response objects are instances of [`StreamResponse`](https://github.com/GetStream/stream-chat-python/blob/master/stream_chat/types/stream_response.py) 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](https://getstream.io/chat/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](https://getstream.io/chat/)).

## ⚙️ Installation

```shell
$ pip install stream-chat
```

## ✨ Getting started

> :bulb: The library is almost 100% typed. Feel free to enable [mypy](https://github.com/python/mypy) for our library. We will introduce more improvements in the future in this area.

```python
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

```python
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)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.

Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.

## 🧑‍💻 We are hiring!

We've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) 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](https://getstream.io/team/#jobs).

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/GetStream/stream-chat-python",
    "name": "stream-chat",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Tommaso Barbugli",
    "author_email": "support@getstream.io",
    "download_url": "https://files.pythonhosted.org/packages/f7/23/ae47f4fae209f171712903417b1d822812a5a3bee01a25fb73213339a398/stream-chat-4.20.0.tar.gz",
    "platform": null,
    "description": "# Official Python SDK for [Stream Chat](https://getstream.io/chat/)\n\n[![build](https://github.com/GetStream/stream-chat-python/workflows/build/badge.svg)](https://github.com/GetStream/stream-chat-python/actions) [![PyPI version](https://badge.fury.io/py/stream-chat.svg)](http://badge.fury.io/py/stream-chat) ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stream-chat.svg) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)\n\n<p align=\"center\">\n    <img src=\"./assets/logo.svg\" width=\"50%\" height=\"50%\">\n</p>\n<p align=\"center\">\n    Official Python API client for Stream Chat, a service for building chat applications.\n    <br />\n    <a href=\"https://getstream.io/chat/docs/\"><strong>Explore the docs \u00bb</strong></a>\n    <br />\n    <br />\n    <a href=\"https://github.com/GetStream/python-chat-example\">Code Samples</a>\n    \u00b7\n    <a href=\"https://github.com/GetStream/stream-chat-python/issues\">Report Bug</a>\n    \u00b7\n    <a href=\"https://github.com/GetStream/stream-chat-python/issues\">Request Feature</a>\n</p>\n\n---\n> ### :bulb: Major update in v4.0 <\n> The returned response objects are instances of [`StreamResponse`](https://github.com/GetStream/stream-chat-python/blob/master/stream_chat/types/stream_response.py) 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()`).\n---\n\n## \ud83d\udcdd About Stream\n\nYou can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page.\n\nYou can use this library to access chat API endpoints server-side.\n\nFor the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/chat/)).\n\n## \u2699\ufe0f Installation\n\n```shell\n$ pip install stream-chat\n```\n\n## \u2728 Getting started\n\n> :bulb: The library is almost 100% typed. Feel free to enable [mypy](https://github.com/python/mypy) for our library. We will introduce more improvements in the future in this area.\n\n```python\nfrom stream_chat import StreamChat\n\nchat = StreamChat(api_key=\"STREAM_KEY\", api_secret=\"STREAM_SECRET\")\n\n# add a user\nchat.upsert_user({\"id\": \"chuck\", \"name\": \"Chuck\"})\n\n# create a channel about kung-fu\nchannel = chat.channel(\"messaging\", \"kung-fu\")\nchannel.create(\"chuck\")\n\n# add a first message to the channel\nchannel.send_message({\"text\": \"AMA about kung-fu\"}, \"chuck\")\n\n# we also expose some response metadata through a custom dictionary\nresp = chat.deactivate_user(\"bruce_lee\")\n\nprint(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'>\nprint(resp[\"user\"][\"id\"]) # bruce_lee\n\nrate_limit = resp.rate_limit()\nprint(f\"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}\") # 60 / 59 /2022-01-06 12:35:00+00:00\n\nheaders = resp.headers()\nprint(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }\n\nstatus_code = resp.status_code()\nprint(status_code) # 200\n\n```\n\n### Async\n\n```python\nimport asyncio\nfrom stream_chat import StreamChatAsync\n\n\nasync def main():\n    async with StreamChatAsync(api_key=\"STREAM_KEY\", api_secret=\"STREAM_SECRET\") as chat:\n        # add a user\n        await chat.upsert_user({\"id\": \"chuck\", \"name\": \"Chuck\"})\n\n        # create a channel about kung-fu\n        channel = chat.channel(\"messaging\", \"kung-fu\")\n        await channel.create(\"chuck\")\n\n        # add a first message to the channel\n        await channel.send_message({\"text\": \"AMA about kung-fu\"}, \"chuck\")\n\n        # we also expose some response metadata through a custom dictionary\n        resp = await chat.deactivate_user(\"bruce_lee\")\n        print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'>\n        print(resp[\"user\"][\"id\"]) # bruce_lee\n\n        rate_limit = resp.rate_limit()\n        print(f\"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}\") # 60 / 59 / 2022-01-06 12:35:00+00:00\n\n        headers = resp.headers()\n        print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }\n\n        status_code = resp.status_code()\n        print(status_code) # 200\n\n\nif __name__ == '__main__':\n    loop = asyncio.get_event_loop()\n    try:\n        loop.run_until_complete(main())\n    finally:\n        loop.run_until_complete(loop.shutdown_asyncgens())\n        loop.close()\n\n```\n\n## \u270d\ufe0f Contributing\n\nWe 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)](https://docs.google.com/forms/d/e/1FAIpQLScFKsKkAJI7mhCr7K9rEIOpqIDThrWxuvxnwUq2XkHyG154vQ/viewform) first. See our [license file](./LICENSE) for more details.\n\nHead over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips.\n\n## \ud83e\uddd1\u200d\ud83d\udcbb We are hiring!\n\nWe've recently closed a [$38 million Series B funding round](https://techcrunch.com/2021/03/04/stream-raises-38m-as-its-chat-and-activity-feed-apis-power-communications-for-1b-users/) and we keep actively growing.\nOur 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.\n\nCheck out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs).\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Client for Stream Chat.",
    "version": "4.20.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/GetStream/stream-chat-python/issues",
        "Documentation": "https://getstream.io/activity-feeds/docs/python/?language=python",
        "Homepage": "https://github.com/GetStream/stream-chat-python",
        "Release Notes": "https://github.com/GetStream/stream-chat-python/releases/tag/v4.20.0"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8bc29334b772702b0837c70e6dba8473a98b09725902a5bc8558955f13424d36",
                "md5": "02e9638c0ce11ed28da5531246846e77",
                "sha256": "f2f5aca2b684170c3f19b950060b413877198ce87a8a8602f48d90069260fe6a"
            },
            "downloads": -1,
            "filename": "stream_chat-4.20.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "02e9638c0ce11ed28da5531246846e77",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 42883,
            "upload_time": "2024-12-07T08:46:02",
            "upload_time_iso_8601": "2024-12-07T08:46:02.357974Z",
            "url": "https://files.pythonhosted.org/packages/8b/c2/9334b772702b0837c70e6dba8473a98b09725902a5bc8558955f13424d36/stream_chat-4.20.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f723ae47f4fae209f171712903417b1d822812a5a3bee01a25fb73213339a398",
                "md5": "54cddfa28d75e518f6e803fe14767872",
                "sha256": "71ab9016f6ae35da14eff7edddb4e684ffe9da1862e54e654165914bd66402b6"
            },
            "downloads": -1,
            "filename": "stream-chat-4.20.0.tar.gz",
            "has_sig": false,
            "md5_digest": "54cddfa28d75e518f6e803fe14767872",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 39013,
            "upload_time": "2024-12-07T08:46:04",
            "upload_time_iso_8601": "2024-12-07T08:46:04.207728Z",
            "url": "https://files.pythonhosted.org/packages/f7/23/ae47f4fae209f171712903417b1d822812a5a3bee01a25fb73213339a398/stream-chat-4.20.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-07 08:46:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "GetStream",
    "github_project": "stream-chat-python",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "stream-chat"
}
        
Elapsed time: 1.57931s