Skip to content

Commit 94df3f4

Browse files
committed
Release candidate for 1.5.x
1 parent ce7745c commit 94df3f4

File tree

277 files changed

+3079
-305
lines changed

Some content is hidden

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

277 files changed

+3079
-305
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2023 Appwrite (https://appwrite.io) and individual contributors.
1+
Copyright (c) 2024 Appwrite (https://appwrite.io) and individual contributors.
22
All rights reserved.
33

44
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# Appwrite Python SDK
22

33
![License](https://img.shields.io/github/license/appwrite/sdk-for-python.svg?style=flat-square)
4-
![Version](https://img.shields.io/badge/api%20version-1.4.12-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.4.13-blue.svg?style=flat-square)
55
[![Build Status](https://img.shields.io/travis/com/appwrite/sdk-generator?style=flat-square)](https://travis-ci.com/appwrite/sdk-generator)
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: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
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):
@@ -11,11 +13,11 @@ def __init__(self):
1113
self._endpoint = 'https://HOSTNAME/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.1 (${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.1',
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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import json
2+
from ..enums.authenticator_provider import AuthenticatorProvider
3+
from ..enums.authenticator_factor import AuthenticatorFactor
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.message_type import MessageType
14+
from ..enums.smtp_encryption import SMTPEncryption
15+
from ..enums.compression import Compression
16+
from ..enums.image_gravity import ImageGravity
17+
from ..enums.image_format import ImageFormat
18+
from ..enums.password_version import PasswordVersion
19+
from ..enums.messaging_provider_type import MessagingProviderType
20+
21+
class ValueClassEncoder(json.JSONEncoder):
22+
def default(self, o):
23+
if isinstance(o, AuthenticatorProvider):
24+
return o.value
25+
26+
if isinstance(o, AuthenticatorFactor):
27+
return o.value
28+
29+
if isinstance(o, OAuthProvider):
30+
return o.value
31+
32+
if isinstance(o, Browser):
33+
return o.value
34+
35+
if isinstance(o, CreditCard):
36+
return o.value
37+
38+
if isinstance(o, Flag):
39+
return o.value
40+
41+
if isinstance(o, RelationshipType):
42+
return o.value
43+
44+
if isinstance(o, RelationMutate):
45+
return o.value
46+
47+
if isinstance(o, IndexType):
48+
return o.value
49+
50+
if isinstance(o, Runtime):
51+
return o.value
52+
53+
if isinstance(o, ExecutionMethod):
54+
return o.value
55+
56+
if isinstance(o, MessageType):
57+
return o.value
58+
59+
if isinstance(o, SMTPEncryption):
60+
return o.value
61+
62+
if isinstance(o, Compression):
63+
return o.value
64+
65+
if isinstance(o, ImageGravity):
66+
return o.value
67+
68+
if isinstance(o, ImageFormat):
69+
return o.value
70+
71+
if isinstance(o, PasswordVersion):
72+
return o.value
73+
74+
if isinstance(o, MessagingProviderType):
75+
return o.value
76+
77+
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+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from enum import Enum
2+
3+
class AuthenticatorFactor(Enum):
4+
TOTP = "totp"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from enum import Enum
2+
3+
class AuthenticatorProvider(Enum):
4+
TOTP = "totp"

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"

0 commit comments

Comments
 (0)