Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 37 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: python
version: 10.8.1
version: 10.9.0
schema: 1
scm: github.com/pubnub/python
sdks:
Expand All @@ -18,7 +18,7 @@ sdks:
distributions:
- distribution-type: library
distribution-repository: package
package-name: pubnub-10.8.1
package-name: pubnub-10.9.0
location: https://pypi.org/project/pubnub/
supported-platforms:
supported-operating-systems:
Expand Down Expand Up @@ -94,8 +94,8 @@ sdks:
-
distribution-type: library
distribution-repository: git release
package-name: pubnub-10.8.1
location: https://github.com/pubnub/python/releases/download/10.8.1/pubnub-10.8.1.tar.gz
package-name: pubnub-10.9.0
location: https://github.com/pubnub/python/releases/download/10.9.0/pubnub-10.9.0.tar.gz
supported-platforms:
supported-operating-systems:
Linux:
Expand Down Expand Up @@ -169,6 +169,39 @@ sdks:
license-url: https://github.com/encode/httpx/blob/master/LICENSE.md
is-required: Required
changelog:
- date: 2026-11-20
version: 10.9.0
changes:
- type: feature
text: "Stop the subscribe loop and heartbeat timer without removing the subscriptions. The event engine subscription manager, the default for `PubNubAsyncio`, raises a clear `PubNubException`."
- type: bug
text: "`reconnect()` always raised `AttributeError`. It now restarts the subscribe loop for the threaded and legacy asyncio subscription managers, and raises a clear `PubNubException` with the event engine subscription manager."
- type: bug
text: "Channel, user and membership (App Context) and file events are now delivered to subscription and subscription set listeners instead of raising on the first event."
- type: bug
text: "Listeners added with `subscription.add_listener()` now receive events with the correct callback signature instead of raising `TypeError`."
- type: bug
text: "Fix subscription registry removal for subscription sets sharing channels, `unsubscribe_all` with a following `subscribe()`, a set `unsubscribe()` that sent an empty request, and the `PubNubUserMetadata` subscription type."
- type: bug
text: "Both calls no longer raise `AttributeError` with the asyncio event engine before the first subscribe."
- type: bug
text: "`get_message_actions` now sends `end` together with `start`, and `limit()` no longer accepts only `str`."
- type: bug
text: "Message action events now carry the `event` type (`added` or `removed`)."
- type: bug
text: "`custom_message_type` is now parsed on items from fetch messages."
- type: bug
text: "`MembershipIncludes(total_count=True)` and `MemberIncludes(total_count=True)` now send `count=true` on App Context requests."
- type: bug
text: "The `If-Match` header set by `if_matches_etag` no longer leaks into other App Context requests through a shared class-level dict."
- type: bug
text: "`parse_token` now raises `PubNubException` for malformed tokens instead of `binascii.Error` or `TypeError`."
- type: bug
text: "Grant now accepts `delete` as the only permission flag instead of raising a no-flags error."
- type: bug
text: "Relax `aiohttp>3.10.11` to `>=3.10.11` so it overlaps the dev pin and pip can resolve both."
- type: improvement
text: "Add offline unit tests for the subscription registry, message worker events, `get_message_actions` parameters and the other fixes, and re-record the App Context include cassettes with `count=True`."
- date: 2026-10-26
version: 10.8.1
changes:
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## 10.9.0
November 20 2026

#### Added
- Stop the subscribe loop and heartbeat timer without removing the subscriptions. The event engine subscription manager, the default for `PubNubAsyncio`, raises a clear `PubNubException`.

