From e556b7fda9eff0a0ddd7a5fbec522dec8f5a8057 Mon Sep 17 00:00:00 2001 From: Sebastian Molenda Date: Tue, 13 Aug 2024 16:06:15 +0200 Subject: [PATCH] Additional example (#194) * Additional example * ENV key names fixed * PubNub SDK v8.1.0 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 17 +++++-- CHANGELOG.md | 12 +++++ .../pubnub_asyncio/file_handling_async.py | 47 +++++++++++++++++++ pubnub/pubnub_core.py | 2 +- setup.py | 2 +- 5 files changed, 74 insertions(+), 6 deletions(-) create mode 100644 examples/pubnub_asyncio/file_handling_async.py diff --git a/.pubnub.yml b/.pubnub.yml index bc035c3c..0b71126e 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,5 @@ name: python -version: 8.0.0 +version: 8.1.0 schema: 1 scm: github.com/pubnub/python sdks: @@ -18,7 +18,7 @@ sdks: distributions: - distribution-type: library distribution-repository: package - package-name: pubnub-8.0.0 + package-name: pubnub-8.1.0 location: https://pypi.org/project/pubnub/ supported-platforms: supported-operating-systems: @@ -97,8 +97,8 @@ sdks: - distribution-type: library distribution-repository: git release - package-name: pubnub-8.0.0 - location: https://github.com/pubnub/python/releases/download/v8.0.0/pubnub-8.0.0.tar.gz + package-name: pubnub-8.1.0 + location: https://github.com/pubnub/python/releases/download/v8.1.0/pubnub-8.1.0.tar.gz supported-platforms: supported-operating-systems: Linux: @@ -169,6 +169,15 @@ sdks: license-url: https://github.com/aio-libs/aiohttp/blob/master/LICENSE.txt is-required: Required changelog: + - date: 2024-08-13 + version: v8.1.0 + changes: + - type: feature + text: "Option to lock PNConfiguration mutability. Note that mutable config will be deprecated in future major releases." + - type: bug + text: "Fix for routing crypto module if custom one was defined." + - type: improvement + text: "Additional Examples." - date: 2024-05-09 version: v8.0.0 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b10d02..322f4eb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## v8.1.0 +August 13 2024 + +#### Added +- Option to lock PNConfiguration mutability. Note that mutable config will be deprecated in future major releases. + +#### Fixed +- Fix for routing crypto module if custom one was defined. + +#### Modified +- Additional Examples. + ## v8.0.0 May 09 2024 diff --git a/examples/pubnub_asyncio/file_handling_async.py b/examples/pubnub_asyncio/file_handling_async.py new file mode 100644 index 00000000..6cd1285e --- /dev/null +++ b/examples/pubnub_asyncio/file_handling_async.py @@ -0,0 +1,47 @@ +import os + + +from pubnub.pubnub_asyncio import PubNubAsyncio +from pubnub.pnconfiguration import PNConfiguration + + +config = PNConfiguration() +config.publish_key = os.environ.get('PUBLISH_KEY', 'demo') +config.subscribe_request_timeout = 10 +config.subscribe_key = os.environ.get('SUBSCRIBE_KEY', 'demo') +config.enable_subscribe = False +config.uuid = 'example' + +channel = 'file-channel' +pubnub = PubNubAsyncio(config) +sample_path = f"{os.getcwd()}/examples/native_sync/sample.gif" + + +def callback(response, *args): + print(f"Sent file: {response.result.name} with id: {response.result.file_id}," + f" at timestamp: {response.result.timestamp}") + + +with open(sample_path, 'rb') as sample_file: + sample_file.seek(0) + pubnub.send_file() \ + .channel(channel) \ + .file_name("sample.gif") \ + .message({"test_message": "test"}) \ + .file_object(sample_file) \ + .pn_async(callback) + +file_list_response = pubnub.list_files().channel(channel).sync() +print(f"Found {len(file_list_response.result.data)} files:") + +for pos in file_list_response.result.data: + print(f" {pos['name']} with id: {pos['id']}") + ext = pos['name'].replace('sample', '') + download_url = pubnub.get_file_url().channel(channel).file_id(pos['id']).file_name(pos['name']).sync() + print(f' Download url: {download_url.result.file_url}') + download_file = pubnub.download_file().channel(channel).file_id(pos['id']).file_name(pos['name']).sync() + fw = open(f"{os.getcwd()}/examples/native_sync/out-{pos['id']}{ext}", 'wb') + fw.write(download_file.result.data) + print(f" file saved as {os.getcwd()}/examples/native_sync/out-{pos['id']}{ext}\n") + pubnub.delete_file().channel(channel).file_id(pos['id']).file_name(pos['name']).sync() + print(' File deleted from storage') diff --git a/pubnub/pubnub_core.py b/pubnub/pubnub_core.py index e36abca1..60288671 100644 --- a/pubnub/pubnub_core.py +++ b/pubnub/pubnub_core.py @@ -90,7 +90,7 @@ class PubNubCore: """A base class for PubNub Python API implementations""" - SDK_VERSION = "8.0.0" + SDK_VERSION = "8.1.0" SDK_NAME = "PubNub-Python" TIMESTAMP_DIVIDER = 1000 diff --git a/setup.py b/setup.py index 3d9105ba..b0ab0009 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='pubnub', - version='8.0.0', + version='8.1.0', description='PubNub Real-time push service in the cloud', author='PubNub', author_email='support@pubnub.com',