mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Updated SDKs
This commit is contained in:
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import requests
|
||||
|
||||
|
||||
class Client:
|
||||
def __init__(self):
|
||||
self._self_signed = False
|
||||
self._endpoint = 'https://appwrite.io/v1'
|
||||
self._global_headers = {
|
||||
'content-type': '',
|
||||
'x-sdk-version': 'appwrite:python:0.0.3',
|
||||
}
|
||||
|
||||
def set_self_signed(self, status=True):
|
||||
self._self_signed = status
|
||||
return self
|
||||
|
||||
def set_endpoint(self, endpoint):
|
||||
self._endpoint = endpoint
|
||||
return self
|
||||
|
||||
def add_header(self, key, value):
|
||||
self._global_headers[key.lower()] = value.lower()
|
||||
return self
|
||||
|
||||
def set_project(self, value):
|
||||
"""Your project ID"""
|
||||
|
||||
self._global_headers['x-appwrite-project'] = value.lower()
|
||||
return self
|
||||
|
||||
def set_key(self, value):
|
||||
"""Your secret API key"""
|
||||
|
||||
self._global_headers['x-appwrite-key'] = value.lower()
|
||||
return self
|
||||
|
||||
def set_locale(self, value):
|
||||
self._global_headers['x-appwrite-locale'] = value.lower()
|
||||
return self
|
||||
|
||||
def set_mode(self, value):
|
||||
self._global_headers['x-appwrite-mode'] = value.lower()
|
||||
return self
|
||||
|
||||
def call(self, method, path='', headers=None, params=None):
|
||||
if headers is None:
|
||||
headers = {}
|
||||
|
||||
if params is None:
|
||||
params = {}
|
||||
|
||||
data = {}
|
||||
json = {}
|
||||
|
||||
self._global_headers.update(headers)
|
||||
|
||||
if method != 'get':
|
||||
data = params
|
||||
params = {}
|
||||
|
||||
if headers['content-type'] == 'application/json':
|
||||
json = data
|
||||
data = {}
|
||||
|
||||
response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554
|
||||
method=method,
|
||||
url=self._endpoint + path,
|
||||
params=params,
|
||||
data=data,
|
||||
json=json,
|
||||
headers=self._global_headers,
|
||||
verify=self._self_signed,
|
||||
)
|
||||
|
||||
response.raise_for_status()
|
||||
|
||||
content_type = response.headers['Content-Type']
|
||||
|
||||
if content_type.startswith('application/json'):
|
||||
return response.json()
|
||||
|
||||
return response._content
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
from .client import Client
|
||||
|
||||
|
||||
class Service:
|
||||
def __init__(self, client: Client):
|
||||
self.client = client
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Avatars(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Avatars, self).__init__(client)
|
||||
|
||||
def get_browser(self, code, width=100, height=100, quality=100):
|
||||
"""Get Browser Icon"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/browsers/{code}'
|
||||
path = path.replace('{code}', code)
|
||||
params['width'] = width
|
||||
params['height'] = height
|
||||
params['quality'] = quality
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_credit_card(self, code, width=100, height=100, quality=100):
|
||||
"""Get Credit Card Icon"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/credit-cards/{code}'
|
||||
path = path.replace('{code}', code)
|
||||
params['width'] = width
|
||||
params['height'] = height
|
||||
params['quality'] = quality
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_favicon(self, url):
|
||||
"""Get Favicon"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/favicon'
|
||||
params['url'] = url
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_flag(self, code, width=100, height=100, quality=100):
|
||||
"""Get Country Flag"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/flags/{code}'
|
||||
path = path.replace('{code}', code)
|
||||
params['width'] = width
|
||||
params['height'] = height
|
||||
params['quality'] = quality
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_image(self, url, width=400, height=400):
|
||||
"""Get Image from URL"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/image'
|
||||
params['url'] = url
|
||||
params['width'] = width
|
||||
params['height'] = height
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_q_r(self, text, size=400, margin=1, download=0):
|
||||
"""Get QR Code"""
|
||||
|
||||
params = {}
|
||||
path = '/avatars/qr'
|
||||
params['text'] = text
|
||||
params['size'] = size
|
||||
params['margin'] = margin
|
||||
params['download'] = download
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
@@ -0,0 +1,148 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Database(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Database, self).__init__(client)
|
||||
|
||||
def list_collections(self, search='', limit=25, offset=0, order_type='ASC'):
|
||||
"""List Collections"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections'
|
||||
params['search'] = search
|
||||
params['limit'] = limit
|
||||
params['offset'] = offset
|
||||
params['orderType'] = order_type
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create_collection(self, name, read, write, rules):
|
||||
"""Create Collection"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections'
|
||||
params['name'] = name
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
params['rules'] = rules
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_collection(self, collection_id):
|
||||
"""Get Collection"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update_collection(self, collection_id, name, read, write, rules=[]):
|
||||
"""Update Collection"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
params['name'] = name
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
params['rules'] = rules
|
||||
|
||||
return self.client.call('put', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_collection(self, collection_id):
|
||||
"""Delete Collection"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def list_documents(self, collection_id, filters=[], offset=0, limit=50, order_field='$id', order_type='ASC', order_cast='string', search='', first=0, last=0):
|
||||
"""List Documents"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}/documents'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
params['filters'] = filters
|
||||
params['offset'] = offset
|
||||
params['limit'] = limit
|
||||
params['order-field'] = order_field
|
||||
params['order-type'] = order_type
|
||||
params['order-cast'] = order_cast
|
||||
params['search'] = search
|
||||
params['first'] = first
|
||||
params['last'] = last
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create_document(self, collection_id, data, read, write, parent_document='', parent_property='', parent_property_type='assign'):
|
||||
"""Create Document"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}/documents'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
params['data'] = data
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
params['parentDocument'] = parent_document
|
||||
params['parentProperty'] = parent_property
|
||||
params['parentPropertyType'] = parent_property_type
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_document(self, collection_id, document_id):
|
||||
"""Get Document"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}/documents/{documentId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
path = path.replace('{documentId}', document_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update_document(self, collection_id, document_id, data, read, write):
|
||||
"""Update Document"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}/documents/{documentId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
path = path.replace('{documentId}', document_id)
|
||||
params['data'] = data
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
|
||||
return self.client.call('patch', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_document(self, collection_id, document_id):
|
||||
"""Delete Document"""
|
||||
|
||||
params = {}
|
||||
path = '/database/collections/{collectionId}/documents/{documentId}'
|
||||
path = path.replace('{collectionId}', collection_id)
|
||||
path = path.replace('{documentId}', document_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
@@ -0,0 +1,67 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Locale(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Locale, self).__init__(client)
|
||||
|
||||
def get(self):
|
||||
"""Get User Locale"""
|
||||
|
||||
params = {}
|
||||
path = '/locale'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_continents(self):
|
||||
"""List Countries"""
|
||||
|
||||
params = {}
|
||||
path = '/locale/continents'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_countries(self):
|
||||
"""List Countries"""
|
||||
|
||||
params = {}
|
||||
path = '/locale/countries'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_countries_e_u(self):
|
||||
"""List EU Countries"""
|
||||
|
||||
params = {}
|
||||
path = '/locale/countries/eu'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_countries_phones(self):
|
||||
"""List Countries Phone Codes"""
|
||||
|
||||
params = {}
|
||||
path = '/locale/countries/phones'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_currencies(self):
|
||||
"""List Currencies"""
|
||||
|
||||
params = {}
|
||||
path = '/locale/currencies'
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
@@ -0,0 +1,108 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Storage(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Storage, self).__init__(client)
|
||||
|
||||
def list_files(self, search='', limit=25, offset=0, order_type='ASC'):
|
||||
"""List Files"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files'
|
||||
params['search'] = search
|
||||
params['limit'] = limit
|
||||
params['offset'] = offset
|
||||
params['orderType'] = order_type
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create_file(self, file, read, write):
|
||||
"""Create File"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files'
|
||||
params['file'] = file
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'multipart/form-data',
|
||||
}, params)
|
||||
|
||||
def get_file(self, file_id):
|
||||
"""Get File"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update_file(self, file_id, read, write):
|
||||
"""Update File"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
params['read'] = read
|
||||
params['write'] = write
|
||||
|
||||
return self.client.call('put', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_file(self, file_id):
|
||||
"""Delete File"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_file_download(self, file_id):
|
||||
"""Get File for Download"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}/download'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_file_preview(self, file_id, width=0, height=0, quality=100, background='', output=''):
|
||||
"""Get File Preview"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}/preview'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
params['width'] = width
|
||||
params['height'] = height
|
||||
params['quality'] = quality
|
||||
params['background'] = background
|
||||
params['output'] = output
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_file_view(self, file_id, xas=''):
|
||||
"""Get File for View"""
|
||||
|
||||
params = {}
|
||||
path = '/storage/files/{fileId}/view'
|
||||
path = path.replace('{fileId}', file_id)
|
||||
params['as'] = xas
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
@@ -0,0 +1,105 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Teams(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Teams, self).__init__(client)
|
||||
|
||||
def list(self, search='', limit=25, offset=0, order_type='ASC'):
|
||||
"""List Teams"""
|
||||
|
||||
params = {}
|
||||
path = '/teams'
|
||||
params['search'] = search
|
||||
params['limit'] = limit
|
||||
params['offset'] = offset
|
||||
params['orderType'] = order_type
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create(self, name, roles=[]):
|
||||
"""Create Team"""
|
||||
|
||||
params = {}
|
||||
path = '/teams'
|
||||
params['name'] = name
|
||||
params['roles'] = roles
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get(self, team_id):
|
||||
"""Get Team"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update(self, team_id, name):
|
||||
"""Update Team"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
params['name'] = name
|
||||
|
||||
return self.client.call('put', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete(self, team_id):
|
||||
"""Delete Team"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_memberships(self, team_id):
|
||||
"""Get Team Memberships"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}/memberships'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create_membership(self, team_id, email, roles, url, name=''):
|
||||
"""Create Team Membership"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}/memberships'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
params['email'] = email
|
||||
params['name'] = name
|
||||
params['roles'] = roles
|
||||
params['url'] = url
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_membership(self, team_id, invite_id):
|
||||
"""Delete Team Membership"""
|
||||
|
||||
params = {}
|
||||
path = '/teams/{teamId}/memberships/{inviteId}'
|
||||
path = path.replace('{teamId}', team_id)
|
||||
path = path.replace('{inviteId}', invite_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
@@ -0,0 +1,125 @@
|
||||
from ..service import Service
|
||||
|
||||
|
||||
class Users(Service):
|
||||
|
||||
def __init__(self, client):
|
||||
super(Users, self).__init__(client)
|
||||
|
||||
def list(self, search='', limit=25, offset=0, order_type='ASC'):
|
||||
"""List Users"""
|
||||
|
||||
params = {}
|
||||
path = '/users'
|
||||
params['search'] = search
|
||||
params['limit'] = limit
|
||||
params['offset'] = offset
|
||||
params['orderType'] = order_type
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def create(self, email, password, name=''):
|
||||
"""Create User"""
|
||||
|
||||
params = {}
|
||||
path = '/users'
|
||||
params['email'] = email
|
||||
params['password'] = password
|
||||
params['name'] = name
|
||||
|
||||
return self.client.call('post', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get(self, user_id):
|
||||
"""Get User"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}'
|
||||
path = path.replace('{userId}', user_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_logs(self, user_id):
|
||||
"""Get User Logs"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/logs'
|
||||
path = path.replace('{userId}', user_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_prefs(self, user_id):
|
||||
"""Get User Preferences"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/prefs'
|
||||
path = path.replace('{userId}', user_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update_prefs(self, user_id, prefs):
|
||||
"""Update User Preferences"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/prefs'
|
||||
path = path.replace('{userId}', user_id)
|
||||
params['prefs'] = prefs
|
||||
|
||||
return self.client.call('patch', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def get_sessions(self, user_id):
|
||||
"""Get User Sessions"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/sessions'
|
||||
path = path.replace('{userId}', user_id)
|
||||
|
||||
return self.client.call('get', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_sessions(self, user_id):
|
||||
"""Delete User Sessions"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/sessions'
|
||||
path = path.replace('{userId}', user_id)
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def delete_session(self, user_id, session_id):
|
||||
"""Delete User Session"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/sessions/:session'
|
||||
path = path.replace('{userId}', user_id)
|
||||
params['sessionId'] = session_id
|
||||
|
||||
return self.client.call('delete', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
|
||||
def update_status(self, user_id, status):
|
||||
"""Update User Status"""
|
||||
|
||||
params = {}
|
||||
path = '/users/{userId}/status'
|
||||
path = path.replace('{userId}', user_id)
|
||||
params['status'] = status
|
||||
|
||||
return self.client.call('patch', path, {
|
||||
'content-type': 'application/json',
|
||||
}, params)
|
||||
Reference in New Issue
Block a user