1
0
Fork 0
mirror of synced 2024-06-23 08:40:58 +12:00

Updated Python SDK

This commit is contained in:
Eldad Fux 2020-07-26 10:14:51 +03:00
parent 571f7fb8b8
commit 9f6080ae7b
11 changed files with 469 additions and 159 deletions

View file

@ -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.
Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.

View file

@ -1,6 +1,6 @@
import io
import requests
class Client:
def __init__(self):
self._self_signed = False
@ -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

View file

@ -11,4 +11,4 @@ client = Client()
database = Database(client)
result = database.create_collection('[NAME]', {}, {}, {})
result = database.create_collection('[NAME]', [], [], [])

View file

@ -11,4 +11,4 @@ client = Client()
database = Database(client)
result = database.create_document('[COLLECTION_ID]', {}, {}, {})
result = database.create_document('[COLLECTION_ID]', {}, [], [])

View file

@ -11,4 +11,4 @@ client = Client()
database = Database(client)
result = database.update_collection('[COLLECTION_ID]', '[NAME]', {}, {})
result = database.update_collection('[COLLECTION_ID]', '[NAME]', [], [])

View file

@ -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]', {}, [], [])

View file

@ -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'), [], [])

View file

@ -11,4 +11,4 @@ client = Client()
storage = Storage(client)
result = storage.update_file('[FILE_ID]', {}, {})
result = storage.update_file('[FILE_ID]', [], [])

View file

@ -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')

View file

@ -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',

568
composer.lock generated

File diff suppressed because it is too large Load diff