Skip to content
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.7.4-blue.svg?style=flat-square)
![Version](https://img.shields.io/badge/api%20version-1.8.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.7.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.8.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
6 changes: 3 additions & 3 deletions appwrite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def __init__(self):
self._endpoint = 'https://cloud.appwrite.io/v1'
self._global_headers = {
'content-type': '',
'user-agent' : f'AppwritePythonSDK/11.1.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
'user-agent' : f'AppwritePythonSDK/12.0.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
'x-sdk-name': 'Python',
'x-sdk-platform': 'server',
'x-sdk-language': 'python',
'x-sdk-version': '11.1.0',
'X-Appwrite-Response-Format' : '1.7.0',
'x-sdk-version': '12.0.0',
'X-Appwrite-Response-Format' : '1.8.0',
}

def set_self_signed(self, status=True):
Expand Down
36 changes: 36 additions & 0 deletions appwrite/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,42 @@ def offset(offset):
def contains(attribute, value):
return str(Query("contains", attribute, value))

@staticmethod
def not_contains(attribute, value):
return str(Query("notContains", attribute, value))

@staticmethod
def not_search(attribute, value):
return str(Query("notSearch", attribute, value))

@staticmethod
def not_between(attribute, start, end):
return str(Query("notBetween", attribute, [start, end]))

@staticmethod
def not_starts_with(attribute, value):
return str(Query("notStartsWith", attribute, value))

@staticmethod
def not_ends_with(attribute, value):
return str(Query("notEndsWith", attribute, value))

@staticmethod
def created_before(value):
return str(Query("createdBefore", None, value))

@staticmethod
def created_after(value):
return str(Query("createdAfter", None, value))

@staticmethod
def updated_before(value):
return str(Query("updatedBefore", None, value))

@staticmethod
def updated_after(value):
return str(Query("updatedAfter", None, value))

@staticmethod
def or_queries(queries):
return str(Query("or", None, [json.loads(query) for query in queries]))
Expand Down
44 changes: 9 additions & 35 deletions appwrite/services/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ def create(self, user_id: str, email: str, password: str, name: str = None) -> D
"""
Use this endpoint to allow a new user to register a new account in your project. After the user registration completes successfully, you can use the [/account/verfication](https://appwrite.io/docs/references/cloud/client-web/account#createVerification) route to start verifying the user email address. To allow the new user to login to their new account, you need to create a new [account session](https://appwrite.io/docs/references/cloud/client-web/account#createEmailSession).


Parameters
----------
user_id : str
Expand Down Expand Up @@ -85,7 +84,6 @@ def update_email(self, email: str, password: str) -> Dict[str, Any]:
This endpoint can also be used to convert an anonymous account to a normal one, by passing an email address and a new password.



Parameters
----------
email : str
Expand Down Expand Up @@ -124,7 +122,6 @@ def list_identities(self, queries: List[str] = None) -> Dict[str, Any]:
"""
Get the list of identities for the currently logged in user.


Parameters
----------
queries : List[str]
Expand Down Expand Up @@ -153,7 +150,6 @@ def delete_identity(self, identity_id: str) -> Dict[str, Any]:
"""
Delete an identity by its unique ID.


Parameters
----------
identity_id : str
Expand Down Expand Up @@ -208,7 +204,6 @@ def list_logs(self, queries: List[str] = None) -> Dict[str, Any]:
"""
Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.


Parameters
----------
queries : List[str]
Expand Down Expand Up @@ -237,7 +232,6 @@ def update_mfa(self, mfa: bool) -> Dict[str, Any]:
"""
Enable or disable MFA on an account.


Parameters
----------
mfa : bool
Expand Down Expand Up @@ -270,7 +264,6 @@ def create_mfa_authenticator(self, type: AuthenticatorType) -> Dict[str, Any]:
"""
Add an authenticator app to be used as an MFA factor. Verify the authenticator using the [verify authenticator](/docs/references/cloud/client-web/account#updateMfaAuthenticator) method.


Parameters
----------
type : AuthenticatorType
Expand Down Expand Up @@ -303,7 +296,6 @@ def update_mfa_authenticator(self, type: AuthenticatorType, otp: str) -> Dict[st
"""
Verify an authenticator app after adding it using the [add authenticator](/docs/references/cloud/client-web/account#createMfaAuthenticator) method.


Parameters
----------
type : AuthenticatorType
Expand Down Expand Up @@ -342,7 +334,6 @@ def delete_mfa_authenticator(self, type: AuthenticatorType) -> Dict[str, Any]:
"""
Delete an authenticator for a user by ID.


Parameters
----------
type : AuthenticatorType
Expand Down Expand Up @@ -375,7 +366,6 @@ def create_mfa_challenge(self, factor: AuthenticationFactor) -> Dict[str, Any]:
"""
Begin the process of MFA verification after sign-in. Finish the flow with [updateMfaChallenge](/docs/references/cloud/client-web/account#updateMfaChallenge) method.


Parameters
----------
factor : AuthenticationFactor
Expand Down Expand Up @@ -408,7 +398,6 @@ def update_mfa_challenge(self, challenge_id: str, otp: str) -> Dict[str, Any]:
"""
Complete the MFA challenge by providing the one-time password. Finish the process of MFA verification by providing the one-time password. To begin the flow, use [createMfaChallenge](/docs/references/cloud/client-web/account#createMfaChallenge) method.


Parameters
----------
challenge_id : str
Expand Down Expand Up @@ -533,7 +522,6 @@ def update_name(self, name: str) -> Dict[str, Any]:
"""
Update currently logged in user account name.


Parameters
----------
name : str
Expand Down Expand Up @@ -566,7 +554,6 @@ def update_password(self, password: str, old_password: str = None) -> Dict[str,
"""
Update currently logged in user password. For validation, user is required to pass in the new password, and the old password. For users created with OAuth, Team Invites and Magic URL, oldPassword is optional.


Parameters
----------
password : str
Expand Down Expand Up @@ -602,7 +589,6 @@ def update_phone(self, phone: str, password: str) -> Dict[str, Any]:
"""
Update the currently logged in user's phone number. After updating the phone number, the phone verification status will be reset. A confirmation SMS is not sent automatically, however you can use the [POST /account/verification/phone](https://appwrite.io/docs/references/cloud/client-web/account#createPhoneVerification) endpoint to send a confirmation SMS.


Parameters
----------
phone : str
Expand Down Expand Up @@ -662,7 +648,6 @@ def update_prefs(self, prefs: dict) -> Dict[str, Any]:
"""
Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded.


Parameters
----------
prefs : dict
Expand Down Expand Up @@ -695,7 +680,6 @@ def create_recovery(self, email: str, url: str) -> Dict[str, Any]:
"""
Sends the user an email with a temporary secret key for password reset. When the user clicks the confirmation link he is redirected back to your app password reset URL with the secret key and email address values attached to the URL query string. Use the query string params to submit a request to the [PUT /account/recovery](https://appwrite.io/docs/references/cloud/client-web/account#updateRecovery) endpoint to complete the process. The verification link sent to the user's email address is valid for 1 hour.


Parameters
----------
email : str
Expand Down Expand Up @@ -736,7 +720,6 @@ def update_recovery(self, user_id: str, secret: str, password: str) -> Dict[str,

Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.


Parameters
----------
user_id : str
Expand Down Expand Up @@ -848,7 +831,6 @@ def create_email_password_session(self, email: str, password: str) -> Dict[str,

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).


Parameters
----------
email : str
Expand Down Expand Up @@ -887,7 +869,8 @@ def update_magic_url_session(self, user_id: str, secret: str) -> Dict[str, Any]:
"""
Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.


.. deprecated::
This API has been deprecated.
Parameters
----------
user_id : str
Expand Down Expand Up @@ -926,7 +909,8 @@ def update_phone_session(self, user_id: str, secret: str) -> Dict[str, Any]:
"""
Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.


.. deprecated::
This API has been deprecated.
Parameters
----------
user_id : str
Expand Down Expand Up @@ -965,7 +949,6 @@ def create_session(self, user_id: str, secret: str) -> Dict[str, Any]:
"""
Use this endpoint to create a session from token. Provide the **userId** and **secret** parameters from the successful response of authentication flows initiated by token creation. For example, magic URL and phone login.


Parameters
----------
user_id : str
Expand Down Expand Up @@ -1004,7 +987,6 @@ def get_session(self, session_id: str) -> Dict[str, Any]:
"""
Use this endpoint to get a logged in user's session using a Session ID. Inputting 'current' will return the current session being used.


Parameters
----------
session_id : str
Expand Down Expand Up @@ -1036,7 +1018,6 @@ def update_session(self, session_id: str) -> Dict[str, Any]:
"""
Use this endpoint to extend a session's length. Extending a session is useful when session expiry is short. If the session was created using an OAuth provider, this endpoint refreshes the access token from the provider.


Parameters
----------
session_id : str
Expand Down Expand Up @@ -1069,7 +1050,6 @@ def delete_session(self, session_id: str) -> Dict[str, Any]:
"""
Logout the user. Use 'current' as the session ID to logout on this device, use a session ID to logout on another device. If you're looking to logout the user on all devices, use [Delete Sessions](https://appwrite.io/docs/references/cloud/client-web/account#deleteSessions) instead.


Parameters
----------
session_id : str
Expand Down Expand Up @@ -1122,15 +1102,15 @@ def update_status(self) -> Dict[str, Any]:

def create_email_token(self, user_id: str, email: str, phrase: bool = None) -> Dict[str, Any]:
"""
Sends the user an email with a secret key for creating a session. If the provided user ID has not be registered, a new user will be created. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes.
Sends the user an email with a secret key for creating a session. If the email address has never been used, a **new account is created** using the provided `userId`. Otherwise, if the email address is already attached to an account, the **user ID is ignored**. Then, the user will receive an email with the one-time password. Use the returned user ID and secret and submit a request to the [POST /v1/account/sessions/token](https://appwrite.io/docs/references/cloud/client-web/account#createSession) endpoint to complete the login process. The secret sent to the user's email is valid for 15 minutes.

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).


Parameters
----------
user_id : str
User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
User ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. If the email address has never been used, a new account is created using the provided userId. Otherwise, if the email address is already attached to an account, the user ID is ignored.
email : str
User email.
phrase : bool
Expand Down Expand Up @@ -1171,11 +1151,10 @@ def create_magic_url_token(self, user_id: str, email: str, url: str = None, phra
A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).



Parameters
----------
user_id : str
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. If the email address has never been used, a new account is created using the provided userId. Otherwise, if the email address is already attached to an account, the user ID is ignored.
email : str
User email.
url : str
Expand Down Expand Up @@ -1220,7 +1199,6 @@ def create_o_auth2_token(self, provider: OAuthProvider, success: str = None, fai

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).


Parameters
----------
provider : OAuthProvider
Expand Down Expand Up @@ -1263,11 +1241,10 @@ def create_phone_token(self, user_id: str, phone: str) -> Dict[str, Any]:

A user is limited to 10 active sessions at a time by default. [Learn more about session limits](https://appwrite.io/docs/authentication-security#limits).


Parameters
----------
user_id : str
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.
Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars. If the phone number has never been used, a new account is created using the provided userId. Otherwise, if the phone number is already attached to an account, the user ID is ignored.
phone : str
Phone number. Format this number with a leading '+' and a country code, e.g., +16175551212.

Expand Down Expand Up @@ -1305,7 +1282,6 @@ def create_verification(self, url: str) -> Dict[str, Any]:
Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface.



Parameters
----------
url : str
Expand Down Expand Up @@ -1338,7 +1314,6 @@ def update_verification(self, user_id: str, secret: str) -> Dict[str, Any]:
"""
Use this endpoint to complete the user email verification process. Use both the **userId** and **secret** parameters that were attached to your app URL to verify the user email ownership. If confirmed this route will return a 200 status code.


Parameters
----------
user_id : str
Expand Down Expand Up @@ -1399,7 +1374,6 @@ def update_phone_verification(self, user_id: str, secret: str) -> Dict[str, Any]
"""
Use this endpoint to complete the user phone verification process. Use the **userId** and **secret** that were sent to your user's phone number to verify the user email ownership. If confirmed this route will return a 200 status code.


Parameters
----------
user_id : str
Expand Down
Loading