Back

Python appwrite function

  • 0
  • Functions
Mosh Ontong
10 Apr, 2023, 15:17

I am new in appwrite cloud function

This is the boilerplate code when we create new python function

TypeScript
from appwrite.client import Client

# You can remove imports of services you don't use
from appwrite.services.account import Account
from appwrite.services.avatars import Avatars
from appwrite.services.databases import Databases
from appwrite.services.functions import Functions
from appwrite.services.health import Health
from appwrite.services.locale import Locale
from appwrite.services.storage import Storage
from appwrite.services.teams import Teams
from appwrite.services.users import Users



def main(req, res):
  client = Client()

  # You can remove services you don't use
  account = Account(client)
  avatars = Avatars(client)
  database = Databases(client)
  functions = Functions(client)
  health = Health(client)
  locale = Locale(client)
  storage = Storage(client)
  teams = Teams(client)
  users = Users(client)

  if not req.variables.get('APPWRITE_FUNCTION_ENDPOINT') or not req.variables.get('APPWRITE_FUNCTION_API_KEY'):
    print('Environment variables are not set. Function cannot use Appwrite SDK.')
  else:
    (
    client
      .set_endpoint(req.variables.get('APPWRITE_FUNCTION_ENDPOINT', None))
      .set_project(req.variables.get('APPWRITE_FUNCTION_PROJECT_ID', None))
      .set_key(req.variables.get('APPWRITE_FUNCTION_API_KEY', None))
      .set_self_signed(True)
    )
  
  return res.json({
    "areDevelopersAwesome": True,
  })

My question here is that:

  1. Where I can locate the [APPWRITE_FUNCTION_ENDPOINT]?
  2. Do I need to create APPWRITE FUNCTION API KEY environment? and If yes, how can I create api key then?
TL;DR
1. The [APPWRITE_FUNCTION_ENDPOINT] can be located in the environment variables. Make sure it is set correctly. 2. Yes, you need to create the APPWRITE FUNCTION API KEY environment variable. To create an API key, you can follow these steps: - Go to the Appwrite dashboard. - Navigate to the project where you want to create the API key. - Click on the "API Keys" tab. - Click on the "Create Key" button. - Give a name to your API key and choose the relevant permissions. - Click on the "Create" button. - Copy the
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more