Skip to content

1.6.x #90

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 8 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Appwrite Python SDK

![License](https://img.shields.io/github/license/appwrite/sdk-for-python.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.5.6-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.6.0-blue.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version 1.5.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-python/releases).**
**This SDK is compatible with Appwrite server version 1.6.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-python/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. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)

Expand Down
11 changes: 8 additions & 3 deletions appwrite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ def __init__(self):
self._endpoint = 'https://cloud.appwrite.io/v1'
self._global_headers = {
'content-type': '',
'user-agent' : 'AppwritePythonSDK/5.0.3 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
'user-agent' : 'AppwritePythonSDK/6.0.0 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
'x-sdk-name': 'Python',
'x-sdk-platform': 'server',
'x-sdk-language': 'python',
'x-sdk-version': '5.0.3',
'X-Appwrite-Response-Format' : '1.5.0',
'x-sdk-version': '6.0.0',
'X-Appwrite-Response-Format' : '1.6.0',
}

def set_self_signed(self, status=True):
Expand Down Expand Up @@ -113,6 +113,11 @@ def call(self, method, path='', headers=None, params=None, response_type='json')

response.raise_for_status()

warnings = response.headers.get('x-appwrite-warning')
if warnings:
for warning in warnings.split(';'):
print(f'Warning: {warning}')

content_type = response.headers['Content-Type']

if response_type == 'location':
Expand Down
2 changes: 1 addition & 1 deletion appwrite/enums/name.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Name(Enum):
V1_FUNCTIONS = "v1-functions"
V1_USAGE = "v1-usage"
V1_USAGE_DUMP = "v1-usage-dump"
WEBHOOKSV1 = "webhooksv1"
V1_WEBHOOKS = "v1-webhooks"
V1_CERTIFICATES = "v1-certificates"
V1_BUILDS = "v1-builds"
V1_MESSAGING = "v1-messaging"
Expand Down
1 change: 1 addition & 0 deletions appwrite/enums/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ class Runtime(Enum):
CPP_17 = "cpp-17"
CPP_20 = "cpp-20"
BUN_1_0 = "bun-1.0"
GO_1_23 = "go-1.23"
14 changes: 5 additions & 9 deletions appwrite/services/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def create_jwt(self):
"""Create JWT"""


api_path = '/account/jwt'
api_path = '/account/jwts'
api_params = {}

return self.client.call('post', api_path, {
Expand Down Expand Up @@ -132,7 +132,7 @@ def update_mfa(self, mfa):
}, api_params)

def create_mfa_authenticator(self, type):
"""Add Authenticator"""
"""Create Authenticator"""


api_path = '/account/mfa/authenticators/{type}'
Expand Down Expand Up @@ -167,7 +167,7 @@ def update_mfa_authenticator(self, type, otp):
'content-type': 'application/json',
}, api_params)

def delete_mfa_authenticator(self, type, otp):
def delete_mfa_authenticator(self, type):
"""Delete Authenticator"""


Expand All @@ -176,19 +176,15 @@ def delete_mfa_authenticator(self, type, otp):
if type is None:
raise AppwriteException('Missing required parameter: "type"')

if otp is None:
raise AppwriteException('Missing required parameter: "otp"')

api_path = api_path.replace('{type}', type)

api_params['otp'] = otp

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

def create_mfa_challenge(self, factor):
"""Create 2FA Challenge"""
"""Create MFA Challenge"""


api_path = '/account/mfa/challenge'
Expand Down Expand Up @@ -693,7 +689,7 @@ def create_phone_verification(self):
}, api_params)

def update_phone_verification(self, user_id, secret):
"""Create phone verification (confirmation)"""
"""Update phone verification (confirmation)"""


api_path = '/account/verification/phone'
Expand Down
81 changes: 67 additions & 14 deletions appwrite/services/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def list(self, queries = None, search = None):
'content-type': 'application/json',
}, 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, 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_branch = None):
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"""


Expand All @@ -47,6 +47,7 @@ def create(self, function_id, name, runtime, execute = None, events = None, sche
api_params['logging'] = logging
api_params['entrypoint'] = entrypoint
api_params['commands'] = commands
api_params['scopes'] = scopes
api_params['installationId'] = installation_id
api_params['providerRepositoryId'] = provider_repository_id
api_params['providerBranch'] = provider_branch
Expand All @@ -55,7 +56,8 @@ def create(self, function_id, name, runtime, execute = None, events = None, sche
api_params['templateRepository'] = template_repository
api_params['templateOwner'] = template_owner
api_params['templateRootDirectory'] = template_root_directory
api_params['templateBranch'] = template_branch
api_params['templateVersion'] = template_version
api_params['specification'] = specification

return self.client.call('post', api_path, {
'content-type': 'application/json',
Expand All @@ -72,6 +74,17 @@ def list_runtimes(self):
'content-type': 'application/json',
}, api_params)

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


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

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

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

Expand All @@ -88,7 +101,7 @@ def get(self, function_id):
'content-type': 'application/json',
}, 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, installation_id = None, provider_repository_id = None, provider_branch = None, provider_silent_mode = None, provider_root_directory = None):
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"""


