Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
Appwrite backend as a service cuts up to 70% of the time and costs required for building a modern application. We abstract and simplify common development tasks behind a REST APIs, to help you develop your app in a fast and secure way. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)



![Appwrite](https://appwrite.io/images/github.png)

**API Version: latest**
Expand All @@ -21,6 +20,23 @@ To install via [PyPI](https://pypi.org/):
pip install appwrite
```

## Example

Here's a small and simple example:
```py
from appwrite import Account

account = Account ()
...
```

## Todo

ToDo list:
- Fix weird function arguments in `database.py` (`appwrite/services/database.py`)
- Fix weird function arguments in `storage.py` (`appwrite/services/storage.py`)
- Fix weird function arguments in `teams.py` (`appwrite/services/teams.py`)

## License

Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.
Please see the [BSD-3-Clause license](https://raw.githubusercontent.com/appwrite/appwrite/master/LICENSE) file for more information.
2 changes: 1 addition & 1 deletion appwrite/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import Client
40 changes: 24 additions & 16 deletions appwrite/client.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests


class Client:
def __init__(self):
self._self_signed = False
Expand All @@ -18,56 +17,65 @@ def set_endpoint(self, endpoint):
self._endpoint = endpoint
return self

def add_header(self, key, value):
def add_header(self, key: str, value: str):
if not (isinstance (key, str) or isinstance (value, str)):
raise TypeError ("Both key and value must be a string!")

self._global_headers[key.lower()] = value.lower()
return self

def set_project(self, value):
def set_project(self, value: str):
"""Your Appwrite project ID. You can find your project ID in your Appwrite console project settings."""

if not isinstance (value, str):
raise TypeError ("Value must be a string!")

self._global_headers['x-appwrite-project'] = value.lower()
return self

def set_key(self, value):
def set_key(self, value: str):
"""Your Appwrite project secret key. You can can create a new API key from your Appwrite console API keys dashboard."""

if not isinstance (value, str):
raise TypeError ("Value must be a string!")

self._global_headers['x-appwrite-key'] = value.lower()
return self

def set_locale(self, value):
def set_locale(self, value: str):
if not isinstance (value, str):
raise TypeError ("Value must be a string!")

self._global_headers['x-appwrite-locale'] = value.lower()
return self

def set_mode(self, value):
def set_mode(self, value: str):
if not isinstance (value, str):
raise TypeError ("Value must be a string!")

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 = {}

def call(self, method, path='', headers={}, params={}):
data = {}
json = {}
headers = {**self._global_headers, **headers}

if method != 'get':
data = params
params = {}
params.clear ()

if headers['content-type'] == 'application/json':
json = data
data = {}
data.clear ()

response = getattr(requests, method)( # call method dynamically https://stackoverflow.com/a/4246075/2299554
url=self._endpoint + path,
params=params,
data=data,
json=json,
headers=headers,
verify=self._self_signed,
verify=self._self_signed
)

return response
1 change: 0 additions & 1 deletion appwrite/service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .client import Client


class Service:
def __init__(self, client: Client):
self.client = client
10 changes: 9 additions & 1 deletion appwrite/services/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@

from .account import Account
from .auth import Auth
from .avatars import Avatars
from .database import Databse # Fix function arguments
from .locale import Locale
from .projects import Projects
from .storage import Storage # Fix function arguments
from .teams import Teams # Fix function arguments
from .users import Users
2 changes: 0 additions & 2 deletions appwrite/services/account.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..service import Service


class Account(Service):

def get(self):
"""Get Account"""

Expand Down
10 changes: 4 additions & 6 deletions appwrite/services/auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from ..service import Service


class Auth(Service):

def login(self, email, password, success='', failure=''):
"""Login User"""

Expand Down Expand Up @@ -30,7 +28,7 @@ def logout_by_session(self, id):

params = {}
path = '/auth/logout/{id}'
path.replace('{id}', id)
path.replace('{id}', id)

return self.client.call('delete', path, {
}, params)
Expand All @@ -40,8 +38,8 @@ def oauth_callback(self, project_id, provider, code, state=''):

params = {}
path = '/auth/oauth/callback/{provider}/{projectId}'
path.replace('{projectId}', project_id)
path.replace('{provider}', provider)
path.replace('{projectId}', project_id)
path.replace('{provider}', provider)
params['code'] = code
params['state'] = state

Expand All @@ -53,7 +51,7 @@ def oauth(self, provider, success='', failure=''):

params = {}
path = '/auth/oauth/{provider}'
path.replace('{provider}', provider)
path.replace('{provider}', provider)
params['success'] = success
params['failure'] = failure

Expand Down
8 changes: 3 additions & 5 deletions appwrite/services/avatars.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from ..service import Service


class Avatars(Service):

def get_browser(self, code, width=100, height=100, quality=100):
"""Get Browser Icon"""

params = {}
path = '/avatars/browsers/{code}'
path.replace('{code}', code)
path.replace('{code}', code)
params['width'] = width
params['height'] = height
params['quality'] = quality
Expand All @@ -21,7 +19,7 @@ def get_credit_card(self, code, width=100, height=100, quality=100):

params = {}
path = '/avatars/credit-cards/{code}'
path.replace('{code}', code)
path.replace('{code}', code)
params['width'] = width
params['height'] = height
params['quality'] = quality
Expand All @@ -44,7 +42,7 @@ def get_flag(self, code, width=100, height=100, quality=100):

params = {}
path = '/avatars/flags/{code}'
path.replace('{code}', code)
path.replace('{code}', code)
params['width'] = width
params['height'] = height
params['quality'] = quality
Expand Down
Loading