Skip to content

Commit c472c0b

Browse files
authored
feat: add ratelimit info, plus remove py 3.6 support
1 parent a5ae243 commit c472c0b

File tree

22 files changed

+208
-55
lines changed

22 files changed

+208
-55
lines changed

.coveragerc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[run]
2+
omit = stream_chat/tests/*

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @ferhatelmas @gumuz
1+
* @gumuz @peterdeme @ferhatelmas

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ jobs:
1414
name: 🧪 Test & lint
1515
runs-on: ubuntu-latest
1616
strategy:
17+
fail-fast: false
1718
max-parallel: 1
1819
matrix:
19-
python: [3.6, 3.7, 3.8, 3.9, "3.10"]
20+
python: [3.7, 3.8, 3.9, "3.10"]
2021
steps:
2122
- uses: actions/checkout@v2
2223
- uses: actions/setup-python@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ coverage.xml
4444
.project
4545
.pydevproject
4646
.coverage*
47+
!.coveragerc
4748

4849
# Rope
4950
.ropeproject

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ lint: ## Run linters
1616

1717
lint-fix:
1818
black stream_chat
19+
isort stream_chat
1920

2021
test: ## Run tests
2122
STREAM_KEY=$(STREAM_KEY) STREAM_SECRET=$(STREAM_SECRET) pytest --cov=stream_chat --cov-report=xml stream_chat/tests

README.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
[![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/)
44

5-
the official Python API client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
5+
---
6+
> ### :bulb: Major update in v4.0 <
7+
> 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+
---
69

7-
You can sign up for a Stream account at https://getstream.io/chat/get_started/.
10+
The official Python API client for [Stream chat](https://getstream.io/chat/) a service for building chat applications.
811

9-
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 (https://getstream.io/chat/).
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.
1015

1116
### Installation
1217

@@ -34,6 +39,7 @@ pip install stream-chat
3439
- User search
3540
- Channel search
3641
- Campaign API (alpha - susceptible changes and even won't be available in some regions yet)
42+
- Rate limit in response
3743

3844
### Quickstart
3945

@@ -58,6 +64,20 @@ def main():
5864
# add a first message to the channel
5965
channel.send_message({"text": "AMA about kung-fu"}, "chuck")
6066

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
71+
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
74+
75+
headers = resp.headers()
76+
print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }
77+
78+
status_code = resp.status_code()
79+
print(status_code) # 200
80+
6181

6282
if __name__ == '__main__':
6383
main()
@@ -83,6 +103,20 @@ async def main():
83103
# add a first message to the channel
84104
await channel.send_message({"text": "AMA about kung-fu"}, "chuck")
85105

106+
# we also expose some response metadata through a custom dictionary
107+
resp = await chat.deactivate_user("bruce_lee")
108+
print(type(resp)) # <class 'stream_chat.types.stream_response.StreamResponse'>
109+
print(resp["user"]["id"]) # bruce_lee
110+
111+
rate_limit = resp.rate_limit()
112+
print(f"{rate_limit.limit} / {rate_limit.remaining} / {rate_limit.reset}") # 60 / 59 / 2022-01-06 12:35:00+00:00
113+
114+
headers = resp.headers()
115+
print(headers) # { 'Content-Encoding': 'gzip', 'Content-Length': '33', ... }
116+
117+
status_code = resp.status_code()
118+
print(status_code) # 200
119+
86120

87121
if __name__ == '__main__':
88122
loop = asyncio.get_event_loop()

pyproject.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ exclude = '''
2424
)/
2525
'''
2626

27+
[tool.isort]
28+
profile = "black"
29+
src_paths = ["stream_chat"]
30+
known_first_party = ["stream_chat"]
31+
2732
[tool.pytest.ini_options]
2833
testpaths = ["stream_chat/tests"]
2934
asyncio_mode = "auto"

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ci_require = [
1313
"black",
1414
"flake8",
15+
"flake8-isort",
1516
"flake8-bugbear",
1617
"pytest-cov",
1718
"mypy",
@@ -47,7 +48,7 @@
4748
install_requires=install_requires,
4849
extras_require={"test": tests_require, "ci": ci_require},
4950
include_package_data=True,
50-
python_requires=">=3.6",
51+
python_requires=">=3.7",
5152
classifiers=[
5253
"Intended Audience :: Developers",
5354
"Intended Audience :: System Administrators",
@@ -56,7 +57,6 @@
5657
"Development Status :: 5 - Production/Stable",
5758
"Natural Language :: English",
5859
"Programming Language :: Python :: 3",
59-
"Programming Language :: Python :: 3.6",
6060
"Programming Language :: Python :: 3.7",
6161
"Programming Language :: Python :: 3.8",
6262
"Programming Language :: Python :: 3.9",

stream_chat/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .client import StreamChat
21
from .async_chat import StreamChatAsync
2+
from .client import StreamChat
33

44
__all__ = ["StreamChat", "StreamChatAsync"]

stream_chat/async_chat/channel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
from typing import Any, Dict, Iterable, List, Union
33

4-
54
from stream_chat.base.channel import ChannelInterface, add_user_id
65
from stream_chat.types.stream_response import StreamResponse
76

0 commit comments

Comments
 (0)