#### Fixed
- `reconnect()` always raised `AttributeError`. It now restarts the subscribe loop for the threaded and legacy asyncio subscription managers, and raises a clear `PubNubException` with the event engine subscription manager.
- Channel, user and membership (App Context) and file events are now delivered to subscription and subscription set listeners instead of raising on the first event.
- Listeners added with `subscription.add_listener()` now receive events with the correct callback signature instead of raising `TypeError`.
- Fix subscription registry removal for subscription sets sharing channels, `unsubscribe_all` with a following `subscribe()`, a set `unsubscribe()` that sent an empty request, and the `PubNubUserMetadata` subscription type.
- Both calls no longer raise `AttributeError` with the asyncio event engine before the first subscribe.
- `get_message_actions` now sends `end` together with `start`, and `limit()` no longer accepts only `str`.
- Message action events now carry the `event` type (`added` or `removed`).
- `custom_message_type` is now parsed on items from fetch messages.
- `MembershipIncludes(total_count=True)` and `MemberIncludes(total_count=True)` now send `count=true` on App Context requests.
- The `If-Match` header set by `if_matches_etag` no longer leaks into other App Context requests through a shared class-level dict.
- `parse_token` now raises `PubNubException` for malformed tokens instead of `binascii.Error` or `TypeError`.
- Grant now accepts `delete` as the only permission flag instead of raising a no-flags error.
- Relax `aiohttp>3.10.11` to `>=3.10.11` so it overlaps the dev pin and pip can resolve both.

#### Modified
- Add offline unit tests for the subscription registry, message worker events, `get_message_actions` parameters and the other fixes, and re-record the App Context include cassettes with `count=True`.

## 10.8.1
October 26 2026

Expand Down
9 changes: 5 additions & 4 deletions examples/native_sync/message_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ def main() -> None:
assert len(messages[0].actions) >= 2, "Unexpected number of actions in history"

# Step 4: Retrieve all reactions for the message
# We use a time window around the message timetoken to fetch reactions
# The window is 1000 time units before and after the message
start_timetoken = str(int(message_timetoken) - 1000)
end_timetoken = str(int(message_timetoken) + 1000)
# The range is made of action timetokens. start is the newer bound (exclusive) and end is the older bound
# (inclusive), so start must be greater than end. Reactions are added after the message, hence the message
# timetoken is a safe older bound and the newest reaction plus one is the newer bound.
start_timetoken = str(int(second_reaction.action_timetoken) + 1)
end_timetoken = str(message_timetoken)
reactions = get_reactions(pubnub, channel, start_timetoken, end_timetoken, "100")
print(f"Reactions found: {len(reactions.actions)}")
assert len(reactions.actions) >= 2, "Unexpected number of reactions"
Expand Down
2 changes: 1 addition & 1 deletion pubnub/endpoints/access/grant.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def validate_params(self):
)

if self._write is None and self._read is None and self._manage is None and self._get is None \
and self._update is None and self._join is None:
and self._update is None and self._join is None and self._delete is None:
raise PubNubException(pn_error=PNERR_PAM_NO_FLAGS)

self.validate_categories()
Expand Down
2 changes: 1 addition & 1 deletion pubnub/endpoints/message_actions/get_message_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def custom_params(self):
if self._start is not None:
params['start'] = self._start

if self._end is not None and self._start is None:
if self._end is not None:
params['end'] = self._end

if self._limit != GetMessageActions.MAX_LIMIT:
Expand Down
10 changes: 6 additions & 4 deletions pubnub/endpoints/objects_v2/objects_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ObjectsEndpoint(Endpoint):

__if_matches_etag: str = None

_custom_headers: dict = {}
_custom_headers: dict = None

def __init__(self, pubnub):
Endpoint.__init__(self, pubnub)
Expand All @@ -42,7 +42,9 @@ def validate_specific_params(self):

def if_matches_etag(self, etag: str):
self.__if_matches_etag = etag
self._custom_headers.update({"If-Match": etag})
# copy so the header stays on this request and never lands on a shared dict
self._custom_headers = dict(self._custom_headers or {})
self._custom_headers["If-Match"] = etag
return self

def encoded_params(self):
Expand All @@ -67,8 +69,8 @@ def custom_params(self):
if self._limit:
params["limit"] = int(self._limit)

if self._include_total_count:
params["count"] = bool(self._include_total_count)
if self._include_total_count or getattr(self._includes, 'total_count', False):
params["count"] = True

if self._sort_keys:
joined_sort_params_array = []
Expand Down
6 changes: 6 additions & 0 deletions pubnub/event_engine/models/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class PNContext(dict):
reason: PubNubException
with_presence: bool = False

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# read by get_subscribed_channels() and unsubscribe_all() before the first subscribe
self.channels = []
self.groups = []

