Skip to content

Commit 10be5b7

Browse files
committed
Release candidate for 1.5.x
1 parent 06b002d commit 10be5b7

File tree

279 files changed

+3157
-303
lines changed

Some content is hidden

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

279 files changed

+3157
-303
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

9-
**This SDK is compatible with Appwrite server version 1.4.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-python/releases).**
9+
**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).**
1010

1111
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)
1212

appwrite/client.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
import io
2-
import requests
2+
import json
33
import os
4+
import requests
45
from .input_file import InputFile
56
from .exception import AppwriteException
7+
from .encoders.value_class_encoder import ValueClassEncoder
68

79
class Client:
810
def __init__(self):
911
self._chunk_size = 5*1024*1024
1012
self._self_signed = False
11-
self._endpoint = 'https://HOSTNAME/v1'
13+
self._endpoint = 'https://cloud.appwrite.io/v1'
1214
self._global_headers = {
1315
'content-type': '',
14-
'user-agent' : 'AppwritePythonSDK/4.1.0 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
16+
'user-agent' : 'AppwritePythonSDK/5.0.0-rc.2 (${os.uname().sysname}; ${os.uname().version}; ${os.uname().machine})',
1517
'x-sdk-name': 'Python',
1618
'x-sdk-platform': 'server',
1719
'x-sdk-language': 'python',
18-
'x-sdk-version': '4.1.0',
20+
'x-sdk-version': '5.0.0-rc.2',
1921
'X-Appwrite-Response-Format' : '1.4.0',
2022
}
2123

@@ -53,6 +55,24 @@ def set_locale(self, value):
5355
self._global_headers['x-appwrite-locale'] = value
5456
return self
5557

58+
def set_session(self, value):
59+
"""The user session to authenticate with"""
60+
61+
self._global_headers['x-appwrite-session'] = value
62+
return self
63+
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+
70+
def set_forwarded_user_agent(self, value):
71+
"""The user agent string of the client that made the request"""
72+
73+
self._global_headers['x-forwarded-user-agent'] = value
74+
return self
75+
5676
def call(self, method, path='', headers=None, params=None):
5777
if headers is None:
5878
headers = {}
@@ -63,7 +83,6 @@ def call(self, method, path='', headers=None, params=None):
6383
params = {k: v for k, v in params.items() if v is not None} # Remove None values from params dictionary
6484

6585
data = {}
66-
json = {}
6786
files = {}
6887
stringify = False
6988

@@ -74,8 +93,7 @@ def call(self, method, path='', headers=None, params=None):
7493
params = {}
7594

7695
if headers['content-type'].startswith('application/json'):
77-
json = data
78-
data = {}
96+
data = json.dumps(data, cls=ValueClassEncoder)
7997

8098
if headers['content-type'].startswith('multipart/form-data'):
8199
del headers['content-type']
@@ -84,14 +102,14 @@ def call(self, method, path='', headers=None, params=None):
84102
if isinstance(data[key], InputFile):
85103
files[key] = (data[key].filename, data[key].data)
86104
del data[key]
105+
data = self.flatten(data, stringify=stringify)
87106
response = None
88107
try:
89108
response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554
90109
method=method,
91110
url=self._endpoint + path,
92111
params=self.flatten(params, stringify=stringify),
93-
data=self.flatten(data),
94-
json=json,
112+
data=data,
95113
files=files,
96114
headers=headers,
97115
verify=(not self._self_signed),

