Skip to content

fix: revert multipart #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions appwrite/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import io
import json
import os
import requests
from .payload import Payload
from .multipart import MultipartParser
from .input_file import InputFile
from .exception import AppwriteException
from .encoders.value_class_encoder import ValueClassEncoder

@@ -90,15 +91,11 @@ def call(self, method, path='', headers=None, params=None, response_type='json')

if headers['content-type'].startswith('multipart/form-data'):
del headers['content-type']
headers['accept'] = 'multipart/form-data'
stringify = True
for key in data.copy():
if isinstance(data[key], Payload):
if data[key].filename:
files[key] = (data[key].filename, data[key].to_binary())
del data[key]
else:
data[key] = data[key].to_string()
if isinstance(data[key], InputFile):
files[key] = (data[key].filename, data[key].data)
del data[key]
data = self.flatten(data, stringify=stringify)

response = None
@@ -129,9 +126,6 @@ def call(self, method, path='', headers=None, params=None, response_type='json')
if content_type.startswith('application/json'):
return response.json()

if content_type.startswith('multipart/form-data'):
return MultipartParser(response.content, content_type).to_dict()

return response._content
except Exception as e:
if response != None:
@@ -152,10 +146,20 @@ def chunked_upload(
on_progress = None,
upload_id = ''
):
payload = params[param_name]
size = params[param_name].size
input_file = params[param_name]

if input_file.source_type == 'path':
size = os.stat(input_file.path).st_size
input = open(input_file.path, 'rb')
elif input_file.source_type == 'bytes':
size = len(input_file.data)
input = input_file.data

if size < self._chunk_size:
if input_file.source_type == 'path':
input_file.data = input.read()

if size < self._chunk_size:
params[param_name] = input_file
return self.call(
'post',
path,
@@ -178,10 +182,16 @@ def chunked_upload(
input.seek(offset)

while offset < size:
params[param_name] = Payload.from_binary(
payload.to_binary(offset, min(self._chunk_size, size - offset)),
payload.filename
)
if input_file.source_type == 'path':
input_file.data = input.read(self._chunk_size) or input.read(size - offset)
elif input_file.source_type == 'bytes':
if offset + self._chunk_size < size:
end = offset + self._chunk_size
else:
end = size - offset
input_file.data = input[offset:end]

params[param_name] = input_file
headers["content-range"] = f'bytes {offset}-{min((offset + self._chunk_size) - 1, size - 1)}/{size}'

result = self.call(
11 changes: 10 additions & 1 deletion appwrite/enums/runtime.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ class Runtime(Enum):
NODE_19_0 = "node-19.0"
NODE_20_0 = "node-20.0"
NODE_21_0 = "node-21.0"
NODE_22 = "node-22"
PHP_8_0 = "php-8.0"
PHP_8_1 = "php-8.1"
PHP_8_2 = "php-8.2"
@@ -25,28 +26,36 @@ class Runtime(Enum):
DENO_1_24 = "deno-1.24"
DENO_1_35 = "deno-1.35"
DENO_1_40 = "deno-1.40"
DENO_1_46 = "deno-1.46"
DENO_2_0 = "deno-2.0"
DART_2_15 = "dart-2.15"
DART_2_16 = "dart-2.16"
DART_2_17 = "dart-2.17"
DART_2_18 = "dart-2.18"
DART_3_0 = "dart-3.0"
DART_3_1 = "dart-3.1"
DART_3_3 = "dart-3.3"
DOTNET_3_1 = "dotnet-3.1"
DART_3_5 = "dart-3.5"
DOTNET_6_0 = "dotnet-6.0"
DOTNET_7_0 = "dotnet-7.0"
DOTNET_8_0 = "dotnet-8.0"
JAVA_8_0 = "java-8.0"
JAVA_11_0 = "java-11.0"
JAVA_17_0 = "java-17.0"
JAVA_18_0 = "java-18.0"
JAVA_21_0 = "java-21.0"
JAVA_22 = "java-22"
SWIFT_5_5 = "swift-5.5"
SWIFT_5_8 = "swift-5.8"
SWIFT_5_9 = "swift-5.9"
SWIFT_5_10 = "swift-5.10"
KOTLIN_1_6 = "kotlin-1.6"
KOTLIN_1_8 = "kotlin-1.8"
KOTLIN_1_9 = "kotlin-1.9"
KOTLIN_2_0 = "kotlin-2.0"
CPP_17 = "cpp-17"
CPP_20 = "cpp-20"
BUN_1_0 = "bun-1.0"
BUN_1_1 = "bun-1.1"
GO_1_23 = "go-1.23"
STATIC_1 = "static-1"
21 changes: 21 additions & 0 deletions appwrite/input_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import mimetypes

class InputFile:
@classmethod
def from_path(cls, path):
instance = cls()
instance.path = path
instance.filename = os.path.basename(path)
instance.mime_type = mimetypes.guess_type(path)
instance.source_type = 'path'
return instance

@classmethod
def from_bytes(cls, bytes, filename, mime_type = None):
instance = cls()
instance.data = bytes
instance.filename = filename
instance.mime_type = mime_type
instance.source_type = 'bytes'
return instance
49 changes: 0 additions & 49 deletions appwrite/multipart.py

This file was deleted.

72 changes: 0 additions & 72 deletions appwrite/payload.py

This file was deleted.

173 changes: 129 additions & 44 deletions appwrite/services/account.py

Large diffs are not rendered by default.

29 changes: 21 additions & 8 deletions appwrite/services/avatars.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Avatars, self).__init__(client)

def get_browser(self, code, width = None, height = None, quality = None):
"""Get browser icon"""
"""Get browser icon"""


api_path = '/avatars/browsers/{code}'
api_params = {}
if code is None:
@@ -24,7 +26,9 @@ def get_browser(self, code, width = None, height = None, quality = None):
}, api_params)

