Back

[SOLVED] Python context object

  • 0
  • Functions
Bas
2 Nov, 2023, 08:16

Good day 👋

I am making a Python-based Appwrite function and I see that generally, this is done by accepting a file structured like this:

def main(context): return context.res.send("Hello World")

I was wondering if there is any information on what type/structure this "context" object has? Can it perhaps be imported from an SDK of be defined somewhere? I would love to know this for creating tests.

TL;DR
The user was looking for information on the Python context object used in Appwrite functions. They asked if there is any information on the type or structure of the context object, as they wanted to create tests. Another user provided a link to the GitHub repository where the Context object is defined. The issue of adding type support for the Python SDK was mentioned and a link to the related issue and pull request was shared. The user thanked for the response and stated that they had already seen the link but wanted more information on the context object. No solution was provided in the thread.
Bas
2 Nov, 2023, 14:41

@ideclon thanks for the response. I already saw this page and guess I should have formulated the question differently.

Is there some Python definition of the context object? I.e. such that I can make a script like this:

TypeScript

def main(context: RuntimeContext):
    return context.res.send("")```

In other words; this context object must have some class or data structure which is not specified in the documentation. This is relevant because I might want to write unittests that send such a context object, preferably without mocking an implementation and rather using the actual thing.
Guille
2 Nov, 2023, 14:48

Python SDK doesn't have types, but there is a open issue an PR to implement it: https://github.com/appwrite/sdk-for-python/issues/43

Guille
2 Nov, 2023, 14:51

Looking the PR seems like it doesn't include types for the context, you can comment the issue giving your feedback

Drake
2 Nov, 2023, 16:46

We've been wanting to add better type support for open runtimes...not sure when we'll be able t oget to it

Bas
3 Nov, 2023, 15:10

Alright, thanks for the info!

Bas
4 Nov, 2023, 12:05

Just for future reference, I found the Context object definition here https://github.com/open-runtimes/open-runtimes/blob/main/runtimes/python-3.10/src/server.py#L47-L70

This is what I was looking for 😀 thx again for the pointers

Guille
7 Nov, 2023, 19:44

[SOLVED] Python context object

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