mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
30 lines
1.0 KiB
Plaintext
30 lines
1.0 KiB
Plaintext
// Module included in the following assemblies
|
|
//
|
|
// * serverless/functions/serverless-developing-python-functions.adoc
|
|
|
|
:_mod-docs-content-type: CONCEPT
|
|
[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
|
|
----
|