def get_credit_card(self, code, width = None, height = None, quality = None):
"""Get credit card icon"""
"""Get credit card icon"""


api_path = '/avatars/credit-cards/{code}'
api_params = {}
if code is None:
@@ -41,7 +45,9 @@ def get_credit_card(self, code, width = None, height = None, quality = None):
}, api_params)

def get_favicon(self, url):
"""Get favicon"""
"""Get favicon"""


api_path = '/avatars/favicon'
api_params = {}
if url is None:
@@ -55,7 +61,9 @@ def get_favicon(self, url):
}, api_params)

def get_flag(self, code, width = None, height = None, quality = None):
"""Get country flag"""
"""Get country flag"""


api_path = '/avatars/flags/{code}'
api_params = {}
if code is None:
@@ -72,7 +80,9 @@ def get_flag(self, code, width = None, height = None, quality = None):
}, api_params)

def get_image(self, url, width = None, height = None):
"""Get image from URL"""
"""Get image from URL"""


api_path = '/avatars/image'
api_params = {}
if url is None:
@@ -88,7 +98,9 @@ def get_image(self, url, width = None, height = None):
}, api_params)

def get_initials(self, name = None, width = None, height = None, background = None):
"""Get user initials"""
"""Get user initials"""


api_path = '/avatars/initials'
api_params = {}

@@ -102,7 +114,9 @@ def get_initials(self, name = None, width = None, height = None, background = No
}, api_params)

def get_qr(self, text, size = None, margin = None, download = None):
"""Get QR code"""
"""Get QR code"""


api_path = '/avatars/qr'
api_params = {}
if text is None:
@@ -117,4 +131,3 @@ def get_qr(self, text, size = None, margin = None, download = None):
return self.client.call('get', api_path, {
'content-type': 'application/json',
}, api_params)

169 changes: 126 additions & 43 deletions appwrite/services/databases.py

Large diffs are not rendered by default.

110 changes: 79 additions & 31 deletions appwrite/services/functions.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Functions, self).__init__(client)

def list(self, queries = None, search = None):
"""List functions"""
"""List functions"""


api_path = '/functions'
api_params = {}

@@ -19,7 +21,9 @@ def list(self, queries = None, search = None):
}, api_params)

def create(self, function_id, name, runtime, execute = None, events = None, schedule = None, timeout = None, enabled = None, logging = None, entrypoint = None, commands = None, scopes = None, installation_id = None, provider_repository_id = None, provider_branch = None, provider_silent_mode = None, provider_root_directory = None, template_repository = None, template_owner = None, template_root_directory = None, template_version = None, specification = None):
"""Create function"""
"""Create function"""


api_path = '/functions'
api_params = {}
if function_id is None:
@@ -60,7 +64,9 @@ def create(self, function_id, name, runtime, execute = None, events = None, sche
}, api_params)

