Create and deploy a serverless function in Python
With the Flex.io API, you can quickly build a serverless cloud-based function that executes server-side Python code.
This template provides a basic example of how to create a serverless function using Python. Replace the sample snippet with your Python code and Flex.io executes it in a container when you run the pipe.
When you use a
python() task in a pipe, Flex.io executes the Python code you specify in a container. Input is passed to the task via standard in and the results are passed back to the pipe via standard out.
In the SDK, this command is a wrapper for the
execute task in the Flex.io API. When
python() is called, an
execute task is added to the pipe that includes a base64-encoded version of the code to be executed, as well as an identifier that indicates the code to be executed is Python.
For example, in this template, when the pipe runs,
flexio_handler(context) is called, executing
context.output.write('Hello World!'), which writes ‘Hello World!’ to the output. The results are returned to the caller, and echoed to the user interface in a callback function.
You can create your own serverless function simply by setting up and saving a pipe with a
python() task. You can pass any number of parameters to a serverless function, or create it using code on GitHub.
To create an API endpoint that invokes a serverless function, save the pipe with an alias:
Best practices for aliases are to use your username as a prefix (e.g.
Later on, you can run pipe in the following manner:
Execute a serverless function with parameters sent via the API.
Chain together functions to build up processing logic with reusable code building blocks.
Load and run code directly from GitHub.