Expand All @@ -112,11 +125,13 @@ def update(self, function_id, name, runtime = None, execute = None, events = Non
api_params['logging'] = logging
api_params['entrypoint'] = entrypoint
api_params['commands'] = commands
api_params['scopes'] = scopes
api_params['installationId'] = installation_id
api_params['providerRepositoryId'] = provider_repository_id
api_params['providerBranch'] = provider_branch
api_params['providerSilentMode'] = provider_silent_mode
api_params['providerRootDirectory'] = provider_root_directory
api_params['specification'] = specification

return self.client.call('put', api_path, {
'content-type': 'application/json',
Expand Down Expand Up @@ -208,7 +223,7 @@ def get_deployment(self, function_id, deployment_id):
}, api_params)

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


api_path = '/functions/{functionId}/deployments/{deploymentId}'
Expand Down Expand Up @@ -247,32 +262,49 @@ def delete_deployment(self, function_id, deployment_id):
'content-type': 'application/json',
}, api_params)

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


api_path = '/functions/{functionId}/deployments/{deploymentId}/builds/{buildId}'
api_path = '/functions/{functionId}/deployments/{deploymentId}/build'
api_params = {}
if function_id is None:
raise AppwriteException('Missing required parameter: "function_id"')

if deployment_id is None:
raise AppwriteException('Missing required parameter: "deployment_id"')

if build_id is None:
raise AppwriteException('Missing required parameter: "build_id"')

api_path = api_path.replace('{functionId}', function_id)
api_path = api_path.replace('{deploymentId}', deployment_id)
api_path = api_path.replace('{buildId}', build_id)

api_params['buildId'] = build_id

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

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


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

if deployment_id is None:
raise AppwriteException('Missing required parameter: "deployment_id"')

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


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

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


api_path = '/functions/{functionId}/deployments/{deploymentId}/download'
Expand Down Expand Up @@ -309,7 +341,7 @@ 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):
def create_execution(self, function_id, body = None, xasync = None, path = None, method = None, headers = None, scheduled_at = None):
"""Create execution"""


Expand All @@ -325,6 +357,7 @@ def create_execution(self, function_id, body = None, xasync = None, path = None,
api_params['path'] = path
api_params['method'] = method
api_params['headers'] = headers
api_params['scheduledAt'] = scheduled_at

return self.client.call('post', api_path, {
'content-type': 'application/json',
Expand All @@ -350,6 +383,26 @@ def get_execution(self, function_id, execution_id):
'content-type': 'application/json',
}, api_params)

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


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

if execution_id is None:
raise AppwriteException('Missing required parameter: "execution_id"')

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


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

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

Expand Down
18 changes: 18 additions & 0 deletions appwrite/services/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,24 @@ def update_email(self, user_id, email):
'content-type': 'application/json',
}, api_params)

def create_jwt(self, user_id, session_id = None, duration = None):
"""Create user JWT"""


api_path = '/users/{userId}/jwts'
api_params = {}
if user_id is None:
raise AppwriteException('Missing required parameter: "user_id"')

api_path = api_path.replace('{userId}', user_id)

api_params['sessionId'] = session_id
api_params['duration'] = duration

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

def update_labels(self, user_id, labels):
"""Update user labels"""

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-anonymous-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-email-password-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-email-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-j-w-t.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-magic-u-r-l-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-mfa-authenticator.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from appwrite.enums import AuthenticatorType

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
client.set_session('') # The user session to authenticate with

account = Account(client)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-mfa-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from appwrite.enums import AuthenticationFactor

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-mfa-recovery-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from appwrite.client import Client

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
client.set_session('') # The user session to authenticate with

account = Account(client)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/account/create-o-auth2token.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ from appwrite.enums import OAuthProvider

client = Client()
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
client.set_project('5df5acd0d48c2') # Your project ID
client.set_project('<YOUR_PROJECT_ID>') # Your project ID

account = Account(client)

Expand Down
Loading