def list_runtimes(self):
"""List runtimes"""
"""List runtimes"""


api_path = '/functions/runtimes'
api_params = {}

@@ -69,7 +75,9 @@ def list_runtimes(self):
}, api_params)

def list_specifications(self):
"""List available function runtime specifications"""
"""List available function runtime specifications"""


api_path = '/functions/specifications'
api_params = {}

@@ -78,7 +86,9 @@ def list_specifications(self):
}, api_params)

def get(self, function_id):
"""Get function"""
"""Get function"""


api_path = '/functions/{functionId}'
api_params = {}
if function_id is None:
@@ -92,7 +102,9 @@ def get(self, function_id):
}, api_params)

def update(self, function_id, name, runtime = None, execute = None, events = None, schedule = None, timeout = None, enabled = None, logging = None, entrypoint = None, commands = None, scopes = None, installation_id = None, provider_repository_id = None, provider_branch = None, provider_silent_mode = None, provider_root_directory = None, specification = None):
"""Update function"""
"""Update function"""


api_path = '/functions/{functionId}'
api_params = {}
if function_id is None:
@@ -126,7 +138,9 @@ def update(self, function_id, name, runtime = None, execute = None, events = Non
}, api_params)

def delete(self, function_id):
"""Delete function"""
"""Delete function"""


api_path = '/functions/{functionId}'
api_params = {}
if function_id is None:
@@ -140,7 +154,9 @@ def delete(self, function_id):
}, api_params)

def list_deployments(self, function_id, queries = None, search = None):
"""List deployments"""
"""List deployments"""


api_path = '/functions/{functionId}/deployments'
api_params = {}
if function_id is None:
@@ -156,7 +172,9 @@ def list_deployments(self, function_id, queries = None, search = None):
}, api_params)

def create_deployment(self, function_id, code, activate, entrypoint = None, commands = None, on_progress = None):
"""Create deployment"""
"""Create deployment"""


api_path = '/functions/{functionId}/deployments'
api_params = {}
if function_id is None:
@@ -176,15 +194,18 @@ def create_deployment(self, function_id, code, activate, entrypoint = None, comm
api_params['activate'] = str(activate).lower() if type(activate) is bool else activate

param_name = 'code'


upload_id = ''

return self.client.chunked_upload(api_path, {
'content-type': 'multipart/form-data',
}, api_params, param_name, on_progress, upload_id)


def get_deployment(self, function_id, deployment_id):
"""Get deployment"""
"""Get deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}'
api_params = {}
if function_id is None:
@@ -202,7 +223,9 @@ def get_deployment(self, function_id, deployment_id):
}, api_params)

def update_deployment(self, function_id, deployment_id):
"""Update deployment"""
"""Update deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}'
api_params = {}
if function_id is None:
@@ -220,7 +243,9 @@ def update_deployment(self, function_id, deployment_id):
}, api_params)

def delete_deployment(self, function_id, deployment_id):
"""Delete deployment"""
"""Delete deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}'
api_params = {}
if function_id is None:
@@ -238,7 +263,9 @@ def delete_deployment(self, function_id, deployment_id):
}, api_params)

def create_build(self, function_id, deployment_id, build_id = None):
"""Rebuild deployment"""
"""Rebuild deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}/build'
api_params = {}
if function_id is None:
@@ -257,7 +284,9 @@ def create_build(self, function_id, deployment_id, build_id = None):
}, api_params)

