Skip to content

Commit 51664a7

Browse files
committed
add backups service
1 parent ba131a9 commit 51664a7

36 files changed

Lines changed: 1252 additions & 14 deletions

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.8.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 latest. 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 abstracts and simplifies 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/encoders/value_class_encoder.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from ..enums.scopes import Scopes
23
from ..enums.authenticator_type import AuthenticatorType
34
from ..enums.authentication_factor import AuthenticationFactor
45
from ..enums.o_auth_provider import OAuthProvider
@@ -9,12 +10,12 @@
910
from ..enums.timezone import Timezone
1011
from ..enums.browser_permission import BrowserPermission
1112
from ..enums.image_format import ImageFormat
13+
from ..enums.backup_services import BackupServices
1214
from ..enums.relationship_type import RelationshipType
1315
from ..enums.relation_mutate import RelationMutate
1416
from ..enums.index_type import IndexType
1517
from ..enums.order_by import OrderBy
1618
from ..enums.runtime import Runtime
17-
from ..enums.scopes import Scopes
1819
from ..enums.template_reference_type import TemplateReferenceType
1920
from ..enums.vcs_reference_type import VCSReferenceType
2021
from ..enums.deployment_download_type import DeploymentDownloadType
@@ -42,6 +43,9 @@
4243

4344
class ValueClassEncoder(json.JSONEncoder):
4445
def default(self, o):
46+
if isinstance(o, Scopes):
47+
return o.value
48+
4549
if isinstance(o, AuthenticatorType):
4650
return o.value
4751

@@ -72,6 +76,9 @@ def default(self, o):
7276
if isinstance(o, ImageFormat):
7377
return o.value
7478

79+
if isinstance(o, BackupServices):
80+
return o.value
81+
7582
if isinstance(o, RelationshipType):
7683
return o.value
7784

@@ -87,9 +94,6 @@ def default(self, o):
8794
if isinstance(o, Runtime):
8895
return o.value
8996

90-
if isinstance(o, Scopes):
91-
return o.value
92-
9397
if isinstance(o, TemplateReferenceType):
9498
return o.value
9599

appwrite/enums/backup_services.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 BackupServices(Enum):
4+
DATABASES = "databases"
5+
FUNCTIONS = "functions"
6+
STORAGE = "storage"

appwrite/enums/build_runtime.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class BuildRuntime(Enum):
2323
PYTHON_3_12 = "python-3.12"
2424
PYTHON_ML_3_11 = "python-ml-3.11"
2525
PYTHON_ML_3_12 = "python-ml-3.12"
26-
DENO_1_21 = "deno-1.21"
27-
DENO_1_24 = "deno-1.24"
28-
DENO_1_35 = "deno-1.35"
2926
DENO_1_40 = "deno-1.40"
3027
DENO_1_46 = "deno-1.46"
3128
DENO_2_0 = "deno-2.0"

appwrite/enums/o_auth_provider.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ class OAuthProvider(Enum):
4040
YANDEX = "yandex"
4141
ZOHO = "zoho"
4242
ZOOM = "zoom"
43+
GITHUBIMAGINE = "githubImagine"
44+
GOOGLEIMAGINE = "googleImagine"

appwrite/enums/runtime.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@ class Runtime(Enum):
2323
PYTHON_3_12 = "python-3.12"
2424
PYTHON_ML_3_11 = "python-ml-3.11"
2525
PYTHON_ML_3_12 = "python-ml-3.12"
26-
DENO_1_21 = "deno-1.21"
27-
DENO_1_24 = "deno-1.24"
28-
DENO_1_35 = "deno-1.35"
2926
DENO_1_40 = "deno-1.40"
3027
DENO_1_46 = "deno-1.46"
3128
DENO_2_0 = "deno-2.0"

appwrite/enums/scopes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ class Scopes(Enum):
5656
ASSISTANT_READ = "assistant.read"
5757
TOKENS_READ = "tokens.read"
5858
TOKENS_WRITE = "tokens.write"
59+
POLICIES_WRITE = "policies.write"
60+
POLICIES_READ = "policies.read"
61+
ARCHIVES_READ = "archives.read"
62+
ARCHIVES_WRITE = "archives.write"
63+
RESTORATIONS_READ = "restorations.read"
64+
RESTORATIONS_WRITE = "restorations.write"
65+
DOMAINS_READ = "domains.read"
66+
DOMAINS_WRITE = "domains.write"

appwrite/services/account.py

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import List, Dict, Any, Optional
33
from ..exception import AppwriteException
44
from appwrite.utils.deprecated import deprecated
5+
from ..enums.scopes import Scopes;
56
from ..enums.authenticator_type import AuthenticatorType;
67
from ..enums.authentication_factor import AuthenticationFactor;
78
from ..enums.o_auth_provider import OAuthProvider;
@@ -215,6 +216,186 @@ def create_jwt(self, duration: Optional[float] = None) -> Dict[str, Any]:
215216
'content-type': 'application/json',
216217
}, api_params)
217218