appwrite/encoders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import json
2+
from ..enums.factor import Factor
3+
from ..enums.type import Type
4+
from ..enums.o_auth_provider import OAuthProvider
5+
from ..enums.browser import Browser
6+
from ..enums.credit_card import CreditCard
7+
from ..enums.flag import Flag
8+
from ..enums.relationship_type import RelationshipType
9+
from ..enums.relation_mutate import RelationMutate
10+
from ..enums.index_type import IndexType
11+
from ..enums.runtime import Runtime
12+
from ..enums.execution_method import ExecutionMethod
13+
from ..enums.name import Name
14+
from ..enums.message_status import MessageStatus
15+
from ..enums.smtp_encryption import SMTPEncryption
16+
from ..enums.compression import Compression
17+
from ..enums.image_gravity import ImageGravity
18+
from ..enums.image_format import ImageFormat
19+
from ..enums.password_hash import PasswordHash
20+
from ..enums.messaging_provider_type import MessagingProviderType
21+
22+
class ValueClassEncoder(json.JSONEncoder):
23+
def default(self, o):
24+
if isinstance(o, Factor):
25+
return o.value
26+
27+
if isinstance(o, Type):
28+
return o.value
29+
30+
if isinstance(o, OAuthProvider):
31+
return o.value
32+
33+
if isinstance(o, Browser):
34+
return o.value
35+
36+
if isinstance(o, CreditCard):
37+
return o.value
38+
39+
if isinstance(o, Flag):
40+
return o.value
41+
42+
if isinstance(o, RelationshipType):
43+
return o.value
44+
45+
if isinstance(o, RelationMutate):
46+
return o.value
47+
48+
if isinstance(o, IndexType):
49+
return o.value
50+
51+
if isinstance(o, Runtime):
52+
return o.value
53+
54+
if isinstance(o, ExecutionMethod):
55+
return o.value
56+
57+
if isinstance(o, Name):
58+
return o.value
59+
60+
if isinstance(o, MessageStatus):
61+
return o.value
62+
63+
if isinstance(o, SMTPEncryption):
64+
return o.value
65+
66+
if isinstance(o, Compression):
67+
return o.value
68+
69+
if isinstance(o, ImageGravity):
70+
return o.value
71+
72+
if isinstance(o, ImageFormat):
73+
return o.value
74+
75+
if isinstance(o, PasswordHash):
76+
return o.value
77+
78+
if isinstance(o, MessagingProviderType):
79+
return o.value
80+
81+
return super().default(o)

appwrite/enums/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

appwrite/enums/browser.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from enum import Enum
2+
3+
class Browser(Enum):
4+
AVANT_BROWSER = "aa"
5+
ANDROID_WEBVIEW_BETA = "an"
6+
GOOGLE_CHROME = "ch"
7+
GOOGLE_CHROME_IOS = "ci"
8+
GOOGLE_CHROME_MOBILE = "cm"
9+
CHROMIUM = "cr"
10+
MOZILLA_FIREFOX = "ff"
11+
SAFARI = "sf"
12+
MOBILE_SAFARI = "mf"
13+
MICROSOFT_EDGE = "ps"
14+
MICROSOFT_EDGE_IOS = "oi"
15+
OPERA_MINI = "om"
16+
OPERA = "op"
17+
OPERA_NEXT = "on"

appwrite/enums/compression.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
class Compression(Enum):
4+
NONE = "none"
5+
GZIP = "gzip"
6+
ZSTD = "zstd"

appwrite/enums/credit_card.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from enum import Enum
2+
3+
class CreditCard(Enum):
4+
AMERICAN_EXPRESS = "amex"
5+
ARGENCARD = "argencard"
6+
CABAL = "cabal"
7+
CONSOSUD = "censosud"
8+
DINERS_CLUB = "diners"
9+
DISCOVER = "discover"
10+
ELO = "elo"
11+
HIPERCARD = "hipercard"
12+
JCB = "jcb"
13+
MASTERCARD = "mastercard"
14+
NARANJA = "naranja"
15+
TARJETA_SHOPPING = "targeta-shopping"
16+
UNION_CHINA_PAY = "union-china-pay"
17+
VISA = "visa"
18+
MIR = "mir"
19+
MAESTRO = "maestro"

appwrite/enums/execution_method.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from enum import Enum
2+
3+
class ExecutionMethod(Enum):
4+
GET = "GET"
5+
POST = "POST"
6+
PUT = "PUT"
7+
PATCH = "PATCH"
8+
DELETE = "DELETE"
9+
OPTIONS = "OPTIONS"

appwrite/enums/factor.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from enum import Enum
2+
3+
class Factor(Enum):
4+
TOTP = "totp"
5+
PHONE = "phone"
6+
EMAIL = "email"

0 commit comments

Comments
 (0)