def update_deployment_build(self, function_id, deployment_id):
"""Cancel deployment"""
"""Cancel deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}/build'
api_params = {}
if function_id is None:
@@ -275,7 +304,9 @@ def update_deployment_build(self, function_id, deployment_id):
}, api_params)

def get_deployment_download(self, function_id, deployment_id):
"""Download deployment"""
"""Download deployment"""


api_path = '/functions/{functionId}/deployments/{deploymentId}/download'
api_params = {}
if function_id is None:
@@ -293,7 +324,9 @@ def get_deployment_download(self, function_id, deployment_id):
}, api_params)

def list_executions(self, function_id, queries = None, search = None):
"""List executions"""
"""List executions"""


api_path = '/functions/{functionId}/executions'
api_params = {}
if function_id is None:
@@ -308,28 +341,32 @@ def list_executions(self, function_id, queries = None, search = None):
'content-type': 'application/json',
}, api_params)

def create_execution(self, function_id, body = None, xasync = None, path = None, method = None, headers = None, scheduled_at = None, on_progress = None):
"""Create execution"""
def create_execution(self, function_id, body = None, xasync = None, path = None, method = None, headers = None, scheduled_at = None):
"""Create execution"""


api_path = '/functions/{functionId}/executions'
api_params = {}
if function_id is None:
raise AppwriteException('Missing required parameter: "function_id"')

api_path = api_path.replace('{functionId}', function_id)

api_params['body'] = str(body).lower() if type(body) is bool else body
api_params['async'] = str(xasync).lower() if type(xasync) is bool else xasync
api_params['body'] = body
api_params['async'] = xasync
api_params['path'] = path
api_params['method'] = method
api_params['headers'] = str(headers).lower() if type(headers) is bool else headers
api_params['headers'] = headers
api_params['scheduledAt'] = scheduled_at

return self.client.call('post', api_path, {
'content-type': 'multipart/form-data',
'content-type': 'application/json',
}, api_params)

def get_execution(self, function_id, execution_id):
"""Get execution"""
"""Get execution"""


api_path = '/functions/{functionId}/executions/{executionId}'
api_params = {}
if function_id is None:
@@ -347,7 +384,9 @@ def get_execution(self, function_id, execution_id):
}, api_params)

def delete_execution(self, function_id, execution_id):
"""Delete execution"""
"""Delete execution"""


api_path = '/functions/{functionId}/executions/{executionId}'
api_params = {}
if function_id is None:
@@ -365,7 +404,9 @@ def delete_execution(self, function_id, execution_id):
}, api_params)

def list_variables(self, function_id):
"""List variables"""
"""List variables"""


api_path = '/functions/{functionId}/variables'
api_params = {}
if function_id is None:
@@ -379,7 +420,9 @@ def list_variables(self, function_id):
}, api_params)

def create_variable(self, function_id, key, value):
"""Create variable"""
"""Create variable"""


api_path = '/functions/{functionId}/variables'
api_params = {}
if function_id is None:
@@ -401,7 +444,9 @@ def create_variable(self, function_id, key, value):
}, api_params)

def get_variable(self, function_id, variable_id):
"""Get variable"""
"""Get variable"""


api_path = '/functions/{functionId}/variables/{variableId}'
api_params = {}
if function_id is None:
@@ -419,7 +464,9 @@ def get_variable(self, function_id, variable_id):
}, api_params)

def update_variable(self, function_id, variable_id, key, value = None):
"""Update variable"""
"""Update variable"""


api_path = '/functions/{functionId}/variables/{variableId}'
api_params = {}
if function_id is None:
@@ -442,7 +489,9 @@ def update_variable(self, function_id, variable_id, key, value = None):
}, api_params)

def delete_variable(self, function_id, variable_id):
"""Delete variable"""
"""Delete variable"""


api_path = '/functions/{functionId}/variables/{variableId}'
api_params = {}
if function_id is None:
@@ -458,4 +507,3 @@ def delete_variable(self, function_id, variable_id):
return self.client.call('delete', api_path, {
'content-type': 'application/json',
}, api_params)

9 changes: 6 additions & 3 deletions appwrite/services/graphql.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Graphql, self).__init__(client)

def query(self, query):
"""GraphQL endpoint"""
"""GraphQL endpoint"""


api_path = '/graphql'
api_params = {}
if query is None:
@@ -22,7 +24,9 @@ def query(self, query):
}, api_params)

def mutation(self, query):
"""GraphQL endpoint"""
"""GraphQL endpoint"""


api_path = '/graphql/mutation'
api_params = {}
if query is None:
@@ -35,4 +39,3 @@ def mutation(self, query):
'x-sdk-graphql': 'true',
'content-type': 'application/json',
}, api_params)

93 changes: 69 additions & 24 deletions appwrite/services/health.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Health, self).__init__(client)

def get(self):
"""Get HTTP"""
"""Get HTTP"""


api_path = '/health'
api_params = {}

@@ -16,7 +18,9 @@ def get(self):
}, api_params)

def get_antivirus(self):
"""Get antivirus"""
"""Get antivirus"""


api_path = '/health/anti-virus'
api_params = {}

@@ -25,7 +29,9 @@ def get_antivirus(self):
}, api_params)

def get_cache(self):
"""Get cache"""
"""Get cache"""


api_path = '/health/cache'
api_params = {}

@@ -34,7 +40,9 @@ def get_cache(self):
}, api_params)

def get_certificate(self, domain = None):
"""Get the SSL certificate for a domain"""
"""Get the SSL certificate for a domain"""


api_path = '/health/certificate'
api_params = {}

@@ -45,7 +53,9 @@ def get_certificate(self, domain = None):
}, api_params)

def get_db(self):
"""Get DB"""
"""Get DB"""


api_path = '/health/db'
api_params = {}

@@ -54,7 +64,9 @@ def get_db(self):
}, api_params)

def get_pub_sub(self):
"""Get pubsub"""
"""Get pubsub"""


api_path = '/health/pubsub'
api_params = {}

@@ -63,7 +75,9 @@ def get_pub_sub(self):
}, api_params)

def get_queue(self):
"""Get queue"""
"""Get queue"""


api_path = '/health/queue'
api_params = {}

@@ -72,7 +86,9 @@ def get_queue(self):
}, api_params)

def get_queue_builds(self, threshold = None):
"""Get builds queue"""
"""Get builds queue"""


api_path = '/health/queue/builds'
api_params = {}

@@ -83,7 +99,9 @@ def get_queue_builds(self, threshold = None):
}, api_params)

def get_queue_certificates(self, threshold = None):
"""Get certificates queue"""
"""Get certificates queue"""


api_path = '/health/queue/certificates'
api_params = {}

@@ -94,7 +112,9 @@ def get_queue_certificates(self, threshold = None):
}, api_params)

def get_queue_databases(self, name = None, threshold = None):
"""Get databases queue"""
"""Get databases queue"""


api_path = '/health/queue/databases'
api_params = {}

@@ -106,7 +126,9 @@ def get_queue_databases(self, name = None, threshold = None):
}, api_params)

def get_queue_deletes(self, threshold = None):
"""Get deletes queue"""
"""Get deletes queue"""


api_path = '/health/queue/deletes'
api_params = {}

@@ -117,7 +139,9 @@ def get_queue_deletes(self, threshold = None):
}, api_params)

def get_failed_jobs(self, name, threshold = None):
"""Get number of failed queue jobs"""
"""Get number of failed queue jobs"""


api_path = '/health/queue/failed/{name}'
api_params = {}
if name is None:
@@ -132,7 +156,9 @@ def get_failed_jobs(self, name, threshold = None):
}, api_params)

def get_queue_functions(self, threshold = None):
"""Get functions queue"""
"""Get functions queue"""


api_path = '/health/queue/functions'
api_params = {}

@@ -143,7 +169,9 @@ def get_queue_functions(self, threshold = None):
}, api_params)

def get_queue_logs(self, threshold = None):
"""Get logs queue"""
"""Get logs queue"""


api_path = '/health/queue/logs'
api_params = {}

@@ -154,7 +182,9 @@ def get_queue_logs(self, threshold = None):
}, api_params)

def get_queue_mails(self, threshold = None):
"""Get mails queue"""
"""Get mails queue"""


api_path = '/health/queue/mails'
api_params = {}

@@ -165,7 +195,9 @@ def get_queue_mails(self, threshold = None):
}, api_params)

def get_queue_messaging(self, threshold = None):
"""Get messaging queue"""
"""Get messaging queue"""


api_path = '/health/queue/messaging'
api_params = {}

@@ -176,7 +208,9 @@ def get_queue_messaging(self, threshold = None):
}, api_params)

def get_queue_migrations(self, threshold = None):
"""Get migrations queue"""
"""Get migrations queue"""


api_path = '/health/queue/migrations'
api_params = {}

@@ -187,7 +221,9 @@ def get_queue_migrations(self, threshold = None):
}, api_params)

def get_queue_usage(self, threshold = None):
"""Get usage queue"""
"""Get usage queue"""


api_path = '/health/queue/usage'
api_params = {}

@@ -198,7 +234,9 @@ def get_queue_usage(self, threshold = None):
}, api_params)

def get_queue_usage_dump(self, threshold = None):
"""Get usage dump queue"""
"""Get usage dump queue"""


api_path = '/health/queue/usage-dump'
api_params = {}

@@ -209,7 +247,9 @@ def get_queue_usage_dump(self, threshold = None):
}, api_params)

def get_queue_webhooks(self, threshold = None):
"""Get webhooks queue"""
"""Get webhooks queue"""


api_path = '/health/queue/webhooks'
api_params = {}

@@ -220,7 +260,9 @@ def get_queue_webhooks(self, threshold = None):
}, api_params)

def get_storage(self):
"""Get storage"""
"""Get storage"""


api_path = '/health/storage'
api_params = {}

@@ -229,7 +271,9 @@ def get_storage(self):
}, api_params)

def get_storage_local(self):
"""Get local storage"""
"""Get local storage"""


api_path = '/health/storage/local'
api_params = {}

@@ -238,11 +282,12 @@ def get_storage_local(self):
}, api_params)

def get_time(self):
"""Get time"""
"""Get time"""


api_path = '/health/time'
api_params = {}

return self.client.call('get', api_path, {
'content-type': 'application/json',
}, api_params)

33 changes: 24 additions & 9 deletions appwrite/services/locale.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Locale, self).__init__(client)

def get(self):
"""Get user locale"""
"""Get user locale"""


api_path = '/locale'
api_params = {}

@@ -16,7 +18,9 @@ def get(self):
}, api_params)

def list_codes(self):
"""List locale codes"""
"""List locale codes"""


api_path = '/locale/codes'
api_params = {}

@@ -25,7 +29,9 @@ def list_codes(self):
}, api_params)

def list_continents(self):
"""List continents"""
"""List continents"""


api_path = '/locale/continents'
api_params = {}

@@ -34,7 +40,9 @@ def list_continents(self):
}, api_params)

def list_countries(self):
"""List countries"""
"""List countries"""


api_path = '/locale/countries'
api_params = {}

@@ -43,7 +51,9 @@ def list_countries(self):
}, api_params)

def list_countries_eu(self):
"""List EU countries"""
"""List EU countries"""


api_path = '/locale/countries/eu'
api_params = {}

@@ -52,7 +62,9 @@ def list_countries_eu(self):
}, api_params)

def list_countries_phones(self):
"""List countries phone codes"""
"""List countries phone codes"""


api_path = '/locale/countries/phones'
api_params = {}

@@ -61,7 +73,9 @@ def list_countries_phones(self):
}, api_params)

def list_currencies(self):
"""List currencies"""
"""List currencies"""


api_path = '/locale/currencies'
api_params = {}

@@ -70,11 +84,12 @@ def list_currencies(self):
}, api_params)

def list_languages(self):
"""List languages"""
"""List languages"""


api_path = '/locale/languages'
api_params = {}

return self.client.call('get', api_path, {
'content-type': 'application/json',
}, api_params)

185 changes: 138 additions & 47 deletions appwrite/services/messaging.py

Large diffs are not rendered by default.

57 changes: 42 additions & 15 deletions appwrite/services/storage.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Storage, self).__init__(client)

def list_buckets(self, queries = None, search = None):
"""List buckets"""
"""List buckets"""


api_path = '/storage/buckets'
api_params = {}

@@ -19,7 +21,9 @@ def list_buckets(self, queries = None, search = None):
}, api_params)

def create_bucket(self, bucket_id, name, permissions = None, file_security = None, enabled = None, maximum_file_size = None, allowed_file_extensions = None, compression = None, encryption = None, antivirus = None):
"""Create bucket"""
"""Create bucket"""


api_path = '/storage/buckets'
api_params = {}
if bucket_id is None:
@@ -45,7 +49,9 @@ def create_bucket(self, bucket_id, name, permissions = None, file_security = Non
}, api_params)

def get_bucket(self, bucket_id):
"""Get bucket"""
"""Get bucket"""


api_path = '/storage/buckets/{bucketId}'
api_params = {}
if bucket_id is None:
@@ -59,7 +65,9 @@ def get_bucket(self, bucket_id):
}, api_params)

def update_bucket(self, bucket_id, name, permissions = None, file_security = None, enabled = None, maximum_file_size = None, allowed_file_extensions = None, compression = None, encryption = None, antivirus = None):
"""Update bucket"""
"""Update bucket"""


api_path = '/storage/buckets/{bucketId}'
api_params = {}
if bucket_id is None:
@@ -85,7 +93,9 @@ def update_bucket(self, bucket_id, name, permissions = None, file_security = Non
}, api_params)

def delete_bucket(self, bucket_id):
"""Delete bucket"""
"""Delete bucket"""


api_path = '/storage/buckets/{bucketId}'
api_params = {}
if bucket_id is None:
@@ -99,7 +109,9 @@ def delete_bucket(self, bucket_id):
}, api_params)

def list_files(self, bucket_id, queries = None, search = None):
"""List files"""
"""List files"""


api_path = '/storage/buckets/{bucketId}/files'
api_params = {}
if bucket_id is None:
@@ -115,7 +127,9 @@ def list_files(self, bucket_id, queries = None, search = None):
}, api_params)

def create_file(self, bucket_id, file_id, file, permissions = None, on_progress = None):
"""Create file"""
"""Create file"""


api_path = '/storage/buckets/{bucketId}/files'
api_params = {}
if bucket_id is None:
@@ -134,15 +148,19 @@ def create_file(self, bucket_id, file_id, file, permissions = None, on_progress
api_params['permissions'] = permissions

param_name = 'file'


upload_id = ''
upload_id = file_id

return self.client.chunked_upload(api_path, {
'content-type': 'multipart/form-data',
}, api_params, param_name, on_progress, upload_id)


def get_file(self, bucket_id, file_id):
"""Get file"""
"""Get file"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}'
api_params = {}
if bucket_id is None:
@@ -160,7 +178,9 @@ def get_file(self, bucket_id, file_id):
}, api_params)

