Skip to content

Commit 686b4f4

Browse files
Sebastian Molendapubnub-release-bot
andauthored
Add type hints to customer facing interfaces (#195)
* PubNub SDK v9.0.0 release. --------- Co-authored-by: PubNub Release Bot <[email protected]>
1 parent 0d47e58 commit 686b4f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1231
-549
lines changed

.pubnub.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: python
2-
version: 8.1.0
2+
version: 9.0.0
33
schema: 1
44
scm: github.com/pubnub/python
55
sdks:
@@ -18,7 +18,7 @@ sdks:
1818
distributions:
1919
- distribution-type: library
2020
distribution-repository: package
21-
package-name: pubnub-8.1.0
21+
package-name: pubnub-9.0.0
2222
location: https://pypi.org/project/pubnub/
2323
supported-platforms:
2424
supported-operating-systems:
@@ -97,8 +97,8 @@ sdks:
9797
-
9898
distribution-type: library
9999
distribution-repository: git release
100-
package-name: pubnub-8.1.0
101-
location: https://github.com/pubnub/python/releases/download/v8.1.0/pubnub-8.1.0.tar.gz
100+
package-name: pubnub-9.0.0
101+
location: https://github.com/pubnub/python/releases/download/v9.0.0/pubnub-9.0.0.tar.gz
102102
supported-platforms:
103103
supported-operating-systems:
104104
Linux:
@@ -169,6 +169,19 @@ sdks:
169169
license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt
170170
is-required: Required
171171
changelog:
172+
- date: 2024-10-02
173+
version: v9.0.0
174+
changes:
175+
- type: feature
176+
text: "BREAKING CHANGES: Automatic reconnecting for subscribe with exponential backoff is now enabled by default."
177+
- type: feature
178+
text: "Access manager v2 endpoints (grant and audit) will no longer be supported after December 31, 2024, and will be removed without further notice. Refer to the documentation to learn more."
179+
- type: feature
180+
text: "BREAKING CHANGES: Once used to instantiate PubNub, the configuration object (PNConfiguration instance) becomes immutable. You will receive exceptions if you rely on modifying the configuration after the PubNub instance is created. Refer to the documentation to learn more."
181+
- type: improvement
182+
text: "Type hints for parameters and return values are now added to provide a better developer experience."
183+
- type: improvement
184+
text: "All endpoints are now accessible through the builder pattern and named parameters, providing a more flexible experience suitable for custom solutions."
172185
- date: 2024-08-13
173186
version: v8.1.0
174187
changes:

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## v9.0.0
2+
October 02 2024
3+
4+
#### Added
5+
- BREAKING CHANGES: Automatic reconnecting for subscribe with exponential backoff is now enabled by default.
6+
- Access manager v2 endpoints (grant and audit) will no longer be supported after December 31, 2024, and will be removed without further notice. Refer to the documentation to learn more.
7+
- BREAKING CHANGES: Once used to instantiate PubNub, the configuration object (PNConfiguration instance) becomes immutable. You will receive exceptions if you rely on modifying the configuration after the PubNub instance is created. Refer to the documentation to learn more.
8+
9+
#### Modified
10+
- Type hints for parameters and return values are now added to provide a better developer experience.
11+
- All endpoints are now accessible through the builder pattern and named parameters, providing a more flexible experience suitable for custom solutions.
12+
113
## v8.1.0
214
August 13 2024
315

pubnub/endpoints/access/grant_token.py

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,77 @@
1+
from typing import Union, List, Optional
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_TTL_MISSING, PNERR_INVALID_META, PNERR_RESOURCES_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
7+
from pubnub.models.consumer.common import PNStatus
68
from pubnub.models.consumer.v3.access_manager import PNGrantTokenResult
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNGrantTokenResultEnvelope(Envelope):
13+
result: PNGrantTokenResult
14+
status: PNStatus
715

816

917
class GrantToken(Endpoint):
1018
GRANT_TOKEN_PATH = "/v3/pam/%s/grant"
1119

12-
def __init__(self, pubnub):
20+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_groups: Union[str, List[str]] = None,
21+
users: Union[str, List[str]] = None, spaces: Union[str, List[str]] = None,
22+
authorized_user_id: str = None, ttl: Optional[int] = None, meta: Optional[any] = None):
1323
Endpoint.__init__(self, pubnub)
14-
self._ttl = None
15-
self._meta = None
16-
self._authorized_uuid = None
24+
self._ttl = ttl
25+
self._meta = meta
26+
self._authorized_uuid = authorized_user_id
1727
self._channels = []
28+
if channels:
29+
utils.extend_list(self._channels, channels)
30+
if spaces:
31+
utils.extend_list(self._channels, spaces)
32+
1833
self._groups = []
34+
if channel_groups:
35+
utils.extend_list(self._groups, channel_groups)
1936
self._uuids = []
37+
if users:
38+
utils.extend_list(self._uuids, users)
2039

2140
self._sort_params = True
2241

