Skip to content
Back

Tips for Debugging Appwrite Functions Locally

  • 0
  • 2
  • Functions
cccabdalla
7 Jan, 2026, 20:12

Hi everyone! 👋

I have an Appwrite Function running locally with Docker, but I’m struggling to debug it because execution doesn’t reach the breakpoints I set. I’d really appreciate any guidance on:

  1. How to debug Appwrite Functions locally
  2. Inspecting variables or stepping through code while running in Docker

Thanks so much in advance for any tips or best practices!

TL;DR
Creating a mock context by defining classes for request and response objects, then executing the function's main file with the desired arguments can help debug an Appwrite function locally using VSCode breakpoints. Example code provided in the thread.
8 Jan, 2026, 02:10

Personally the way I've been doing it is creating a mock context and simply executing the function's main file with the arguments you want. So for a Python function you have the main() function and it accepts context as an argument. Create a test file that calls the main file simulating the context object. Something like this:

TypeScript


class MockRequest:
    def __init__(
        self,
        body_raw,
        body,
        headers,
        scheme,
        method,
        url,
        host,
        port,
        path,
        query_string,
        query,
    ):
        self.body_raw = body_raw
        self.body = body
        self.headers = headers
        self.scheme = scheme
        self.method = method
        self.url = url
        self.host = host
        self.port = port
        self.path = path
        self.query_string = query_string
        self.query = query


class MockResponse:
    def __init__(self):
        self.response = None

    def send(self, response):
        self.response = response
        print(f"Response: {response}")

    def json(self, response):
        self.response = response
        return response

    def empty(self):
        return None


class MockContext:
    def __init__(self, req: MockRequest):
        self.req = req
        self.res = MockResponse()

    def log(self, message):
        print(message)

    def error(self, message):
        print(f"ERROR: {message}")
8 Jan, 2026, 17:46

I am already able to send request to my function but the execution doesn't come to the place where the break point is put. Thus, unable to know the state of a given variable. The only option currently available is to log it but logging it every place is tiresome and boring.

8 Jan, 2026, 23:18

Well what I'm doing here is executing this through VSCode with breakpoints. I create a file that calls my appwrite functions main function by importing it:

TypeScript
from main import main # Your appwrite function entrypoint

def test():
  req = MockRequest(
        body_raw,
        normalized_body,
        headers,
        scheme,
        method_value,
        url,
        host,
        port,
        path_value,
        query_string,
        query,
    )
  context = MockContext(req)
  main(context)

if __name__ == "__main__":  # pragma: no cover
    test()
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