def update_file(self, bucket_id, file_id, name = None, permissions = None):
"""Update file"""
"""Update file"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}'
api_params = {}
if bucket_id is None:
@@ -180,7 +200,9 @@ def update_file(self, bucket_id, file_id, name = None, permissions = None):
}, api_params)

def delete_file(self, bucket_id, file_id):
"""Delete file"""
"""Delete file"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}'
api_params = {}
if bucket_id is None:
@@ -198,7 +220,9 @@ def delete_file(self, bucket_id, file_id):
}, api_params)

def get_file_download(self, bucket_id, file_id):
"""Get file for download"""
"""Get file for download"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}/download'
api_params = {}
if bucket_id is None:
@@ -216,7 +240,9 @@ def get_file_download(self, bucket_id, file_id):
}, api_params)

def get_file_preview(self, bucket_id, file_id, width = None, height = None, gravity = None, quality = None, border_width = None, border_color = None, border_radius = None, opacity = None, rotation = None, background = None, output = None):
"""Get file preview"""
"""Get file preview"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}/preview'
api_params = {}
if bucket_id is None:
@@ -245,7 +271,9 @@ def get_file_preview(self, bucket_id, file_id, width = None, height = None, grav
}, api_params)

def get_file_view(self, bucket_id, file_id):
"""Get file for view"""
"""Get file for view"""