def update(self, context):
super().update(context.__dict__)

Expand Down
25 changes: 22 additions & 3 deletions pubnub/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from abc import abstractmethod, ABCMeta

import base64
import binascii
import random

from cbor2 import loads
Expand Down Expand Up @@ -401,6 +402,14 @@ def get_token(self):
def parse_token(cls, token):
token = cls.unwrap_token(token)

try:
return cls._parse_unwrapped_token(token)
except (KeyError, TypeError, AttributeError, ValueError):
raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN,
errormsg="token payload is missing required fields or has the wrong shape")

@staticmethod
def _parse_unwrapped_token(token):
parsed_token = {
"version": token["v"],
"timestamp": token["t"],
Expand Down Expand Up @@ -444,13 +453,23 @@ def parse_token(cls, token):

@staticmethod
def unwrap_token(token):
if not isinstance(token, str) or len(token) == 0:
raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN, errormsg="token must be a non-empty string")

token = token.replace("_", "/").replace("-", "+")
byte_array = base64.b64decode(token)

try:
byte_array = base64.b64decode(token)
except (binascii.Error, ValueError):
raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN, errormsg="token is not valid base64")

try:
unwrapped_obj = loads(byte_array)
decoded_obj = utils.decode_utf8_dict(unwrapped_obj)

return decoded_obj
except Exception:
raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN)

if not isinstance(decoded_obj, dict):
raise PubNubException(pn_error=PNERR_INVALID_ACCESS_TOKEN, errormsg="token payload is not a map")

return decoded_obj
3 changes: 3 additions & 0 deletions pubnub/models/consumer/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def from_json(cls, json_input, include_message_actions=False, start_timetoken=No
message.uuid = item['uuid']
if 'message_type' in item:
message.message_type = item['message_type']
if 'custom_message_type' in item:
message.custom_message_type = item['custom_message_type']

if 'meta' in item:
message.meta = item['meta']
Expand All @@ -118,6 +120,7 @@ def __init__(self, message, timetoken, meta=None, actions=None, error: Exception
self.timetoken = timetoken
self.actions = actions
self.error = error
self.custom_message_type = None

def __str__(self):
return "Fetch message item with tt: %s and content: %s" % (self.timetoken, self.message)
5 changes: 4 additions & 1 deletion pubnub/models/consumer/objects_v2/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def __str__(self):


class PNChannelMetadataResult(object):
def __init__(self, event, data):
def __init__(self, event, data, *, channel=None, subscription=None):
self.data = data
self.event = event
# subscription and subscription set listeners match App Context events by these two attributes
self.channel = channel
self.subscription = subscription

def __str__(self):
return "Channel %s event with data: %s" % (self.event, self.data)
5 changes: 4 additions & 1 deletion pubnub/models/consumer/objects_v2/memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ def __str__(self):


class PNMembershipResult(object):
def __init__(self, event, data):
def __init__(self, event, data, *, channel=None, subscription=None):
self.data = data
self.event = event
# subscription and subscription set listeners match App Context events by these two attributes
self.channel = channel
self.subscription = subscription

def __str__(self):
return "Membership %s event with data: %s" % (self.event, self.data)
5 changes: 4 additions & 1 deletion pubnub/models/consumer/objects_v2/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def __str__(self):


class PNUUIDMetadataResult(object):
def __init__(self, event, data):
def __init__(self, event, data, *, channel=None, subscription=None):
self.data = data
self.event = event
# subscription and subscription set listeners match App Context events by these two attributes
self.channel = channel
self.subscription = subscription

def __str__(self):
return "UUID %s event with data: %s" % (self.event, self.data)
2 changes: 2 additions & 0 deletions pubnub/models/consumer/pubsub.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def __init__(self, result, *, subscription=None, channel=None):
super(PNMessageActionResult, self).__init__(result)
self.subscription = subscription
self.channel = channel
# 'added' or 'removed', set by the subscribe message worker from the event payload
self.event = None


class PNPublishResult(object):
Expand Down
Loading
Loading