23-
def ttl(self, ttl):
42+
def ttl(self, ttl: int) -> 'GrantToken':
2443
self._ttl = ttl
2544
return self
2645

27-
def meta(self, meta):
46+
def meta(self, meta: any) -> 'GrantToken':
2847
self._meta = meta
2948
return self
3049

31-
def authorized_uuid(self, uuid):
50+
def authorized_uuid(self, uuid: str) -> 'GrantToken':
3251
self._authorized_uuid = uuid
3352
return self
3453

35-
def authorized_user(self, user):
54+
def authorized_user(self, user) -> 'GrantToken':
3655
self._authorized_uuid = user
3756
return self
3857

39-
def spaces(self, spaces):
58+
def spaces(self, spaces: Union[str, List[str]]) -> 'GrantToken':
4059
self._channels = spaces
4160
return self
4261

43-
def users(self, users):
62+
def users(self, users: Union[str, List[str]]) -> 'GrantToken':
4463
self._uuids = users
4564
return self
4665

47-
def channels(self, channels):
66+
def channels(self, channels: Union[str, List[str]]) -> 'GrantToken':
4867
self._channels = channels
4968
return self
5069

51-
def groups(self, groups):
70+
def groups(self, groups: Union[str, List[str]]) -> 'GrantToken':
5271
self._groups = groups
5372
return self
5473

55-
def uuids(self, uuids):
74+
def uuids(self, uuids: Union[str, List[str]]) -> 'GrantToken':
5675
self._uuids = uuids
5776
return self
5877

@@ -102,9 +121,12 @@ def validate_params(self):
102121
self.validate_ttl()
103122
self.validate_resources()
104123

105-
def create_response(self, envelope):
124+
def create_response(self, envelope) -> PNGrantTokenResult:
106125
return PNGrantTokenResult.from_json(envelope['data'])
107126

127+
def sync(self) -> PNGrantTokenResultEnvelope:
128+
return PNGrantTokenResultEnvelope(super().sync())
129+
108130
def is_auth_required(self):
109131
return False
110132

pubnub/endpoints/access/revoke_token.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
from pubnub.enums import PNOperationType, HttpMethod
22
from pubnub.endpoints.endpoint import Endpoint
3+
from pubnub.models.consumer.common import PNStatus
34
from pubnub.models.consumer.v3.access_manager import PNRevokeTokenResult
45
from pubnub import utils
6+
from pubnub.structures import Envelope
7+
8+
9+
class PNRevokeTokenResultEnvelope(Envelope):
10+
result: PNRevokeTokenResult
11+
status: PNStatus
512

613

714
class RevokeToken(Endpoint):
815
REVOKE_TOKEN_PATH = "/v3/pam/%s/grant/%s"
916

10-
def __init__(self, pubnub, token):
17+
def __init__(self, pubnub, token: str):
1118
Endpoint.__init__(self, pubnub)
1219
self.token = token
1320

@@ -18,6 +25,9 @@ def validate_params(self):
1825
def create_response(self, envelope):
1926
return PNRevokeTokenResult(envelope)
2027

28+
def sync(self) -> PNRevokeTokenResultEnvelope:
29+
return PNRevokeTokenResultEnvelope(super().sync())
30+
2131
def is_auth_required(self):
2232
return False
2333

pubnub/endpoints/channel_groups/add_channel_to_channel_group.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1+
from typing import List, Union
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_CHANNELS_MISSING, PNERR_GROUP_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
67
from pubnub.models.consumer.channel_group import PNChannelGroupsAddChannelResult
8+
from pubnub.models.consumer.common import PNStatus
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNChannelGroupsAddChannelResultEnvelope(Envelope):
13+
result: PNChannelGroupsAddChannelResult
14+
status: PNStatus
715

816

917
class AddChannelToChannelGroup(Endpoint):
1018
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>?add=ch1,ch2
1119
ADD_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
1220

13-
def __init__(self, pubnub):
21+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_group: str = None):
1422
Endpoint.__init__(self, pubnub)
1523
self._channels = []
16-
self._channel_group = None
17-
18-
def channels(self, channels):
19-
if isinstance(channels, (list, tuple)):
20-
self._channels.extend(channels)
21-
else:
22-
self._channels.extend(utils.split_items(channels))
24+
if channels:
25+
utils.extend_list(self._channels, channels)
26+
self._channel_group = channel_group
2327

28+
def channels(self, channels) -> 'AddChannelToChannelGroup':
29+
utils.extend_list(self._channels, channels)
2430
return self
2531

26-
def channel_group(self, channel_group):
32+
def channel_group(self, channel_group: str) -> 'AddChannelToChannelGroup':
2733
self._channel_group = channel_group
28-
2934
return self
3035

3136
def custom_params(self):
@@ -50,9 +55,12 @@ def validate_params(self):
5055
def is_auth_required(self):
5156
return True
5257

53-
def create_response(self, envelope):
58+
def create_response(self, envelope) -> PNChannelGroupsAddChannelResult:
5459
return PNChannelGroupsAddChannelResult()
5560

