Skip to content

Commit cd6c8f8

Browse files
committed
Updated file uploads
1 parent 94876ad commit cd6c8f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+107
-20
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Appwrite Python SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-python.svg?v=1)
4-
![Version](https://img.shields.io/badge/api%20version-0.6.0-blue.svg?v=1)
4+
![Version](https://img.shields.io/badge/api%20version-0.6.2-blue.svg?v=1)
55

6-
**This SDK is compatible with Appwrite server version 0.6.0. For older versions, please check previous releases.**
6+
**This SDK is compatible with Appwrite server version 0.6.2. For older versions, please check previous releases.**
77

88
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.
99
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
2727

2828
## License
2929

30-
Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.
30+
Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.

appwrite/client.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import io
12
import requests
23

3-
44
class Client:
55
def __init__(self):
66
self._self_signed = False
77
self._endpoint = 'https://appwrite.io/v1'
88
self._global_headers = {
99
'content-type': '',
10-
'x-sdk-version': 'appwrite:python:0.0.5',
10+
'x-sdk-version': 'appwrite:python:0.0.6',
1111
}
1212

1313
def set_self_signed(self, status=True):
@@ -47,24 +47,34 @@ def call(self, method, path='', headers=None, params=None):
4747

4848
data = {}
4949
json = {}
50+
files = {}
5051

51-
self._global_headers.update(headers)
52+
headers = {**self._global_headers, **headers}
5253

5354
if method != 'get':
5455
data = params
5556
params = {}
5657

57-
if headers['content-type'] == 'application/json':
58+
if headers['content-type'].startswith('application/json'):
5859
json = data
5960
data = {}
6061

62+
if headers['content-type'].startswith('multipart/form-data'):
63+
del headers['content-type']
64+
65+
for key in data.copy():
66+
if isinstance(data[key], io.BufferedIOBase):
67+
files[key] = data[key]
68+
del data[key]
69+
6170
response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554
6271
method=method,
6372
url=self._endpoint + path,
64-
params=params,
65-
data=data,
73+
params=self.flatten(params),
74+
data=self.flatten(data),
6675
json=json,
67-
headers=self._global_headers,
76+
files=files,
77+
headers=headers,
6878
verify=self._self_signed,
6979
)
7080

@@ -77,3 +87,20 @@ def call(self, method, path='', headers=None, params=None):
7787

7888
return response._content
7989

90+
def flatten(self, data, prefix=''):
91+
output = {}
92+
i = 0
93+
94+
for key in data:
95+
value = data[key] if isinstance(data, dict) else key
96+
finalKey = prefix + '[' + key +']' if prefix else key
97+
finalKey = prefix + '[' + str(i) +']' if isinstance(data, list) else finalKey
98+
i += 1
99+
100+
if isinstance(value, list) or isinstance(value, dict):
101+
output = {**output, **self.flatten(value, finalKey)}
102+
else:
103+
output[finalKey] = value
104+
105+
return output
106+

docs/examples/avatars/get-browser.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/avatars/get-credit-card.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/avatars/get-favicon.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/avatars/get-flag.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/avatars/get-image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/avatars/get-q-r.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ from appwrite.services.avatars import Avatars
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)

docs/examples/database/create-collection.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ from appwrite.services.database import Database
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)
1011

1112
database = Database(client)
1213

13-
result = database.create_collection('[NAME]', {}, {}, {})
14+
result = database.create_collection('[NAME]', [], [], [])

docs/examples/database/create-document.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ from appwrite.services.database import Database
44
client = Client()
55

66
(client
7+
.set_endpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
78
.set_project('5df5acd0d48c2') # Your project ID
89
.set_key('919c2d18fb5d4...a2ae413da83346ad2') # Your secret API key
910
)
1011

1112
database = Database(client)
1213

13-
result = database.create_document('[COLLECTION_ID]', {}, {}, {})
14+
result = database.create_document('[COLLECTION_ID]', {}, [], [])

0 commit comments

Comments
 (0)