From 27093c57cc3059263386a987db5907c4b900bceb Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:09:24 +0100 Subject: [PATCH 1/8] feat: Python starter template --- python/starter-template/.gitignore | 160 +++++++++++++++++++++++ python/starter-template/README.md | 42 ++++++ python/starter-template/requirements.txt | 1 + python/starter-template/src/main.py | 34 +++++ 4 files changed, 237 insertions(+) create mode 100644 python/starter-template/.gitignore create mode 100644 python/starter-template/README.md create mode 100644 python/starter-template/requirements.txt create mode 100644 python/starter-template/src/main.py diff --git a/python/starter-template/.gitignore b/python/starter-template/.gitignore new file mode 100644 index 00000000..6769e21d --- /dev/null +++ b/python/starter-template/.gitignore @@ -0,0 +1,160 @@ +# 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/ +share/python-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/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ +cover/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +.pybuilder/ +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# 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/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +#.idea/ \ No newline at end of file diff --git a/python/starter-template/README.md b/python/starter-template/README.md new file mode 100644 index 00000000..067d8053 --- /dev/null +++ b/python/starter-template/README.md @@ -0,0 +1,42 @@ +# ⚡ Starter Function + +A simple starter function. Edit `src/main.js` to get started and create something awesome! 🚀 + +## 🧰 Usage + +### `GET` + +- Returns a "Hello, World!" message. + +**Response** + +Sample `200` Response: + +```text +Hello, World! 🌎 +``` + +### `POST`, `PUT`, `PATCH`, `DELETE` + +- Returns a "Learn More" JSON response. + +**Response** + +Sample `200` Response: + +```json +{ + "motto": "Build Fast. Scale Big. All in One Place.", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io" +} +``` + +## ⚙️ Configuration + +| Setting | Value | +|----------------|-----------------------------------| +| Runtime | Python | +| Entrypoint | src/main.py | +| Build Commands | `pip install -r requirements.txt` | \ No newline at end of file diff --git a/python/starter-template/requirements.txt b/python/starter-template/requirements.txt new file mode 100644 index 00000000..7a6977ed --- /dev/null +++ b/python/starter-template/requirements.txt @@ -0,0 +1 @@ +appwrite \ No newline at end of file diff --git a/python/starter-template/src/main.py b/python/starter-template/src/main.py new file mode 100644 index 00000000..e24b284c --- /dev/null +++ b/python/starter-template/src/main.py @@ -0,0 +1,34 @@ +from appwrite.client import Client + + +# This is your Appwrite function +# It's executed each time we get a request +def main(ctx): + # Why not try the Appwrite SDK? + # + # client = Client() + # .setEndpoint('https:#cloud.appwrite.io/v1') + # .setProject(process.env.APPWRITE_PROJECT_ID) + # .setKey(process.env.APPWRITE_API_KEY); + + # You can log messages to the console + ctx.log("Hello, Logs! 👋") + + # If something goes wrong, log an error + ctx.error("Hello, Errors! ⛔") + + # The `ctx.req` object contains the request data + if ctx.req.method == "GET": + # Send a response with the res object helpers + # `ctx.res.send()` dispatches a string back to the client + return ctx.res.send("Hello, World! 🌎") + + # `ctx.res.json()` is a handy helper for sending JSON + return ctx.res.json( + { + "motto": "Build Fast. Scale Big. All in One Place.", + "learn": "https:#appwrite.io/docs", + "connect": "https:#appwrite.io/discord", + "getInspired": "https:#builtwith.appwrite.io", + } + ) From ff7240f6c4ab22329fbd4146c3ba68436f081eb8 Mon Sep 17 00:00:00 2001 From: "Luke B. Silver" <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 13:10:58 +0100 Subject: [PATCH 2/8] docs: readme --- python/starter-template/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/starter-template/README.md b/python/starter-template/README.md index 067d8053..6c6cd44d 100644 --- a/python/starter-template/README.md +++ b/python/starter-template/README.md @@ -1,6 +1,6 @@ # ⚡ Starter Function -A simple starter function. Edit `src/main.js` to get started and create something awesome! 🚀 +A simple starter function. Edit `src/main.py` to get started and create something awesome! 🚀 ## 🧰 Usage @@ -39,4 +39,4 @@ Sample `200` Response: |----------------|-----------------------------------| | Runtime | Python | | Entrypoint | src/main.py | -| Build Commands | `pip install -r requirements.txt` | \ No newline at end of file +| Build Commands | `pip install -r requirements.txt` | From b1bc6e3a3cd22c50c53de99ae3d162572a3277b8 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:03:38 +0100 Subject: [PATCH 3/8] chore: matej review --- python/starter-template/.gitignore | 2 +- python/starter-template/README.md | 20 ++++++++++++++------ python/starter-template/requirements.txt | 2 +- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/python/starter-template/.gitignore b/python/starter-template/.gitignore index 6769e21d..68bc17f9 100644 --- a/python/starter-template/.gitignore +++ b/python/starter-template/.gitignore @@ -157,4 +157,4 @@ cython_debug/ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ \ No newline at end of file +#.idea/ diff --git a/python/starter-template/README.md b/python/starter-template/README.md index 6c6cd44d..02aa5a00 100644 --- a/python/starter-template/README.md +++ b/python/starter-template/README.md @@ -1,4 +1,4 @@ -# ⚡ Starter Function +# ⚡ Python Starter Function A simple starter function. Edit `src/main.py` to get started and create something awesome! 🚀 @@ -35,8 +35,16 @@ Sample `200` Response: ## ⚙️ Configuration -| Setting | Value | -|----------------|-----------------------------------| -| Runtime | Python | -| Entrypoint | src/main.py | -| Build Commands | `pip install -r requirements.txt` | +| Setting | Value | +|-------------------|-----------------------------------| +| Runtime | Python | +| Entrypoint | src/main.py | +| Build Commands | `pip install -r requirements.txt` | +| Permissions | any | +| Events | users.*.create | +| CRON | 0 * * * * | +| Timeout (Seconds) | 15 | + +## 🔒 Environment Variables + +No environment variables required. diff --git a/python/starter-template/requirements.txt b/python/starter-template/requirements.txt index 7a6977ed..3217f138 100644 --- a/python/starter-template/requirements.txt +++ b/python/starter-template/requirements.txt @@ -1 +1 @@ -appwrite \ No newline at end of file +appwrite From 5a6d7d4be4f3fcaa89952115de78445bdf964ac1 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:07:58 +0100 Subject: [PATCH 4/8] fix: sdk snippet --- python/starter-template/src/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/python/starter-template/src/main.py b/python/starter-template/src/main.py index e24b284c..bf064f25 100644 --- a/python/starter-template/src/main.py +++ b/python/starter-template/src/main.py @@ -1,4 +1,5 @@ from appwrite.client import Client +import os # This is your Appwrite function @@ -7,9 +8,9 @@ def main(ctx): # Why not try the Appwrite SDK? # # client = Client() - # .setEndpoint('https:#cloud.appwrite.io/v1') - # .setProject(process.env.APPWRITE_PROJECT_ID) - # .setKey(process.env.APPWRITE_API_KEY); + # .setEndpoint('https://cloud.appwrite.io/v1') + # .setProject(os.environ['APPWRITE_PROJECT_ID']) + # .setKey(os.environ['APPWRITE_API_KEY']) # You can log messages to the console ctx.log("Hello, Logs! 👋") From 320ad7700fd6711f38bbed2133d1e3d2510c2646 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:18:56 +0100 Subject: [PATCH 5/8] fix: sdk init --- python/starter-template/src/main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python/starter-template/src/main.py b/python/starter-template/src/main.py index bf064f25..33fbfe23 100644 --- a/python/starter-template/src/main.py +++ b/python/starter-template/src/main.py @@ -7,10 +7,12 @@ def main(ctx): # Why not try the Appwrite SDK? # - # client = Client() - # .setEndpoint('https://cloud.appwrite.io/v1') - # .setProject(os.environ['APPWRITE_PROJECT_ID']) - # .setKey(os.environ['APPWRITE_API_KEY']) + # client = ( + # Client() + # .set_endpoint("https://cloud.appwrite.io/v1") + # .set_project(os.environ["APPWRITE_PROJECT_ID"]) + # .set_key(os.environ["APPWRITE_API_KEY"]) + # ) # You can log messages to the console ctx.log("Hello, Logs! 👋") From 3b71555be01e234035dbd5ea8de673805ba54801 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:19:41 +0100 Subject: [PATCH 6/8] fix: urls --- python/starter-template/src/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/starter-template/src/main.py b/python/starter-template/src/main.py index 33fbfe23..7b75092c 100644 --- a/python/starter-template/src/main.py +++ b/python/starter-template/src/main.py @@ -30,8 +30,8 @@ def main(ctx): return ctx.res.json( { "motto": "Build Fast. Scale Big. All in One Place.", - "learn": "https:#appwrite.io/docs", - "connect": "https:#appwrite.io/discord", - "getInspired": "https:#builtwith.appwrite.io", + "learn": "https://appwrite.io/docs", + "connect": "https://appwrite.io/discord", + "getInspired": "https://builtwith.appwrite.io", } ) From dd0f06dc44510ab2b6cd61af267f7e56383bc464 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:26:22 +0100 Subject: [PATCH 7/8] docs: config --- python/starter-template/README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/python/starter-template/README.md b/python/starter-template/README.md index 02aa5a00..5ce8fedb 100644 --- a/python/starter-template/README.md +++ b/python/starter-template/README.md @@ -37,12 +37,10 @@ Sample `200` Response: | Setting | Value | |-------------------|-----------------------------------| -| Runtime | Python | +| Runtime | Python (3.10) | | Entrypoint | src/main.py | | Build Commands | `pip install -r requirements.txt` | | Permissions | any | -| Events | users.*.create | -| CRON | 0 * * * * | | Timeout (Seconds) | 15 | ## 🔒 Environment Variables From 3709ad6edb76933060cc1cd24a8f1c6b9ea50d4b Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 20 Jul 2023 14:44:42 +0100 Subject: [PATCH 8/8] docs: restore `` --- python/starter-template/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/starter-template/README.md b/python/starter-template/README.md index 5ce8fedb..79678e49 100644 --- a/python/starter-template/README.md +++ b/python/starter-template/README.md @@ -38,9 +38,9 @@ Sample `200` Response: | Setting | Value | |-------------------|-----------------------------------| | Runtime | Python (3.10) | -| Entrypoint | src/main.py | +| Entrypoint | `src/main.py` | | Build Commands | `pip install -r requirements.txt` | -| Permissions | any | +| Permissions | `any` | | Timeout (Seconds) | 15 | ## 🔒 Environment Variables