diff --git a/app/config/platforms.php b/app/config/platforms.php index ec1507c50d..b424b06e5e 100644 --- a/app/config/platforms.php +++ b/app/config/platforms.php @@ -195,7 +195,7 @@ return [ [ 'key' => 'python', 'name' => 'Python', - 'version' => '0.0.5', + 'version' => '0.0.6', 'url' => 'https://github.com/appwrite/sdk-for-python', 'enabled' => true, 'beta' => true, diff --git a/app/sdks/server-python/README.md b/app/sdks/server-python/README.md index 1d5c72a9c4..04421ff241 100644 --- a/app/sdks/server-python/README.md +++ b/app/sdks/server-python/README.md @@ -1,9 +1,9 @@ # Appwrite Python SDK ![License](https://img.shields.io/github/license/appwrite/sdk-for-python.svg?v=1) -![Version](https://img.shields.io/badge/api%20version-0.6.1-blue.svg?v=1) +![Version](https://img.shields.io/badge/api%20version-0.6.2-blue.svg?v=1) -**This SDK is compatible with Appwrite server version 0.6.1. For older versions, please check previous releases.** +**This SDK is compatible with Appwrite server version 0.6.2. For older versions, please check previous releases.** Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Python SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. @@ -27,4 +27,4 @@ This library is auto-generated by Appwrite custom [SDK Generator](https://github ## License -Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. \ No newline at end of file +Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information. diff --git a/app/sdks/server-python/appwrite/client.py b/app/sdks/server-python/appwrite/client.py index a9d0bf8a1b..8989fccb9c 100644 --- a/app/sdks/server-python/appwrite/client.py +++ b/app/sdks/server-python/appwrite/client.py @@ -1,13 +1,13 @@ +import io import requests - class Client: def __init__(self): self._self_signed = False self._endpoint = 'https://appwrite.io/v1' self._global_headers = { 'content-type': '', - 'x-sdk-version': 'appwrite:python:0.0.5', + 'x-sdk-version': 'appwrite:python:0.0.6', } def set_self_signed(self, status=True): @@ -47,24 +47,34 @@ class Client: data = {} json = {} + files = {} - self._global_headers.update(headers) + headers = {**self._global_headers, **headers} if method != 'get': data = params params = {} - if headers['content-type'] == 'application/json': + if headers['content-type'].startswith('application/json'): json = data data = {} + if headers['content-type'].startswith('multipart/form-data'): + del headers['content-type'] + + for key in data.copy(): + if isinstance(data[key], io.BufferedIOBase): + files[key] = data[key] + del data[key] + response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554 method=method, url=self._endpoint + path, - params=params, - data=data, + params=self.flatten(params), + data=self.flatten(data), json=json, - headers=self._global_headers, + files=files, + headers=headers, verify=self._self_signed, ) @@ -77,3 +87,20 @@ class Client: return response._content + def flatten(self, data, prefix=''): + output = {} + i = 0 + + for key in data: + value = data[key] if isinstance(data, dict) else key + finalKey = prefix + '[' + key +']' if prefix else key + finalKey = prefix + '[' + str(i) +']' if isinstance(data, list) else finalKey + i += 1 + + if isinstance(value, list) or isinstance(value, dict): + output = {**output, **self.flatten(value, finalKey)} + else: + output[finalKey] = value + + return output + diff --git a/app/sdks/server-python/docs/examples/database/create-collection.md b/app/sdks/server-python/docs/examples/database/create-collection.md index 357757880c..8741c13744 100644 --- a/app/sdks/server-python/docs/examples/database/create-collection.md +++ b/app/sdks/server-python/docs/examples/database/create-collection.md @@ -11,4 +11,4 @@ client = Client() database = Database(client) -result = database.create_collection('[NAME]', {}, {}, {}) +result = database.create_collection('[NAME]', [], [], []) diff --git a/app/sdks/server-python/docs/examples/database/create-document.md b/app/sdks/server-python/docs/examples/database/create-document.md index f8bcdef562..fff7a96bc0 100644 --- a/app/sdks/server-python/docs/examples/database/create-document.md +++ b/app/sdks/server-python/docs/examples/database/create-document.md @@ -11,4 +11,4 @@ client = Client() database = Database(client) -result = database.create_document('[COLLECTION_ID]', {}, {}, {}) +result = database.create_document('[COLLECTION_ID]', {}, [], []) diff --git a/app/sdks/server-python/docs/examples/database/update-collection.md b/app/sdks/server-python/docs/examples/database/update-collection.md index ef1a65a67d..0bf8f29fb8 100644 --- a/app/sdks/server-python/docs/examples/database/update-collection.md +++ b/app/sdks/server-python/docs/examples/database/update-collection.md @@ -11,4 +11,4 @@ client = Client() database = Database(client) -result = database.update_collection('[COLLECTION_ID]', '[NAME]', {}, {}) +result = database.update_collection('[COLLECTION_ID]', '[NAME]', [], []) diff --git a/app/sdks/server-python/docs/examples/database/update-document.md b/app/sdks/server-python/docs/examples/database/update-document.md index a3c9fe0b0b..40e11c0665 100644 --- a/app/sdks/server-python/docs/examples/database/update-document.md +++ b/app/sdks/server-python/docs/examples/database/update-document.md @@ -11,4 +11,4 @@ client = Client() database = Database(client) -result = database.update_document('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, {}, {}) +result = database.update_document('[COLLECTION_ID]', '[DOCUMENT_ID]', {}, [], []) diff --git a/app/sdks/server-python/docs/examples/storage/create-file.md b/app/sdks/server-python/docs/examples/storage/create-file.md index 045ef3adc3..fd76dd068b 100644 --- a/app/sdks/server-python/docs/examples/storage/create-file.md +++ b/app/sdks/server-python/docs/examples/storage/create-file.md @@ -11,4 +11,4 @@ client = Client() storage = Storage(client) -result = storage.create_file(document.getElementById('uploader').files[0], {}, {}) +result = storage.create_file(open('/path/to/file.png', 'rb'), [], []) diff --git a/app/sdks/server-python/docs/examples/storage/update-file.md b/app/sdks/server-python/docs/examples/storage/update-file.md index d1085e7df8..5001cbae74 100644 --- a/app/sdks/server-python/docs/examples/storage/update-file.md +++ b/app/sdks/server-python/docs/examples/storage/update-file.md @@ -11,4 +11,4 @@ client = Client() storage = Storage(client) -result = storage.update_file('[FILE_ID]', {}, {}) +result = storage.update_file('[FILE_ID]', [], []) diff --git a/app/sdks/server-python/docs/examples/teams/create-membership.md b/app/sdks/server-python/docs/examples/teams/create-membership.md index 5b68051829..e72ddc6fe3 100644 --- a/app/sdks/server-python/docs/examples/teams/create-membership.md +++ b/app/sdks/server-python/docs/examples/teams/create-membership.md @@ -11,4 +11,4 @@ client = Client() teams = Teams(client) -result = teams.create_membership('[TEAM_ID]', 'email@example.com', {}, 'https://example.com') +result = teams.create_membership('[TEAM_ID]', 'email@example.com', [], 'https://example.com') diff --git a/app/sdks/server-python/setup.py b/app/sdks/server-python/setup.py index 4903197191..8e2fd0c3cb 100644 --- a/app/sdks/server-python/setup.py +++ b/app/sdks/server-python/setup.py @@ -3,7 +3,7 @@ import setuptools setuptools.setup( name = 'appwrite', packages = ['appwrite', 'appwrite/services'], - version = '0.0.5', + version = '0.0.6', license='BSD-3-Clause', description = 'Appwrite is an open-source self-hosted backend server that abstract and simplify complex and repetitive development tasks behind a very simple REST API', author = 'Appwrite Team', @@ -11,7 +11,7 @@ setuptools.setup( maintainer = 'Appwrite Team', maintainer_email = 'team@localhost.test', url = 'https://appwrite.io/support', - download_url='https://github.com/appwrite/sdk-for-python/archive/0.0.5.tar.gz', + download_url='https://github.com/appwrite/sdk-for-python/archive/0.0.6.tar.gz', # keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'], install_requires=[ 'requests', @@ -23,7 +23,6 @@ setuptools.setup( 'Topic :: Software Development', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', diff --git a/composer.lock b/composer.lock index d87e0daf9d..d4d95b4b55 100644 --- a/composer.lock +++ b/composer.lock @@ -1923,7 +1923,7 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator", - "reference": "43d15fc337bcbfe480f2a5503bd7c0615743035b" + "reference": "404cf6bb4c75f8ae3b2419e04f6afd215ed706a5" }, "require": { "ext-curl": "*", @@ -1953,7 +1953,7 @@ } ], "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", - "time": "2020-07-26T09:32:03+00:00" + "time": "2020-07-26T07:11:06+00:00" }, { "name": "doctrine/instantiator",