1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-05 21:46:22 +01:00
Files
openshift-docs/modules/serverless-invoking-python-functions.adoc
2021-07-19 14:50:53 +00:00

23 lines
910 B
Plaintext

[id="serverless-invoking-python-functions_{context}"]
= About invoking Python functions
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:
* The `request` attribute is always present, and contains the Flask `request` object.
* The second attribute, `cloud_event`, is populated if the incoming request is a `CloudEvent` object.
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
----