In this tutorial we are going to create a demo python funciton in a step-by-step manner and deploy it on the DeepMux platform.
What are deepmux functions
DeepMux functions are serverless functions that allow you to write complex data processing algorithms without caring about setting up complex infrastructure.
Making sure deepmux-cli is installed
Check out the Installation guide for detailed instructions.
Setting up the project
We recommend creating your project in a separate directory. For example:
mkdir -p myproject cd myproject
List function environments and choose the appropriate.
Environments are used to define language you are going to use to code the function and provide some pre-installed libraries.
We are going to use
Then initialize the project with the following command:
This will create
.deepmuxignore files in your current directory.
name: <required, function name> env: <required, function env> python: call: <required, module:function to call> requirements: <optional, path to requirements.txt>
name field with
python3.7. You can use
deepmux env command to list all available environments.
It is a standard ignore file and should contain ignore patterns.
We are going to fill in
requirements sections later.
Now it's time to implement the function itself.
In this example we will implement a functions that simply reverses it's input.
main.py file in the project directory and fill it with the following code:
def reverse_function(data): return data[::-1]
Functions written in Python accept
Let's save this function to a file
main.py and add it as an entrypoint.
You need to open
deepmux.yaml and add
main:reverse_function to the
At this point
deepmux.yaml would look like:
name: myproject env: python3.7 python: call: main:reverse_function requirements: <optional, path to requirements.txt>
And the project structure should look like:
myproject/ myproject/deepmux.yaml myproject/main.py
Add requirements (Optional)
If you don't have any requirements just delete the last line from
deepmux.yamlfile and skip this section.
You can add requirements for your function. Let's say we need
numpy package in our function.
And add path to the file in your
name: myproject env: python3.7 python: call: main:reverse_function requirements: requirements.txt
Uploading the function
Once we've finished with the function, requirements and
deepmux.yaml we are able to upload function to the platform via cli.
Function will take some time to process. You can use
command to get your functions and their statuses or simply check your functions via the Web UI.
Running the function
Once your function has finished processing and is in
READY state you can call it with an HTTP request.
Here's an example using curl:
curl -X POST \ -H "X-Token: <YOUR API TOKEN>" \ https://api.deepmux.com/v1/function/myproject/run \ --data "Hello!"
You should see the following on the screen:
You also could run your function via cli:
deepmux run --name myproject --data 'hello!' !olleh
Done! Now you are ready to implement more complex functions and enjoy deploying them on the DeepMux platform.