Package: ofn-functions-framework
Functions Framework for PythonThis project is inspired byGCP functions-framework-python.An open source FaaS (Function as a service) framework for writing portable Python functions.The Functions Framework lets you write lightweight functions that run in many different environments, including:OpenFunctionKnative-based environmentsDapr-based environmentsYour local development machineThe framework allows you to go from:fromfunctions_framework.context.user_contextimportUserContextdefhello(context:UserContext):return"Hello world!"To:curlhttp://my-url# Output: Hello world!All without needing to worry about writing an HTTP server or complicated request handling logic.FeaturesSpin up a local development server for quick testingInvoke a function in response to a requestPortable between serverless platformsCan integrate various data middlewaresInstallationInstall the Functions Framework viapip:pipinstallofn-functions-frameworkOr, for deployment, add the Functions Framework to yourrequirements.txtfile:ofn-functions-framework==0.2.0QuickstartsQuickstart: HTTP Function (Hello World)Create anmain.pyfile with the following contents:fromfunctions_framework.context.user_contextimportUserContextdefhello(context:UserContext):# context.get_http_request()return"Hello world!"Export Function Context:exportFUNC_CONTEXT='{"name":"function_name","version":"v1","triggers":{"http":{"port":8080}}}'Run the following command:ff--sourcehello_world.py--targethelloOpenhttp://localhost:8080/in your browser and seeHello world!.Or send requests to this function usingcurlfrom another terminal window:curllocalhost:8080# Output: Hello world!Run your function on OpenFunctionBesides Knative function support, one notable feature of OpenFunction is embracing Dapr system, so far Dapr pub/sub and bindings have been support.Dapr bindings allows you to trigger your applications or services with events coming in from external systems, or interface with external systems. OpenFunction0.6.0 releaseadds Dapr output bindings to its synchronous functions which enables HTTP triggers for asynchronous functions. For example, synchronous functions backed by the Knative runtime can now interact with middlewares defined by Dapr output binding or pub/sub, and an asynchronous function will be triggered by the events sent from the synchronous function.Asynchronous function introduces Dapr pub/sub to provide a platform-agnostic API to send and receive messages. A typical use case is that you can leverage synchronous functions to receive an event in plain JSON or Cloud Events format, and then send the received event to a Dapr output binding or pub/sub component, most likely a message queue (e.g. Kafka, NATS Streaming, GCP PubSub, MQTT). Finally, the asynchronous function could be triggered from the message queue.More details would be brought up to you in some quickstart samples, stay tuned.Configure the Functions FrameworkYou can configure the Functions Framework using command-line flags or environment variables. If you specify both, the environment variable will be ignored.Command-line flagEnvironment variableDescription--hostHOSTThe host on which the Functions Framework listens for requests. Default:0.0.0.0--portPORTThe port on which the Functions Framework listens for requests. Default:8080--targetFUNCTION_TARGETThe name of the exported function to be invoked in response to requests. Default:function--sourceFUNCTION_SOURCEThe path to the file containing your function. Default:main.py(in the current working directory)--debugDEBUGA flag that allows to run functions-framework to run in debug mode, including live reloading. Default:False--dry-runDRY_RUNA flag that allows for testing the function build from the configuration without creating a server. Default:FalseAdvanced ExamplesMore advanced guides can be found in theexamples/directory.