api_path = '/storage/buckets/{bucketId}/files/{fileId}/view'
api_params = {}
if bucket_id is None:
@@ -261,4 +289,3 @@ def get_file_view(self, bucket_id, file_id):
return self.client.call('get', api_path, {
'content-type': 'application/json',
}, api_params)

53 changes: 39 additions & 14 deletions appwrite/services/teams.py
Original file line number Diff line number Diff line change
@@ -7,7 +7,9 @@ def __init__(self, client):
super(Teams, self).__init__(client)

def list(self, queries = None, search = None):
"""List teams"""
"""List teams"""


api_path = '/teams'
api_params = {}

@@ -19,7 +21,9 @@ def list(self, queries = None, search = None):
}, api_params)

def create(self, team_id, name, roles = None):
"""Create team"""
"""Create team"""


api_path = '/teams'
api_params = {}
if team_id is None:
@@ -38,7 +42,9 @@ def create(self, team_id, name, roles = None):
}, api_params)

def get(self, team_id):
"""Get team"""
"""Get team"""


api_path = '/teams/{teamId}'
api_params = {}
if team_id is None:
@@ -52,7 +58,9 @@ def get(self, team_id):
}, api_params)

def update_name(self, team_id, name):
"""Update name"""
"""Update name"""


api_path = '/teams/{teamId}'
api_params = {}
if team_id is None:
@@ -70,7 +78,9 @@ def update_name(self, team_id, name):
}, api_params)