219+
def list_keys(self, total: Optional[bool] = None) -> Dict[str, Any]:
220+
"""
221+
Get a list of all API keys from the current account.
222+
223+
Parameters
224+
----------
225+
total : Optional[bool]
226+
When set to false, the total count returned will be 0 and will not be calculated.
227+
228+
Returns
229+
-------
230+
Dict[str, Any]
231+
API response as a dictionary
232+
233+
Raises
234+
------
235+
AppwriteException
236+
If API request fails
237+
"""
238+
239+
api_path = '/account/keys'
240+
api_params = {}
241+
242+
if total is not None:
243+
api_params['total'] = total
244+
245+
return self.client.call('get', api_path, {
246+
}, api_params)
247+
248+
def create_key(self, name: str, scopes: List[Scopes], expire: Optional[str] = None) -> Dict[str, Any]:
249+
"""
250+
Create a new account API key.
251+
252+
Parameters
253+
----------
254+
name : str
255+
Key name. Max length: 128 chars.
256+
scopes : List[Scopes]
257+
Key scopes list. Maximum of 100 scopes are allowed.
258+
expire : Optional[str]
259+
Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.
260+
261+
Returns
262+
-------
263+
Dict[str, Any]
264+
API response as a dictionary
265+
266+
Raises
267+
------
268+
AppwriteException
269+
If API request fails
270+
"""
271+
272+
api_path = '/account/keys'
273+
api_params = {}
274+
if name is None:
275+
raise AppwriteException('Missing required parameter: "name"')
276+
277+
if scopes is None:
278+
raise AppwriteException('Missing required parameter: "scopes"')
279+
280+
281+
api_params['name'] = name
282+
api_params['scopes'] = scopes
283+
api_params['expire'] = expire
284+
285+
return self.client.call('post', api_path, {
286+
'content-type': 'application/json',
287+
}, api_params)
288+
289+
def get_key(self, key_id: str) -> Dict[str, Any]:
290+
"""
291+
Get a key by its unique ID. This endpoint returns details about a specific API key in your account including it's scopes.
292+
293+
Parameters
294+
----------
295+
key_id : str
296+
Key unique ID.
297+
298+
Returns
299+
-------
300+
Dict[str, Any]
301+
API response as a dictionary
302+
303+
Raises
304+
------
305+
AppwriteException
306+
If API request fails
307+
"""
308+
309+
api_path = '/account/keys/{keyId}'
310+
api_params = {}
311+
if key_id is None:
312+
raise AppwriteException('Missing required parameter: "key_id"')
313+
314+
api_path = api_path.replace('{keyId}', key_id)
315+
316+
317+
return self.client.call('get', api_path, {
318+
}, api_params)
319+
320+
def update_key(self, key_id: str, name: str, scopes: List[Scopes], expire: Optional[str] = None) -> Dict[str, Any]:
321+
"""
322+
Update a key by its unique ID. Use this endpoint to update the name, scopes, or expiration time of an API key.
323+
324+
Parameters
325+
----------
326+
key_id : str
327+
Key unique ID.
328+
name : str
329+
Key name. Max length: 128 chars.
330+
scopes : List[Scopes]
331+
Key scopes list. Maximum of 100 scopes are allowed.
332+
expire : Optional[str]
333+
Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.
334+
335+
Returns
336+
-------
337+
Dict[str, Any]
338+
API response as a dictionary
339+
340+
Raises
341+
------
342+
AppwriteException
343+
If API request fails
344+
"""
345+
346+
api_path = '/account/keys/{keyId}'
347+
api_params = {}
348+
if key_id is None:
349+
raise AppwriteException('Missing required parameter: "key_id"')
350+
351+
if name is None:
352+
raise AppwriteException('Missing required parameter: "name"')
353+
354+
if scopes is None:
355+
raise AppwriteException('Missing required parameter: "scopes"')
356+
357+
api_path = api_path.replace('{keyId}', key_id)
358+
359+
api_params['name'] = name
360+
api_params['scopes'] = scopes
361+
api_params['expire'] = expire
362+
363+
return self.client.call('put', api_path, {
364+
'content-type': 'application/json',
365+
}, api_params)
366+
367+
def delete_key(self, key_id: str) -> Dict[str, Any]:
368+
"""
369+
Delete a key by its unique ID. Once deleted, the key can no longer be used to authenticate API calls.
370+
371+
Parameters
372+
----------
373+
key_id : str
374+
Key unique ID.
375+
376+
Returns
377+
-------
378+
Dict[str, Any]
379+
API response as a dictionary
380+
381+
Raises
382+
------
383+
AppwriteException
384+
If API request fails
385+
"""
386+
387+
api_path = '/account/keys/{keyId}'
388+
api_params = {}
389+
if key_id is None:
390+
raise AppwriteException('Missing required parameter: "key_id"')
391+
392+
api_path = api_path.replace('{keyId}', key_id)
393+
394+
395+
return self.client.call('delete', api_path, {
396+
'content-type': 'application/json',
397+
}, api_params)
398+
218399
def list_logs(self, queries: Optional[List[str]] = None, total: Optional[bool] = None) -> Dict[str, Any]:
219400
"""
220401
Get the list of latest security activity logs for the currently logged in user. Each log returns user IP address, location and date and time of log.
@@ -1228,7 +1409,7 @@ def create_o_auth2_token(self, provider: OAuthProvider, success: Optional[str] =
12281409
Parameters
12291410
----------
12301411
provider : OAuthProvider
1231-
OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom.
1412+
OAuth2 Provider. Currently, supported providers are: amazon, apple, auth0, authentik, autodesk, bitbucket, bitly, box, dailymotion, discord, disqus, dropbox, etsy, facebook, figma, github, gitlab, google, linkedin, microsoft, notion, oidc, okta, paypal, paypalSandbox, podio, salesforce, slack, spotify, stripe, tradeshift, tradeshiftBox, twitch, wordpress, yahoo, yammer, yandex, zoho, zoom, githubImagine, googleImagine.
12321413
success : Optional[str]
12331414
URL to redirect back to your app after a successful login attempt. Only URLs from hostnames in your project's platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.
12341415
failure : Optional[str]

0 commit comments

Comments
 (0)