Skip to content

Commit ba88a24

Browse files
committed
Release candidate for 1.5.x
1 parent 889402a commit ba88a24

File tree

202 files changed

+509
-472
lines changed

Some content is hidden

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

202 files changed

+509
-472
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Once your SDK object is set, create any of the Appwrite service objects and choo
4646
```python
4747
users = Users(client)
4848

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

5252
### Full Example
@@ -66,7 +66,7 @@ client = Client()
6666

6767
users = Users(client)
6868

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

7272
### Error Handling
@@ -75,7 +75,7 @@ The Appwrite Python SDK raises `AppwriteException` object with `message`, `code`
7575
```python
7676
users = Users(client)
7777
try:
78-
result = users.create(ID.unique(), 'email@example.com', 'password')
78+
result = users.create(ID.unique(), email = "email@example.com", phone = "+123456789", password = "password", name = "Walter O'Brien")
7979
except AppwriteException as e:
8080
print(e.message)
8181
```

appwrite/client.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ def __init__(self):
1313
self._endpoint = 'https://cloud.appwrite.io/v1'
1414
self._global_headers = {
1515
'content-type': '',
16-
'user-agent' : 'AppwritePythonSDK/5.0.0-rc.4 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
16+
'user-agent' : 'AppwritePythonSDK/5.0.0-rc.5 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
1717
'x-sdk-name': 'Python',
1818
'x-sdk-platform': 'server',
1919
'x-sdk-language': 'python',
20-
'x-sdk-version': '5.0.0-rc.4',
20+
'x-sdk-version': '5.0.0-rc.5',
2121
'X-Appwrite-Response-Format' : '1.5.0',
2222
}
2323

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

64-
def set_forwarded_for(self, value):
65-
"""The IP address of the client that made the request"""
66-
67-
self._global_headers['x-forwarded-for'] = value
68-
return self
69-
7064
def set_forwarded_user_agent(self, value):
7165
"""The user agent string of the client that made the request"""
7266

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

76-
def call(self, method, path='', headers=None, params=None):
70+
def call(self, method, path='', headers=None, params=None, response_type='json'):
7771
if headers is None:
7872
headers = {}
7973

@@ -103,6 +97,7 @@ def call(self, method, path='', headers=None, params=None):
10397
files[key] = (data[key].filename, data[key].data)
10498
del data[key]
10599
data = self.flatten(data, stringify=stringify)
100+
106101
response = None
107102
try:
108103
response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554
@@ -113,12 +108,16 @@ def call(self, method, path='', headers=None, params=None):
113108
files=files,
114109
headers=headers,
115110
verify=(not self._self_signed),
111+
allow_redirects=False if response_type == 'location' else True
116112
)
117113

118114
response.raise_for_status()
119115

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

118+
if response_type == 'location':
119+
return response.headers.get('Location')
120+
122121
if content_type.startswith('application/json'):
123122
return response.json()
124123

appwrite/encoders/value_class_encoder.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ..enums.execution_method import ExecutionMethod
1313
from ..enums.name import Name
1414
from ..enums.message_status import MessageStatus
15-
from ..enums.encryption import Encryption
15+
from ..enums.smtp_encryption import SmtpEncryption
1616
from ..enums.compression import Compression
1717
from ..enums.image_gravity import ImageGravity
1818
from ..enums.image_format import ImageFormat
@@ -60,7 +60,7 @@ def default(self, o):
6060
if isinstance(o, MessageStatus):
6161
return o.value
6262

63-
if isinstance(o, Encryption):
63+
if isinstance(o, SmtpEncryption):
6464
return o.value
6565

6666
if isinstance(o, Compression):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from enum import Enum
22

3-
class Encryption(Enum):
3+
class SmtpEncryption(Enum):
44
NONE = "none"
55
SSL = "ssl"
66
TLS = "tls"

appwrite/services/account.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def update_mfa(self, mfa):
131131
'content-type': 'application/json',
132132
}, api_params)
133133

134-
def create2_fa_challenge(self, factor):
134+
def create_challenge(self, factor):
135135
"""Create 2FA Challenge"""
136136

137137

@@ -431,7 +431,7 @@ def update_magic_url_session(self, user_id, secret):
431431
'content-type': 'application/json',
432432
}, api_params)
433433

434-
def create_o_auth2_session(self, provider, success = None, failure = None, token = None, scopes = None):
434+
def create_o_auth2_session(self, provider, success = None, failure = None, scopes = None):
435435
"""Create OAuth2 session"""
436436

437437

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

445445
api_params['success'] = success
446446
api_params['failure'] = failure
447-
api_params['token'] = token
448447
api_params['scopes'] = scopes
449448

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

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

575+
def create_o_auth2_token(self, provider, success = None, failure = None, scopes = None):
576+
"""Create OAuth2 token"""
577+
578+
579+
api_path = '/account/tokens/oauth2/{provider}'
580+
api_params = {}
581+
if provider is None:
582+
raise AppwriteException('Missing required parameter: "provider"')
583+
584+
api_path = api_path.replace('{provider}', provider)
585+
586+
api_params['success'] = success
587+
api_params['failure'] = failure
588+
api_params['scopes'] = scopes
589+
590+
return self.client.call('get', api_path, {
591+
'content-type': 'application/json',
592+
}, api_params, response_type='location')
593+
576594
def create_phone_token(self, user_id, phone):
577595
"""Create phone token"""
578596

appwrite/services/messaging.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def list_providers(self, queries = None, search = None):
274274
'content-type': 'application/json',
275275
}, api_params)
276276

277-
def create_apns_provider(self, provider_id, name, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None, enabled = None):
277+
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):
278278
"""Create APNS provider"""
279279

280280

@@ -293,13 +293,14 @@ def create_apns_provider(self, provider_id, name, auth_key = None, auth_key_id =
293293
api_params['authKeyId'] = auth_key_id
294294
api_params['teamId'] = team_id
295295
api_params['bundleId'] = bundle_id
296+
api_params['sandbox'] = sandbox
296297
api_params['enabled'] = enabled
297298

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

302-
def update_apns_provider(self, provider_id, name = None, enabled = None, auth_key = None, auth_key_id = None, team_id = None, bundle_id = None):
303+
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):
303304
"""Update APNS provider"""
304305

305306

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

320322
return self.client.call('patch', api_path, {
321323
'content-type': 'application/json',
@@ -870,7 +872,7 @@ def get_topic(self, topic_id):
870872
'content-type': 'application/json',
871873
}, api_params)
872874

873-
def update_topic(self, topic_id, name = None):
875+
def update_topic(self, topic_id, name = None, subscribe = None):
874876
"""Update a topic"""
875877

876878

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

884886
api_params['name'] = name
887+
api_params['subscribe'] = subscribe
885888

886889
return self.client.call('patch', api_path, {
887890
'content-type': 'application/json',

docs/examples/account/create2f-a-challenge.md renamed to docs/examples/account/create-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ client.set_project('5df5acd0d48c2') # Your project ID
77

88
account = Account(client)
99

10-
result = account.create2_fa_challenge(
10+
result = account.create_challenge(
1111
factor = AuthenticationFactor.TOTP
1212
)

docs/examples/account/create-email-token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ client.set_project('5df5acd0d48c2') # Your project ID
77
account = Account(client)
88

99
result = account.create_email_token(
10-
user_id = '[USER_ID]',
10+
user_id = '<USER_ID>',
1111
email = 'email@example.com',
1212
phrase = False # optional
1313
)

docs/examples/account/create-magic-u-r-l-token.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ client.set_project('5df5acd0d48c2') # Your project ID
77
account = Account(client)
88

99
result = account.create_magic_url_token(
10-
user_id = '[USER_ID]',
10+
user_id = '<USER_ID>',
1111
email = 'email@example.com',
1212
url = 'https://example.com', # optional
1313
phrase = False # optional

docs/examples/account/create-o-auth2session.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,5 @@ result = account.create_o_auth2_session(
1111
provider = OAuthProvider.AMAZON,
1212
success = 'https://example.com', # optional
1313
failure = 'https://example.com', # optional
14-
token = False, # optional
1514
scopes = [] # optional
1615
)

0 commit comments

Comments
 (0)