def delete(self, team_id):
"""Delete team"""
"""Delete team"""


api_path = '/teams/{teamId}'
api_params = {}
if team_id is None:
@@ -84,7 +94,9 @@ def delete(self, team_id):
}, api_params)

def list_memberships(self, team_id, queries = None, search = None):
"""List team memberships"""
"""List team memberships"""


api_path = '/teams/{teamId}/memberships'
api_params = {}
if team_id is None:
@@ -100,7 +112,9 @@ def list_memberships(self, team_id, queries = None, search = None):
}, api_params)

def create_membership(self, team_id, roles, email = None, user_id = None, phone = None, url = None, name = None):
"""Create team membership"""
"""Create team membership"""


api_path = '/teams/{teamId}/memberships'
api_params = {}
if team_id is None:
@@ -123,7 +137,9 @@ def create_membership(self, team_id, roles, email = None, user_id = None, phone
}, api_params)

def get_membership(self, team_id, membership_id):
"""Get team membership"""
"""Get team membership"""


api_path = '/teams/{teamId}/memberships/{membershipId}'
api_params = {}
if team_id is None:
@@ -141,7 +157,9 @@ def get_membership(self, team_id, membership_id):
}, api_params)

def update_membership(self, team_id, membership_id, roles):
"""Update membership"""
"""Update membership"""


