Merge pull request #155 from appwrite/dev · appwrite/sdk-for-python@a3df648 · GitHub
Skip to content

Commit a3df648

Browse files
authored
Merge pull request #155 from appwrite/dev
feat: SDK update for version 24.0.0rc1
2 parents 5eef1a7 + 05cbbcd commit a3df648

734 files changed

Lines changed: 37864 additions & 15506 deletions

File tree

Some content is hidden

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

‎CHANGELOG.md‎

Lines changed: 18 additions & 0 deletions

‎appwrite/__init__.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

‎appwrite/client.py‎

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
from .exception import AppwriteException
1111
from .encoders.value_class_encoder import ValueClassEncoder
1212

13+
1314
class Client:
1415
def __init__(self):
15-
self._chunk_size = 5*1024*1024
16+
self._chunk_size = 5 * 1024 * 1024
1617
self._self_signed = False
1718
self._endpoint = 'https://cloud.appwrite.io/v1'
1819
self._global_headers = {
1920
'content-type': '',
20-
'user-agent' : f'AppwritePythonSDK/23.0.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
21+
'user-agent': f'AppwritePythonSDK/24.0.0rc1 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
2122
'x-sdk-name': 'Python',
2223
'x-sdk-platform': 'server',
2324
'x-sdk-language': 'python',
24-
'x-sdk-version': '23.0.0',
25-
'X-Appwrite-Response-Format' : '1.9.6',
25+
'x-sdk-version': '24.0.0rc1',
26+
'X-Appwrite-Response-Format': '1.9.6',
2627
}
2728
self._config = {}
2829

@@ -174,7 +175,7 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
174175
files=files,
175176
headers=headers,
176177
verify=(not self._self_signed),
177-
allow_redirects=False if response_type == 'location' else True
178+
allow_redirects=False if response_type == 'location' else True,
178179
)
179180

180181
response.raise_for_status()
@@ -197,7 +198,9 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
197198
if response != None:
198199
content_type = response.headers['Content-Type']
199200
if content_type.startswith('application/json'):
200-
raise AppwriteException(response.json()['message'], response.status_code, response.json().get('type'), response.text)
201+
raise AppwriteException(
202+
response.json()['message'], response.status_code, response.json().get('type'), response.text
203+
)
201204
else:
202205
raise AppwriteException(response.text, response.status_code, None, response.text)
203206
else:
@@ -206,11 +209,11 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
206209
def chunked_upload(
207210
self,
208211
path,
209-
headers = None,
210-
params = None,
211-
param_name = '',
212-
on_progress = None,
213-
upload_id = ''
212+
headers=None,
213+
params=None,
214+
param_name='',
215+
on_progress=None,
216+
upload_id='',
214217
):
215218
input_file = params[param_name]
216219

