|
1 |
| -# stream-chat-python |
| 1 | +# Official Python SDK for [Stream Chat](https://getstream.io/chat/) |
2 | 2 |
|
3 | 3 | [](https://github.com/GetStream/stream-chat-python/actions) [](http://badge.fury.io/py/stream-chat)  [](http://mypy-lang.org/)
|
4 | 4 |
|
| 5 | +<p align="center"> |
| 6 | + <img src="./assets/logo.svg" width="50%" height="50%"> |
| 7 | +</p> |
| 8 | +<p align="center"> |
| 9 | + Official Python API client for Stream Chat, a service for building chat applications. |
| 10 | + <br /> |
| 11 | + <a href="https://getstream.io/chat/docs/"><strong>Explore the docs »</strong></a> |
| 12 | + <br /> |
| 13 | + <br /> |
| 14 | + <a href="https://github.com/GetStream/python-chat-example">Code Samples</a> |
| 15 | + · |
| 16 | + <a href="https://github.com/GetStream/stream-chat-python/issues">Report Bug</a> |
| 17 | + · |
| 18 | + <a href="https://github.com/GetStream/stream-chat-python/issues">Request Feature</a> |
| 19 | +</p> |
| 20 | + |
5 | 21 | ---
|
6 | 22 | > ### :bulb: Major update in v4.0 <
|
7 | 23 | > 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()`).
|
8 | 24 | ---
|
9 | 25 |
|
10 |
| -The official Python API client for [Stream chat](https://getstream.io/chat/) a service for building chat applications. |
11 |
| - |
12 |
| -You can sign up for a Stream account on our [Get Started](https://getstream.io/chat/get_started/) page. |
13 |
| - |
14 |
| -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. |
15 |
| - |
16 |
| -### Installation |
17 |
| - |
18 |
| -```bash |
19 |
| -pip install stream-chat |
20 |
| -``` |
| 26 | +## 📝 About Stream |
21 | 27 |
|
22 |
| -### Documentation |
| 28 | +You can sign up for a Stream account at our [Get Started](https://getstream.io/chat/get_started/) page. |
23 | 29 |
|
24 |
| -[Official API docs](https://getstream.io/chat/docs/) |
| 30 | +You can use this library to access chat API endpoints server-side. |
25 | 31 |
|
26 |
| -### How to build a chat app with Python tutorial |
| 32 | +For the client-side integrations (web and mobile) have a look at the JavaScript, iOS and Android SDK libraries ([docs](https://getstream.io/chat/)). |
27 | 33 |
|
28 |
| -[Chat with Python, Django and React](https://github.com/GetStream/python-chat-example) |
| 34 | +## ⚙️ Installation |
29 | 35 |
|
30 |
| -### Supported features |
31 |
| - |
32 |
| -- Chat channels |
33 |
| -- Messages |
34 |
| -- Chat channel types |
35 |
| -- User management |
36 |
| -- Moderation API |
37 |
| -- Push configuration |
38 |
| -- User devices |
39 |
| -- User search |
40 |
| -- Channel search |
41 |
| -- Campaign API (alpha - susceptible changes and even won't be available in some regions yet) |
42 |
| -- Rate limit in response |
| 36 | +```shell |
| 37 | +$ pip install stream-chat |
| 38 | +``` |
43 | 39 |
|
44 |
| -### Quickstart |
| 40 | +## ✨ Getting started |
45 | 41 |
|
46 | 42 | > :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.
|
47 | 43 |
|
48 |
| -#### Sync |
49 |
| - |
50 | 44 | ```python
|
51 | 45 | from stream_chat import StreamChat
|
52 | 46 |
|
| 47 | +chat = StreamChat(api_key="STREAM_KEY", api_secret="STREAM_SECRET") |
53 | 48 |
|
54 |
| -def main(): |
55 |
| - chat = StreamChat(api_key="STREAM_KEY", api_secret="STREAM_SECRET") |
56 |
| - |
57 |
| - # add a user |
58 |
| - chat.update_user({"id": "chuck", "name": "Chuck"}) |
59 |
| - |
60 |
| - # create a channel about kung-fu |
61 |
| - channel = chat.channel("messaging", "kung-fu") |
62 |
| - channel.create("chuck") |
| 49 | +# add a user |
| 50 | +chat.update_user({"id": "chuck", "name": "Chuck"}) |
63 | 51 |
|
64 |
| - # add a first message to the channel |
65 |
| - channel.send_message({"text": "AMA about kung-fu"}, "chuck") |
| 52 | +# create a channel about kung-fu |
| 53 | +channel = chat.channel("messaging", "kung-fu") |
| 54 | +channel.create("chuck") |
66 | 55 |
|
67 |
| - # we also expose some response metadata through a custom dictionary |
68 |
| - resp = chat.deactivate_user("bruce_lee") |
69 |
| - print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'> |
70 |
| - print(resp["user"]["id"]) # bruce_lee |
| 56 | +# add a first message to the channel |
| 57 | +channel.send_message({"text": "AMA about kung-fu"}, "chuck") |
71 | 58 |
|
72 |
| - rate_limit = resp.rate_limit() |
73 |
| - print(f"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}") # 60 / 59 / 2022-01-06 12:35:00+00:00 |
| 59 | +# we also expose some response metadata through a custom dictionary |
| 60 | +resp = chat.deactivate_user("bruce_lee") |
74 | 61 |
|
75 |
| - headers = resp.headers() |
76 |
| - print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... } |
| 62 | +print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'> |
| 63 | +print(resp["user"]["id"]) # bruce_lee |
77 | 64 |
|
78 |
| - status_code = resp.status_code() |
79 |
| - print(status_code) # 200 |
| 65 | +rate_limit = resp.rate_limit() |
| 66 | +print(f"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}") # 60 / 59 /2022-01-06 12:35:00+00:00 |
80 | 67 |
|
| 68 | +headers = resp.headers() |
| 69 | +print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... } |
81 | 70 |
|
82 |
| -if __name__ == '__main__': |
83 |
| - main() |
| 71 | +status_code = resp.status_code() |
| 72 | +print(status_code) # 200 |
84 | 73 |
|
85 | 74 | ```
|
86 | 75 |
|
87 |
| -#### Async |
| 76 | +### Async |
88 | 77 |
|
89 | 78 | ```python
|
90 | 79 | import asyncio
|
@@ -128,34 +117,15 @@ if __name__ == '__main__':
|
128 | 117 |
|
129 | 118 | ```
|
130 | 119 |
|
131 |
| -### Contributing |
132 |
| - |
133 |
| -Install deps |
134 |
| - |
135 |
| -``` |
136 |
| -pip install .[test, ci] |
137 |
| -``` |
138 |
| - |
139 |
| -First, make sure you can run the test suite. Tests are run via pytest. |
| 120 | +## ✍️ Contributing |
140 | 121 |
|
141 |
| -```bash |
142 |
| -export STREAM_KEY=my_api_key |
143 |
| -export STREAM_SECRET=my_api_secret |
| 122 | +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. |
144 | 123 |
|
145 |
| -make test |
146 |
| -``` |
147 |
| - |
148 |
| -> 💡 If you're on a Unix system, you could also use [direnv](https://direnv.net/) to set up these env vars. |
149 |
| -
|
150 |
| -Run linters |
151 |
| - |
152 |
| -```bash |
153 |
| -make lint |
154 |
| -``` |
| 124 | +Head over to [CONTRIBUTING.md](./CONTRIBUTING.md) for some development tips. |
155 | 125 |
|
156 |
| -## We are hiring! |
| 126 | +## 🧑💻 We are hiring! |
157 | 127 |
|
158 | 128 | 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.
|
159 | 129 | 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.
|
160 | 130 |
|
161 |
| -Check out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs). |
| 131 | +Check out our current openings and apply via [Stream's website](https://getstream.io/team/#jobs). |
0 commit comments