api_path = '/teams/{teamId}/memberships/{membershipId}'
api_params = {}
if team_id is None:
@@ -163,7 +181,9 @@ def update_membership(self, team_id, membership_id, roles):
}, api_params)

def delete_membership(self, team_id, membership_id):
"""Delete team membership"""
"""Delete team membership"""


api_path = '/teams/{teamId}/memberships/{membershipId}'
api_params = {}
if team_id is None:
@@ -181,7 +201,9 @@ def delete_membership(self, team_id, membership_id):
}, api_params)

def update_membership_status(self, team_id, membership_id, user_id, secret):
"""Update team membership status"""
"""Update team membership status"""


api_path = '/teams/{teamId}/memberships/{membershipId}/status'
api_params = {}
if team_id is None:
@@ -207,7 +229,9 @@ def update_membership_status(self, team_id, membership_id, user_id, secret):
}, api_params)

def get_prefs(self, team_id):
"""Get team preferences"""
"""Get team preferences"""


api_path = '/teams/{teamId}/prefs'
api_params = {}
if team_id is None:
@@ -221,7 +245,9 @@ def get_prefs(self, team_id):
}, api_params)

def update_prefs(self, team_id, prefs):
"""Update preferences"""
"""Update preferences"""


api_path = '/teams/{teamId}/prefs'
api_params = {}
if team_id is None:
@@ -237,4 +263,3 @@ def update_prefs(self, team_id, prefs):
return self.client.call('put', api_path, {
'content-type': 'application/json',
}, api_params)

169 changes: 126 additions & 43 deletions appwrite/services/users.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/examples/databases/update-string-attribute.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,6 @@ result = databases.update_string_attribute(
key = '',
required = False,
default = '<DEFAULT>',
size = None, # optional
size = 1, # optional
new_key = '' # optional
)
4 changes: 2 additions & 2 deletions docs/examples/functions/create-deployment.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from appwrite.client import Client
from appwrite.payload import Payload
from appwrite.input_file import InputFile

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
@@ -10,7 +10,7 @@ functions = Functions(client)

result = functions.create_deployment(
function_id = '<FUNCTION_ID>',
code = Payload.from_file('/path/to/file.png'),
code = InputFile.from_path('file.png'),
activate = False,
entrypoint = '<ENTRYPOINT>', # optional
commands = '<COMMANDS>' # optional
2 changes: 1 addition & 1 deletion docs/examples/functions/create-execution.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ functions = Functions(client)

result = functions.create_execution(
function_id = '<FUNCTION_ID>',
body = Payload.from_json({"x": "y"}), # optional
body = '<BODY>', # optional
async = False, # optional
path = '<PATH>', # optional
method = ExecutionMethod.GET, # optional
4 changes: 2 additions & 2 deletions docs/examples/storage/create-file.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from appwrite.client import Client
from appwrite.payload import Payload
from appwrite.input_file import InputFile

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
@@ -11,6 +11,6 @@ storage = Storage(client)
result = storage.create_file(
bucket_id = '<BUCKET_ID>',
file_id = '<FILE_ID>',
file = Payload.from_file('/path/to/file.png'),
file = InputFile.from_path('file.png'),
permissions = ["read("any")"] # optional
)