61+
def sync(self) -> PNChannelGroupsAddChannelResultEnvelope:
62+
return PNChannelGroupsAddChannelResultEnvelope(super().sync())
63+
5664
def request_timeout(self):
5765
return self.pubnub.config.non_subscribe_request_timeout
5866

pubnub/endpoints/channel_groups/list_channels_in_channel_group.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@
44
from pubnub.exceptions import PubNubException
55
from pubnub.enums import HttpMethod, PNOperationType
66
from pubnub.models.consumer.channel_group import PNChannelGroupsListResult
7+
from pubnub.models.consumer.common import PNStatus
8+
from pubnub.structures import Envelope
9+
10+
11+
class PNChannelGroupsListResultEnvelope(Envelope):
12+
result: PNChannelGroupsListResult
13+
status: PNStatus
714

815

916
class ListChannelsInChannelGroup(Endpoint):
1017
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>
1118
LIST_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
1219

13-
def __init__(self, pubnub):
20+
def __init__(self, pubnub, channel_group: str = None):
1421
Endpoint.__init__(self, pubnub)
15-
self._channel_group = None
16-
17-
def channel_group(self, channel_group):
1822
self._channel_group = channel_group
1923

24+
def channel_group(self, channel_group: str) -> 'ListChannelsInChannelGroup':
25+
self._channel_group = channel_group
2026
return self
2127

2228
def custom_params(self):
@@ -35,12 +41,15 @@ def validate_params(self):
3541
if not isinstance(self._channel_group, str) or len(self._channel_group) == 0:
3642
raise PubNubException(pn_error=PNERR_GROUP_MISSING)
3743

38-
def create_response(self, envelope):
44+
def create_response(self, envelope) -> PNChannelGroupsListResult:
3945
if 'payload' in envelope and 'channels' in envelope['payload']:
4046
return PNChannelGroupsListResult(envelope['payload']['channels'])
4147
else:
4248
return PNChannelGroupsListResult([])
4349

50+
def sync(self) -> PNChannelGroupsListResultEnvelope:
51+
return PNChannelGroupsListResultEnvelope(super().sync())
52+
4453
def is_auth_required(self):
4554
return True
4655

pubnub/endpoints/channel_groups/remove_channel_from_channel_group.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,38 @@
1+
from typing import List, Union
12
from pubnub import utils
23
from pubnub.endpoints.endpoint import Endpoint
34
from pubnub.errors import PNERR_CHANNELS_MISSING, PNERR_GROUP_MISSING
45
from pubnub.exceptions import PubNubException
56
from pubnub.enums import HttpMethod, PNOperationType
67
from pubnub.models.consumer.channel_group import PNChannelGroupsRemoveChannelResult
8+
from pubnub.models.consumer.common import PNStatus
9+
from pubnub.structures import Envelope
10+
11+
12+
class PNChannelGroupsRemoveChannelResultEnvelope(Envelope):
13+
result: PNChannelGroupsRemoveChannelResult
14+
status: PNStatus
715

816

917
class RemoveChannelFromChannelGroup(Endpoint):
1018
# /v1/channel-registration/sub-key/<sub_key>/channel-group/<group_name>?remove=ch1,ch2
1119
REMOVE_PATH = "/v1/channel-registration/sub-key/%s/channel-group/%s"
20+
_channels: list = []
21+
_channel_group: str = None
1222

13-
def __init__(self, pubnub):
23+
def __init__(self, pubnub, channels: Union[str, List[str]] = None, channel_group: str = None):
1424
Endpoint.__init__(self, pubnub)
1525
self._channels = []
16-
self._channel_group = None
17-
18-
def channels(self, channels):
19-
if isinstance(channels, (list, tuple)):
20-
self._channels.extend(channels)
21-
else:
22-
self._channels.extend(utils.split_items(channels))
26+
if channels:
27+
utils.extend_list(self._channels, channels)
28+
self._channel_group = channel_group
2329

30+
def channels(self, channels) -> 'RemoveChannelFromChannelGroup':
31+
utils.extend_list(self._channels, channels)
2432
return self
2533

26-
def channel_group(self, channel_group):
34+
def channel_group(self, channel_group: str) -> 'RemoveChannelFromChannelGroup':
2735
self._channel_group = channel_group
28-
2936
return self
3037

3138
def custom_params(self):
@@ -50,9 +57,12 @@ def validate_params(self):
5057
def is_auth_required(self):
5158
return True
5259

53-
def create_response(self, envelope):
60+
def create_response(self, envelope) -> PNChannelGroupsRemoveChannelResult:
5461
return PNChannelGroupsRemoveChannelResult()
5562

63+
def sync(self) -> PNChannelGroupsRemoveChannelResultEnvelope:
64+
return PNChannelGroupsRemoveChannelResultEnvelope(super().sync())
65+
5666
def request_timeout(self):
5767
return self.pubnub.config.non_subscribe_request_timeout
5868

0 commit comments

Comments
 (0)