Skip to content
Merged

Dev #80

Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Release candidate for 1.5.x
  • Loading branch information
abnegate committed Feb 24, 2024
commit ba88a2445869bb82528e365f0131b14d875a91d0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Once your SDK object is set, create any of the Appwrite service objects and choo
```python
users = Users(client)

result = users.create('[USER_ID]', 'email@example.com', 'password')
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
```

### Full Example
Expand All @@ -66,7 +66,7 @@ client = Client()

users = Users(client)

result = users.create(ID.unique(), 'email@example.com', 'password')
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
```

### Error Handling
Expand All @@ -75,7 +75,7 @@ The Appwrite Python SDK raises `AppwriteException` object with `message`, `code`
```python
users = Users(client)
try:
result = users.create(ID.unique(), 'email@example.com', 'password')
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
except AppwriteException as e:
print(e.message)
```
Expand Down
17 changes: 8 additions & 9 deletions appwrite/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def __init__(self):
self._endpoint = 'https://cloud.appwrite.io/v1'
self._global_headers = {
'content-type': '',
'user-agent' : 'AppwritePythonSDK/5.0.0-rc.4 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
'user-agent' : 'AppwritePythonSDK/5.0.0-rc.5 (${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.0-rc.4',
'x-sdk-version': '5.0.0-rc.5',
'X-Appwrite-Response-Format' : '1.5.0',
}

Expand Down Expand Up @@ -61,19 +61,13 @@ def set_session(self, value):
self._global_headers['x-appwrite-session'] = value
return self

def set_forwarded_for(self, value):
"""The IP address of the client that made the request"""

self._global_headers['x-forwarded-for'] = value
return self

def set_forwarded_user_agent(self, value):
"""The user agent string of the client that made the request"""

self._global_headers['x-forwarded-user-agent'] = value
return self

def call(self, method, path='', headers=None, params=None):
def call(self, method, path='', headers=None, params=None, response_type='json'):
if headers is None:
headers = {}

Expand Down Expand Up @@ -103,6 +97,7 @@ def call(self, method, path='', headers=None, params=None):
files[key] = (data[key].filename, data[key].data)
del data[key]
data = self.flatten(data, stringify=stringify)

response = None
try:
response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554
Expand All @@ -113,12 +108,16 @@ def call(self, method, path='', headers=None, params=None):
files=files,
headers=headers,
verify=(not self._self_signed),
allow_redirects=False if response_type == 'location' else True
)

response.raise_for_status()

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

if response_type == 'location':
return response.headers.get('Location')

if content_type.startswith('application/json'):
return response.json()

Expand Down
4 changes: 2 additions & 2 deletions appwrite/encoders/value_class_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..enums.execution_method import ExecutionMethod
from ..enums.name import Name
from ..enums.message_status import MessageStatus
from ..enums.encryption import Encryption
from ..enums.smtp_encryption import SmtpEncryption
from ..enums.compression import Compression
from ..enums.image_gravity import ImageGravity
from ..enums.image_format import ImageFormat
Expand Down Expand Up @@ -60,7 +60,7 @@ def default(self, o):
if isinstance(o, MessageStatus):
return o.value

if isinstance(o, Encryption):
if isinstance(o, SmtpEncryption):
return o.value

if isinstance(o, Compression):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from enum import Enum

class Encryption(Enum):
class SmtpEncryption(Enum):
NONE = "none"
SSL = "ssl"
TLS = "tls"
26 changes: 22 additions & 4 deletions appwrite/services/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def update_mfa(self, mfa):
'content-type': 'application/json',
}, api_params)

def create2_fa_challenge(self, factor):
def create_challenge(self, factor):
"""Create 2FA Challenge"""


Expand Down Expand Up @@ -431,7 +431,7 @@ def update_magic_url_session(self, user_id, secret):
'content-type': 'application/json',
}, api_params)

def create_o_auth2_session(self, provider, success = None, failure = None, token = None, scopes = None):
def create_o_auth2_session(self, provider, success = None, failure = None, scopes = None):
"""Create OAuth2 session"""


Expand All @@ -444,12 +444,11 @@ def create_o_auth2_session(self, provider, success = None, failure = None, token

api_params['success'] = success
api_params['failure'] = failure
api_params['token'] = token
api_params['scopes'] = scopes

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

def create_session(self, user_id, secret):
"""Create session"""
Expand Down Expand Up @@ -573,6 +572,25 @@ def create_magic_url_token(self, user_id, email, url = None, phrase = None):
'content-type': 'application/json',
}, api_params)

def create_o_auth2_token(self, provider, success = None, failure = None, scopes = None):
"""Create OAuth2 token"""


api_path = '/account/tokens/oauth2/{provider}'
api_params = {}
if provider is None:
raise AppwriteException('Missing required parameter: "provider"')

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

api_params['success'] = success
api_params['failure'] = failure
api_params['scopes'] = scopes

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

def create_phone_token(self, user_id, phone):
"""Create phone token"""

Expand Down
9 changes: 6 additions & 3 deletions appwrite/services/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def list_providers(self, queries = None, search = None):
'content-type': 'application/json',
}, api_params)

def create_apns_provider(self, provider_id, name, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None, enabled = None):
def create_apns_provider(self, provider_id, name, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None, sandbox = None, enabled = None):
"""Create APNS provider"""


Expand All @@ -293,13 +293,14 @@ def create_apns_provider(self, provider_id, name, auth_key = None, auth_key_id =
api_params['authKeyId'] = auth_key_id
api_params['teamId'] = team_id
api_params['bundleId'] = bundle_id
api_params['sandbox'] = sandbox
api_params['enabled'] = enabled

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

def update_apns_provider(self, provider_id, name = None, enabled = None, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None):
def update_apns_provider(self, provider_id, name = None, enabled = None, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None, sandbox = None):
"""Update APNS provider"""


Expand All @@ -316,6 +317,7 @@ def update_apns_provider(self, provider_id, name = None, enabled = None, auth_ke
api_params['authKeyId'] = auth_key_id
api_params['teamId'] = team_id
api_params['bundleId'] = bundle_id
api_params['sandbox'] = sandbox

return self.client.call('patch', api_path, {
'content-type': 'application/json',
Expand Down Expand Up @@ -870,7 +872,7 @@ def get_topic(self, topic_id):
'content-type': 'application/json',
}, api_params)

def update_topic(self, topic_id, name = None):
def update_topic(self, topic_id, name = None, subscribe = None):
"""Update a topic"""


Expand All @@ -882,6 +884,7 @@ def update_topic(self, topic_id, name = None):
api_path = api_path.replace('{topicId}', topic_id)

api_params['name'] = name
api_params['subscribe'] = subscribe

return self.client.call('patch', api_path, {
'content-type': 'application/json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ client.set_project('5df5acd0d48c2') # Your project ID

account = Account(client)

result = account.create2_fa_challenge(
result = account.create_challenge(
factor = AuthenticationFactor.TOTP
)
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 @@ -7,7 +7,7 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.create_email_token(
user_id = '[USER_ID]',
user_id = '<USER_ID>',
email = 'email@example.com',
phrase = False # optional
)
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 @@ -7,7 +7,7 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.create_magic_url_token(
user_id = '[USER_ID]',
user_id = '<USER_ID>',
email = 'email@example.com',
url = 'https://example.com', # optional
phrase = False # optional
Expand Down
1 change: 0 additions & 1 deletion docs/examples/account/create-o-auth2session.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ result = account.create_o_auth2_session(
provider = OAuthProvider.AMAZON,
success = 'https://example.com', # optional
failure = 'https://example.com', # optional
token = False, # optional
scopes = [] # optional
)
15 changes: 15 additions & 0 deletions docs/examples/account/create-o-auth2token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from appwrite.client import Client
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

account = Account(client)

result = account.create_o_auth2_token(
provider = OAuthProvider.AMAZON,
success = 'https://example.com', # optional
failure = 'https://example.com', # optional
scopes = [] # optional
)
2 changes: 1 addition & 1 deletion docs/examples/account/create-phone-token.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.create_phone_token(
user_id = '[USER_ID]',
user_id = '<USER_ID>',
phone = '+12065550100'
)
4 changes: 2 additions & 2 deletions docs/examples/account/create-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.create_session(
user_id = '[USER_ID]',
secret = '[SECRET]'
user_id = '<USER_ID>',
secret = '<SECRET>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.create(
user_id = '[USER_ID]',
user_id = '<USER_ID>',
email = 'email@example.com',
password = '',
name = '[NAME]' # optional
name = '<NAME>' # optional
)
2 changes: 1 addition & 1 deletion docs/examples/account/delete-authenticator.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ account = Account(client)

result = account.delete_authenticator(
type = AuthenticatorType.TOTP,
otp = '[OTP]'
otp = '<OTP>'
)
2 changes: 1 addition & 1 deletion docs/examples/account/delete-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.delete_identity(
identity_id = '[IDENTITY_ID]'
identity_id = '<IDENTITY_ID>'
)
2 changes: 1 addition & 1 deletion docs/examples/account/delete-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.delete_session(
session_id = '[SESSION_ID]'
session_id = '<SESSION_ID>'
)
2 changes: 1 addition & 1 deletion docs/examples/account/get-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.get_session(
session_id = '[SESSION_ID]'
session_id = '<SESSION_ID>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/update-challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_challenge(
challenge_id = '[CHALLENGE_ID]',
otp = '[OTP]'
challenge_id = '<CHALLENGE_ID>',
otp = '<OTP>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/update-magic-u-r-l-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ client.set_project('5df5acd0d48c2') # Your project ID
account = Account(client)

result = account.update_magic_url_session(
user_id = '[USER_ID]',
secret = '[SECRET]'
user_id = '<USER_ID>',
secret = '<SECRET>'
)
2 changes: 1 addition & 1 deletion docs/examples/account/update-name.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_name(
name = '[NAME]'
name = '<NAME>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/update-phone-verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_phone_verification(
user_id = '[USER_ID]',
secret = '[SECRET]'
user_id = '<USER_ID>',
secret = '<SECRET>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/update-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_recovery(
user_id = '[USER_ID]',
secret = '[SECRET]',
user_id = '<USER_ID>',
secret = '<SECRET>',
password = ''
)
2 changes: 1 addition & 1 deletion docs/examples/account/update-session.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_session(
session_id = '[SESSION_ID]'
session_id = '<SESSION_ID>'
)
4 changes: 2 additions & 2 deletions docs/examples/account/update-verification.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ client.set_session('') # The user session to authenticate with
account = Account(client)

result = account.update_verification(
user_id = '[USER_ID]',
secret = '[SECRET]'
user_id = '<USER_ID>',
secret = '<SECRET>'
)
2 changes: 1 addition & 1 deletion docs/examples/account/verify-authenticator.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ account = Account(client)

result = account.verify_authenticator(
type = AuthenticatorType.TOTP,
otp = '[OTP]'
otp = '<OTP>'
)
Loading