2022-02-15 11:19:22 -06:00
// Module included in the following assemblies
//
// * serverless/functions/serverless-developing-python-functions.adoc
2022-02-04 15:22:10 +00:00
:_content-type: CONCEPT
2021-05-04 10:20:30 -05:00
[id="serverless-invoking-python-functions_{context}"]
= About invoking Python functions
2022-06-14 16:59:25 +02:00
Python functions can be invoked with a simple HTTP request. When an incoming request is received, functions are invoked with a `context` object as the first parameter.
The `context` object is a Python class with two attributes:
2021-05-04 10:20:30 -05:00
* The `request` attribute is always present, and contains the Flask `request` object.
2021-07-14 13:55:23 -05:00
* The second attribute, `cloud_event`, is populated if the incoming request is a `CloudEvent` object.
2021-05-04 10:20:30 -05:00
Developers can access any `CloudEvent` data from the context object.
.Example context object
[source,python]
----
def main(context: Context):
"""
The context parameter contains the Flask request object and any
CloudEvent received with the request.
"""
print(f"Method: {context.request.method}")
print(f"Event data {context.cloud_event.data}")
# ... business logic here
----