Skip to content

Commit ec6af74

Browse files
committed
Add bulk API methods
1 parent 2415efa commit ec6af74

File tree

269 files changed

+499
-267
lines changed

Some content is hidden

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

269 files changed

+499
-267
lines changed

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/10.0.0 ({platform.uname().system}; {platform.uname().version}; {platform.uname().machine})',
17+
'user-agent' : f'AppwritePythonSDK/10.1.0-rc.1 ({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': '10.0.0',
21+
'x-sdk-version': '10.1.0-rc.1',
2222
'X-Appwrite-Response-Format' : '1.6.0',
2323
}
2424

appwrite/services/databases.py

Lines changed: 172 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,6 @@ def list_documents(self, database_id: str, collection_id: str, queries: List[str
17601760
def create_document(self, database_id: str, collection_id: str, document_id: str, data: dict, permissions: List[str] = None) -> Dict[str, Any]:
17611761
"""
17621762
Create a new 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.
1763-
17641763
17651764
Parameters
17661765
----------
@@ -1811,6 +1810,178 @@ def create_document(self, database_id: str, collection_id: str, document_id: str
18111810
'content-type': 'application/json',
18121811
}, api_params)
18131812

1813+
def create_documents(self, database_id: str, collection_id: str, documents: List[dict]) -> Dict[str, Any]:
1814+
"""
1815+
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.
1816+
1817+
1818+
Parameters
1819+
----------
1820+
database_id : str
1821+
Database ID.
1822+
collection_id : str
1823+
Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection). Make sure to define attributes before creating documents.
1824+
documents : List[dict]
1825+
Array of documents data as JSON objects.
1826+
1827+
Returns
1828+
-------
1829+
Dict[str, Any]
1830+
API response as a dictionary
1831+
1832+
Raises
1833+
------
1834+
AppwriteException
1835+
If API request fails
1836+
"""
1837+
1838+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents'
1839+
api_params = {}
1840+
if database_id is None:
1841+
raise AppwriteException('Missing required parameter: "database_id"')
1842+
1843+
if collection_id is None:
1844+
raise AppwriteException('Missing required parameter: "collection_id"')
1845+
1846+
if documents is None:
1847+
raise AppwriteException('Missing required parameter: "documents"')
1848+
1849+
api_path = api_path.replace('{databaseId}', database_id)
1850+
api_path = api_path.replace('{collectionId}', collection_id)
1851+
1852+
api_params['documents'] = documents
1853+
1854+
return self.client.call('post', api_path, {
1855+
'content-type': 'application/json',
1856+
}, api_params)
1857+
1858+
def upsert_documents(self, database_id: str, collection_id: str, documents: List[dict] = None) -> Dict[str, Any]:
1859+
"""
1860+
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+
1862+
1863+
Parameters
1864+
----------
1865+
database_id : str
1866+
Database ID.
1867+
collection_id : str
1868+
Collection ID.
1869+
documents : List[dict]
1870+
Array of document data as JSON objects. May contain partial documents.
1871+
1872+
Returns
1873+
-------
1874+
Dict[str, Any]
1875+
API response as a dictionary
1876+
1877+
Raises
1878+
------
1879+
AppwriteException
1880+
If API request fails
1881+
"""
1882+
1883+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents'
1884+
api_params = {}
1885+
if database_id is None:
1886+
raise AppwriteException('Missing required parameter: "database_id"')
1887+
1888+
if collection_id is None:
1889+
raise AppwriteException('Missing required parameter: "collection_id"')
1890+
1891+
api_path = api_path.replace('{databaseId}', database_id)
1892+
api_path = api_path.replace('{collectionId}', collection_id)
1893+
1894+
api_params['documents'] = documents
1895+
1896+
return self.client.call('put', api_path, {
1897+
'content-type': 'application/json',
1898+
}, api_params)
1899+
1900+
def update_documents(self, database_id: str, collection_id: str, data: dict = None, queries: List[str] = None) -> Dict[str, Any]:
1901+
"""
1902+
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.
1903+
1904+
Parameters
1905+
----------
1906+
database_id : str
1907+
Database ID.
1908+
collection_id : str
1909+
Collection ID.
1910+
data : dict
1911+
Document data as JSON object. Include only attribute and value pairs to be updated.
1912+
queries : List[str]
1913+
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.
1914+
1915+
Returns
1916+
-------
1917+
Dict[str, Any]
1918+
API response as a dictionary
1919+
1920+
Raises
1921+
------
1922+
AppwriteException
1923+
If API request fails
1924+
"""
1925+
1926+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents'
1927+
api_params = {}
1928+
if database_id is None:
1929+
raise AppwriteException('Missing required parameter: "database_id"')
1930+
1931+
if collection_id is None:
1932+
raise AppwriteException('Missing required parameter: "collection_id"')
1933+
1934+
api_path = api_path.replace('{databaseId}', database_id)
1935+
api_path = api_path.replace('{collectionId}', collection_id)
1936+
1937+
api_params['data'] = data
1938+
api_params['queries'] = queries
1939+
1940+
return self.client.call('patch', api_path, {
1941+
'content-type': 'application/json',
1942+
}, api_params)
1943+
1944+
def delete_documents(self, database_id: str, collection_id: str, queries: List[str] = None) -> Dict[str, Any]:
1945+
"""
1946+
Bulk delete documents using queries, if no queries are passed then all documents are deleted.
1947+
1948+
Parameters
1949+
----------
1950+
database_id : str
1951+
Database ID.
1952+
collection_id : str
1953+
Collection ID. You can create a new collection using the Database service [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection).
1954+
queries : List[str]
1955+
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.
1956+
1957+
Returns
1958+
-------
1959+
Dict[str, Any]
1960+
API response as a dictionary
1961+
1962+
Raises
1963+
------
1964+
AppwriteException
1965+
If API request fails
1966+
"""
1967+
1968+
api_path = '/databases/{databaseId}/collections/{collectionId}/documents'
1969+
api_params = {}
1970+
if database_id is None:
1971+
raise AppwriteException('Missing required parameter: "database_id"')
1972+
1973+
if collection_id is None:
1974+
raise AppwriteException('Missing required parameter: "collection_id"')
1975+
1976+
api_path = api_path.replace('{databaseId}', database_id)
1977+
api_path = api_path.replace('{collectionId}', collection_id)
1978+
1979+
api_params['queries'] = queries
1980+
1981+
return self.client.call('delete', api_path, {
1982+
'content-type': 'application/json',
1983+
}, api_params)
1984+
18141985
def get_document(self, database_id: str, collection_id: str, document_id: str, queries: List[str] = None) -> Dict[str, Any]:
18151986
"""
18161987
Get a document by its unique ID. This endpoint response returns a JSON object with the document data.

docs/examples/account/create-anonymous-session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/create-email-password-session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/create-j-w-t.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/create-mfa-authenticator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from appwrite.services.account import Account
33
from appwrite.enums import AuthenticatorType
44

55
client = Client()
6-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
77
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
88
client.set_session('') # The user session to authenticate with
99

docs/examples/account/create-mfa-challenge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from appwrite.services.account import Account
33
from appwrite.enums import AuthenticationFactor
44

55
client = Client()
6-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
77
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
88

99
account = Account(client)

docs/examples/account/create-mfa-recovery-codes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from appwrite.services.account import Account
33
from appwrite.enums import OAuthProvider
44

55
client = Client()
6-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
77
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
88

99
account = Account(client)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/create-phone-verification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/create-recovery.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/create-session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/create-verification.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/create.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77

88
account = Account(client)

docs/examples/account/delete-identity.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/delete-mfa-authenticator.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ from appwrite.services.account import Account
33
from appwrite.enums import AuthenticatorType
44

55
client = Client()
6-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
6+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
77
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
88
client.set_session('') # The user session to authenticate with
99

docs/examples/account/delete-session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/delete-sessions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/get-mfa-recovery-codes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/get-prefs.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

docs/examples/account/get-session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ from appwrite.client import Client
22
from appwrite.services.account import Account
33

44
client = Client()
5-
client.set_endpoint('https://cloud.appwrite.io/v1') # Your API Endpoint
5+
client.set_endpoint('https://<REGION>.cloud.appwrite.io/v1') # Your API Endpoint
66
client.set_project('<YOUR_PROJECT_ID>') # Your project ID
77
client.set_session('') # The user session to authenticate with
88

0 commit comments

Comments
 (0)