Skip to content

Commit fdc1588

Browse files
committed
Add inc/dec
1 parent 580d8c2 commit fdc1588

14 files changed

+246
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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.7.0-blue.svg?style=flat-square)
4+
![Version](https://img.shields.io/badge/api%20version-1.7.4-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)

appwrite/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def __init__(self):
1414
self._endpoint = 'https://cloud.appwrite.io/v1'
1515
self._global_headers = {
1616
'content-type': '',
17-
'user-agent' : f'AppwritePythonSDK/11.0.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
17+
'user-agent' : f'AppwritePythonSDK/11.1.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
1818
'x-sdk-name': 'Python',
1919
'x-sdk-platform': 'server',
2020
'x-sdk-language': 'python',
21-
'x-sdk-version': '11.0.0',
21+
'x-sdk-version': '11.1.0',
2222
'X-Appwrite-Response-Format' : '1.7.0',
2323
}
2424

appwrite/enums/build_runtime.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class BuildRuntime(Enum):
3838
DART_3_1 = "dart-3.1"
3939
DART_3_3 = "dart-3.3"
4040
DART_3_5 = "dart-3.5"
41+
DART_3_8 = "dart-3.8"
4142
DOTNET_6_0 = "dotnet-6.0"
4243
DOTNET_7_0 = "dotnet-7.0"
4344
DOTNET_8_0 = "dotnet-8.0"
@@ -64,3 +65,4 @@ class BuildRuntime(Enum):
6465
FLUTTER_3_24 = "flutter-3.24"
6566
FLUTTER_3_27 = "flutter-3.27"
6667
FLUTTER_3_29 = "flutter-3.29"
68+
FLUTTER_3_32 = "flutter-3.32"

appwrite/enums/image_format.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ class ImageFormat(Enum):
77
WEBP = "webp"
88
HEIC = "heic"
99
AVIF = "avif"
10+
GIF = "gif"

appwrite/enums/runtime.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class Runtime(Enum):
3838
DART_3_1 = "dart-3.1"
3939
DART_3_3 = "dart-3.3"
4040
DART_3_5 = "dart-3.5"
41+
DART_3_8 = "dart-3.8"
4142
DOTNET_6_0 = "dotnet-6.0"
4243
DOTNET_7_0 = "dotnet-7.0"
4344
DOTNET_8_0 = "dotnet-8.0"
@@ -64,3 +65,4 @@ class Runtime(Enum):
6465
FLUTTER_3_24 = "flutter-3.24"
6566
FLUTTER_3_27 = "flutter-3.27"
6667
FLUTTER_3_29 = "flutter-3.29"
68+
FLUTTER_3_32 = "flutter-3.32"

appwrite/services/databases.py

Lines changed: 179 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ def create_document(self, database_id: str, collection_id: str, document_id: str
18121812

18131813
def create_documents(self, database_id: str, collection_id: str, documents: List[dict]) -> Dict[str, Any]:
18141814
"""
1815+
**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.
1816+
18151817
Create new Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
18161818
18171819
Parameters
@@ -1854,10 +1856,11 @@ def create_documents(self, database_id: str, collection_id: str, documents: List
18541856
'content-type': 'application/json',
18551857
}, api_params)
18561858

1857-
def upsert_documents(self, database_id: str, collection_id: str, documents: List[dict] = None) -> Dict[str, Any]:
1859+
def upsert_documents(self, database_id: str, collection_id: str, documents: List[dict]) -> Dict[str, Any]:
18581860
"""
1859-
Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
1861+
**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.
18601862
1863+
Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
18611864
18621865
Parameters
18631866
----------
@@ -1887,6 +1890,9 @@ def upsert_documents(self, database_id: str, collection_id: str, documents: List
18871890
if collection_id is None:
18881891
raise AppwriteException('Missing required parameter: "collection_id"')
18891892

1893+
if documents is None:
1894+
raise AppwriteException('Missing required parameter: "documents"')
1895+
18901896
api_path = api_path.replace('{databaseId}', database_id)
18911897
api_path = api_path.replace('{collectionId}', collection_id)
18921898

@@ -1898,6 +1904,8 @@ def upsert_documents(self, database_id: str, collection_id: str, documents: List
18981904

18991905
def update_documents(self, database_id: str, collection_id: str, data: dict = None, queries: List[str] = None) -> Dict[str, Any]:
19001906
"""
1907+
**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.
1908+
19011909
Update all documents that match your queries, if no queries are submitted then all documents are updated. You can pass only specific fields to be updated.
19021910
19031911
Parameters
@@ -1942,6 +1950,8 @@ def update_documents(self, database_id: str, collection_id: str, data: dict = No
19421950

19431951
def delete_documents(self, database_id: str, collection_id: str, queries: List[str] = None) -> Dict[str, Any]:
19441952
"""
1953+
**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.
1954+
19451955
Bulk delete documents using queries, if no queries are passed then all documents are deleted.
19461956
19471957
Parameters
@@ -2027,6 +2037,61 @@ def get_document(self, database_id: str, collection_id: str, document_id: str, q
20272037
return self.client.call('get', api_path, {
20282038
}, api_params)
20292039

2040+
def upsert_document(self, database_id: str, collection_id: str, document_id: str, data: dict, permissions: List[str] = None) -> Dict[str, Any]:
2041+
"""
2042+
**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions.
2043+
2044+
Create or update a Document. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.
2045+
2046+
Parameters
2047+
----------
2048+
database_id : str
2049+
Database ID.
2050+
collection_id : str
2051+
Collection ID.
2052+
document_id : str
2053+
Document ID.
2054+
data : dict
2055+
Document data as JSON object. Include all required attributes of the document to be created or updated.
2056+
permissions : List[str]
2057+
An array of permissions strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).
2058+
2059+
Returns
2060+
-------
2061+
Dict[str, Any]
2062+
API response as a dictionary
2063+
2064+
Raises
2065+
------
2066+
AppwriteException
2067+
If API request fails
2068+
"""
2069+
2070+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}'
2071+
api_params = {}
2072+
if database_id is None:
2073+
raise AppwriteException('Missing required parameter: "database_id"')
2074+
2075+
if collection_id is None:
2076+
raise AppwriteException('Missing required parameter: "collection_id"')
2077+
2078+
if document_id is None:
2079+
raise AppwriteException('Missing required parameter: "document_id"')
2080+
2081+
if data is None:
2082+
raise AppwriteException('Missing required parameter: "data"')
2083+
2084+
api_path = api_path.replace('{databaseId}', database_id)
2085+
api_path = api_path.replace('{collectionId}', collection_id)
2086+
api_path = api_path.replace('{documentId}', document_id)
2087+
2088+
api_params['data'] = data
2089+
api_params['permissions'] = permissions
2090+
2091+
return self.client.call('put', api_path, {
2092+
'content-type': 'application/json',
2093+
}, api_params)
2094+
20302095
def update_document(self, database_id: str, collection_id: str, document_id: str, data: dict = None, permissions: List[str] = None) -> Dict[str, Any]:
20312096
"""
20322097
Update a document by its unique ID. Using the patch method you can pass only specific fields that will get updated.
@@ -2121,6 +2186,118 @@ def delete_document(self, database_id: str, collection_id: str, document_id: str
21212186
'content-type': 'application/json',
21222187
}, api_params)
21232188

2189+
def decrement_document_attribute(self, database_id: str, collection_id: str, document_id: str, attribute: str, value: float = None, min: float = None) -> Dict[str, Any]:
2190+
"""
2191+
Decrement a specific attribute of a document by a given value.
2192+
2193+
Parameters
2194+
----------
2195+
database_id : str
2196+
Database ID.
2197+
collection_id : str
2198+
Collection ID.
2199+
document_id : str
2200+
Document ID.
2201+
attribute : str
2202+
Attribute key.
2203+
value : float
2204+
Value to decrement the attribute by. The value must be a number.
2205+
min : float
2206+
Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.
2207+
2208+
Returns
2209+
-------
2210+
Dict[str, Any]
2211+
API response as a dictionary
2212+
2213+
Raises
2214+
------
2215+
AppwriteException
2216+
If API request fails
2217+
"""
2218+
2219+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'
2220+
api_params = {}
2221+
if database_id is None:
2222+
raise AppwriteException('Missing required parameter: "database_id"')
2223+
2224+
if collection_id is None:
2225+
raise AppwriteException('Missing required parameter: "collection_id"')
2226+
2227+
if document_id is None:
2228+
raise AppwriteException('Missing required parameter: "document_id"')
2229+
2230+
if attribute is None:
2231+
raise AppwriteException('Missing required parameter: "attribute"')
2232+
2233+
api_path = api_path.replace('{databaseId}', database_id)
2234+
api_path = api_path.replace('{collectionId}', collection_id)
2235+
api_path = api_path.replace('{documentId}', document_id)
2236+
api_path = api_path.replace('{attribute}', attribute)
2237+
2238+
api_params['value'] = value
2239+
api_params['min'] = min
2240+
2241+
return self.client.call('patch', api_path, {
2242+
'content-type': 'application/json',
2243+
}, api_params)
2244+
2245+
def increment_document_attribute(self, database_id: str, collection_id: str, document_id: str, attribute: str, value: float = None, max: float = None) -> Dict[str, Any]:
2246+
"""
2247+
Increment a specific attribute of a document by a given value.
2248+
2249+
Parameters
2250+
----------
2251+
database_id : str
2252+
Database ID.
2253+
collection_id : str
2254+
Collection ID.
2255+
document_id : str
2256+
Document ID.
2257+
attribute : str
2258+
Attribute key.
2259+
value : float
2260+
Value to increment the attribute by. The value must be a number.
2261+
max : float
2262+
Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.
2263+
2264+
Returns
2265+
-------
2266+
Dict[str, Any]
2267+
API response as a dictionary
2268+
2269+
Raises
2270+
------
2271+
AppwriteException
2272+
If API request fails
2273+
"""
2274+
2275+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'
2276+
api_params = {}
2277+
if database_id is None:
2278+
raise AppwriteException('Missing required parameter: "database_id"')
2279+
2280+
if collection_id is None:
2281+
raise AppwriteException('Missing required parameter: "collection_id"')
2282+
2283+
if document_id is None:
2284+
raise AppwriteException('Missing required parameter: "document_id"')
2285+
2286+
if attribute is None:
2287+
raise AppwriteException('Missing required parameter: "attribute"')
2288+
2289+
api_path = api_path.replace('{databaseId}', database_id)
2290+
api_path = api_path.replace('{collectionId}', collection_id)
2291+
api_path = api_path.replace('{documentId}', document_id)
2292+
api_path = api_path.replace('{attribute}', attribute)
2293+
2294+
api_params['value'] = value
2295+
api_params['max'] = max
2296+
2297+
return self.client.call('patch', api_path, {
2298+
'content-type': 'application/json',
2299+
}, api_params)
2300+
21242301
def list_indexes(self, database_id: str, collection_id: str, queries: List[str] = None) -> Dict[str, Any]:
21252302
"""
21262303
List indexes in the collection.

appwrite/services/tokens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def list(self, bucket_id: str, file_id: str, queries: List[str] = None) -> Dict[
4949

5050
def create_file_token(self, bucket_id: str, file_id: str, expire: str = None) -> Dict[str, Any]:
5151
"""
52-
Create a new token. A token is linked to a file. Token can be passed as a header or request get parameter.
52+
Create a new token. A token is linked to a file. Token can be passed as a request URL search parameter.
5353
5454
Parameters
5555
----------

appwrite/services/users.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1345,7 +1345,7 @@ def list_targets(self, user_id: str, queries: List[str] = None) -> Dict[str, Any
13451345
user_id : str
13461346
User ID.
13471347
queries : List[str]
1348-
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels
1348+
Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, providerId, identifier, providerType
13491349
13501350
Returns
13511351
-------

docs/examples/databases/create-document.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ from appwrite.services.databases import Databases
33

44
client = Client()
55
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_admin('') #
67
client.set_session('') # The user session to authenticate with
78
client.set_key('<YOUR_API_KEY>') # Your secret API key
89
client.set_jwt('<YOUR_JWT>') # Your secret JSON Web Token
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from appwrite.client import Client
2+
from appwrite.services.databases import Databases
3+
4+
client = Client()
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
7+
client.set_key('<YOUR_API_KEY>') # Your secret API key
8+
9+
databases = Databases(client)
10+
11+
result = databases.decrement_document_attribute(
12+
database_id = '<DATABASE_ID>',
13+
collection_id = '<COLLECTION_ID>',
14+
document_id = '<DOCUMENT_ID>',
15+
attribute = '',
16+
value = None, # optional
17+
min = None # optional
18+
)

0 commit comments

Comments
 (0)