Skip to content

Commit

Permalink
Additional example (#194)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
seba-aln and pubnub-release-bot authored Aug 13, 2024
1 parent c8bf260 commit e556b7f
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
17 changes: 13 additions & 4 deletions .pubnub.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: python
version: 8.0.0
version: 8.1.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-8.0.0
package-name: pubnub-8.1.0
location: https://pypi.org/project/pubnub/
supported-platforms:
supported-operating-systems:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
47 changes: 47 additions & 0 deletions examples/pubnub_asyncio/file_handling_async.py
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion pubnub/pubnub_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e556b7f

Please sign in to comment.