@@ -227,21 +230,17 @@ def chunked_upload(
227230
input_file.data = input.read()
228231

229232
params[param_name] = input_file
230-
return self.call(
231-
'post',
232-
path,
233-
headers,
234-
params
235-
)
233+
return self.call('post', path, headers, params)
236234

237235
offset = 0
238236
counter = 0
239237

240-
try:
241-
result = self.call('get', path + '/' + upload_id, headers)
242-
counter = result['chunksUploaded']
243-
except:
244-
pass
238+
if upload_id:
239+
try:
240+
result = self.call('get', path + '/' + upload_id, headers)
241+
counter = result['chunksUploaded']
242+
except:
243+
pass
245244

246245
if counter > 0:
247246
offset = counter * self._chunk_size
@@ -250,11 +249,13 @@ def chunked_upload(
250249
chunks = []
251250
while offset < size:
252251
end = min(offset + self._chunk_size, size)
253-
chunks.append({
254-
'index': counter,
255-
'start': offset,
256-
'end': end,
257-
})
252+
chunks.append(
253+
{
254+
'index': counter,
255+
'start': offset,
256+
'end': end,
257+
}
258+
)
258259
offset = end
259260
counter = counter + 1
260261

@@ -286,7 +287,7 @@ def upload_chunk(chunk, current_upload_id):
286287
chunk_input = InputFile.from_bytes(
287288
read_chunk(chunk['start'], chunk['end']),
288289
input_file.filename,
289-
getattr(input_file, 'mime_type', None)
290+
getattr(input_file, 'mime_type', None),
290291
)
291292
chunk_params = {**params, param_name: chunk_input}
292293
chunk_headers = {**headers}
@@ -310,13 +311,15 @@ def upload_chunk(chunk, current_upload_id):
310311
uploaded_size = chunks[0]['end']
311312

312313
if on_progress is not None:
313-
on_progress({
314-
"$id": result.get("$id"),
315-
"progress": uploaded_size / size * 100,
316-
"sizeUploaded": uploaded_size,
317-
"chunksTotal": total_chunks,
318-
"chunksUploaded": completed_count,
319-
})
314+
on_progress(
315+
{
316+
"$id": result.get("$id"),
317+
"progress": uploaded_size / size * 100,
318+
"sizeUploaded": uploaded_size,
319+
"chunksTotal": total_chunks,
320+
"chunksUploaded": completed_count,
321+
}
322+
)
320323

321324
def upload_remaining_chunk(chunk):
322325
nonlocal completed_count, uploaded_size, last_result, final_result
@@ -328,13 +331,15 @@ def upload_remaining_chunk(chunk):
328331
if is_upload_complete(chunk_result):
329332
final_result = chunk_result
330333
if on_progress is not None:
331-
on_progress({
332-
"$id": upload_id_header,
333-
"progress": uploaded_size / size * 100,
334-
"sizeUploaded": uploaded_size,
335-
"chunksTotal": total_chunks,
336-
"chunksUploaded": completed_count,
337-
})
334+
on_progress(
335+
{
336+
"$id": upload_id_header,
337+
"progress": uploaded_size / size * 100,
338+
"sizeUploaded": uploaded_size,
339+
"chunksTotal": total_chunks,
340+
"chunksUploaded": completed_count,
341+
}
342+
)
338343

339344
with ThreadPoolExecutor(max_workers=8) as executor:
340345
futures = [executor.submit(upload_remaining_chunk, chunk) for chunk in chunks[1:]]
@@ -349,8 +354,8 @@ def flatten(self, data, prefix='', stringify=False):
349354

350355
for key in data:
351356
value = data[key] if isinstance(data, dict) else key
352-
finalKey = prefix + '[' + key +']' if prefix else key
353-
finalKey = prefix + '[' + str(i) +']' if isinstance(data, list) else finalKey
357+
finalKey = prefix + '[' + key + ']' if prefix else key
358+
finalKey = prefix + '[' + str(i) + ']' if isinstance(data, list) else finalKey
354359
i += 1
355360

356361
if isinstance(value, list) or isinstance(value, dict):

‎appwrite/encoders/__init__.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

‎appwrite/encoders/value_class_encoder.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ..enums.relation_mutate import RelationMutate
1616
from ..enums.databases_index_type import DatabasesIndexType
1717
from ..enums.order_by import OrderBy
18+
from ..enums.documents_db_index_type import DocumentsDBIndexType
1819
from ..enums.embedding_model import EmbeddingModel
1920
from ..enums.runtime import Runtime
2021
from ..enums.project_key_scopes import ProjectKeyScopes
@@ -47,12 +48,14 @@
4748
from ..enums.tables_db_index_type import TablesDBIndexType
4849
from ..enums.password_hash import PasswordHash
4950
from ..enums.messaging_provider_type import MessagingProviderType
51+
from ..enums.vectors_db_index_type import VectorsDBIndexType
5052
from ..enums.database_type import DatabaseType
5153
from ..enums.database_status import DatabaseStatus
5254
from ..enums.attribute_status import AttributeStatus
5355
from ..enums.column_status import ColumnStatus
5456
from ..enums.index_status import IndexStatus
5557
from ..enums.deployment_status import DeploymentStatus
58+
from ..enums.execution_resource_type import ExecutionResourceType
5659
from ..enums.execution_trigger import ExecutionTrigger
5760
from ..enums.execution_status import ExecutionStatus
5861
from ..enums.o_auth2_google_prompt import OAuth2GooglePrompt
@@ -63,6 +66,7 @@
6366
from ..enums.message_status import MessageStatus
6467
from ..enums.billing_plan_group import BillingPlanGroup
6568

69+
6670
class ValueClassEncoder(json.JSONEncoder):
6771
def default(self, o):
6872
if isinstance(o, AppwriteModel):
@@ -113,6 +117,9 @@ def default(self, o):
113117
if isinstance(o, OrderBy):
114118
return o.value
115119

120+
if isinstance(o, DocumentsDBIndexType):
121+
return o.value
122+
116123
if isinstance(o, EmbeddingModel):
117124
return o.value
118125

@@ -209,6 +216,9 @@ def default(self, o):
209216
if isinstance(o, MessagingProviderType):
210217
return o.value
211218

219+
if isinstance(o, VectorsDBIndexType):
220+
return o.value
221+
212222
if isinstance(o, DatabaseType):
213223
return o.value
214224

@@ -227,6 +237,9 @@ def default(self, o):
227237
if isinstance(o, DeploymentStatus):
228238
return o.value
229239

240+
if isinstance(o, ExecutionResourceType):
241+
return o.value
242+
230243
if isinstance(o, ExecutionTrigger):
231244
return o.value
232245

‎appwrite/enums/__init__.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

‎appwrite/enums/adapter.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
34
class Adapter(Enum):
45
STATIC = "static"
56
SSR = "ssr"

‎appwrite/enums/attribute_status.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
34
class AttributeStatus(Enum):
45
AVAILABLE = "available"
56
PROCESSING = "processing"

‎appwrite/enums/authentication_factor.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from enum import Enum
22

3+
34
class AuthenticationFactor(Enum):
45
EMAIL = "email"
56
PHONE = "phone"
Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)