Welcome to Flex.io!
Flex.io provides a GUI housing for stitching together serverless functions with out-of-the-box helper tasks that take the pain out of OAuth, notifications, scheduling, local storage, library dependencies and other ‘glue’ code.
These serverless functions and tasks are defined using Flex.io pipes. Once defined, pipes can be scheduled or triggered to run with an API request, webhook or by sending an email.
In this getting started guide, we’ll show you how to build and run your first pipe. Then we’ll point you to additional resources to help you create your own custom serverless pipes.
To begin, you may sign up for an account here.
Enter your name and choose a username between 3 and 80 characters long. The username is your namespace for your pipe and connection paths, when you call them remotely.
Then, enter your email address and choose a password with at least eight characters and one number. Then, click the Sign Up button.
Thereafter, you may sign in to Flex.io here.
Got more questions? Check out our FAQ for some quick answers. And, feel free to message us from the icon in the lower-right of this page; we’re happy to help.
Ok, let’s get started!
To get you started, we’ll create a simple pipe that gets enables you access Gmail via OAuth, apply Python functions to Gmail and then receive an email notification with the results.
Because of Flex.io’s built in Tasks, it’ll only take a couple minutes for you to create and deploy. Specifically, you’ll do the following:
- Get an OAuth token from Gmail
- Add a Python function to read messages from Gmail
- Update the function to read message content
- Add a second Python function that uses pandas to format the results
- Create an email notification with the table
- Deploy the pipe with the built-in scheduler
To begin, first sign in to your Flex.io account and navigate to the Pipes page, which lists all of your pipes.
Select the “New Pipe” button from the upper right to access the Pipe Builder.
For this tutorial, you’ll start with a blank slate. So, first delete the “hello world” Execute Task by hovering over the Task and clicking the delete icon at the right.
You should now see an empty pipe and an option to choose a task. Now let’s start building!
To work with Gmail’s API, you’ll need code to generate a Gmail OAuth token. To do this, click on the OAuth Task.
If you have already created a connection to Gmail, you can simply click on it from your list of existing connections. Otherwise, click on the the “Set up a New Connection” button to pop up a dialog with OAuth connection types. Select the “Gmail” icon and you’ll get a configuration panel.
Click the “‘Authenticate your Gmail Account’ button and then follow the Gmail prompts to authenticate. Once authenticated, click the “Create Connection” button, which will take you back to the OAuth dialog.
We’ll be using Python for this example, so make sure it is selected. Finally, click “Save Changes” and the OAuth dialog will create an Execute task for you to get the Gmail OAuth token, which will look something like this:
Here is what’s happening with this code:
connection_identifier = 'my-gmail'
To test your code, click the “TEST” button at the top right of the Pipe Builder to run your pipe. After running, you’ll see your OAuth refresh token in your output.
With the OAuth token, you now have the ability to talk to Gmail. Next we’ll create a function that gets a basic list of the last 10 messages from your account. To do this we’ll modify the existing OAuth code in two steps.
- In your Execute task, select everything above the line
def flex_handler(flex):and then add the following snippet. This loads the Python modules needed to run this example.
- Then, select everything after the line
auth_token = flex.connections[connection_identifier].get_access_token()
and replace it with the following, which gets a basic list of messages from Gmail using your OAuth token
Your script should now look like this:
After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll receive a list from Gmail with the ten most recent messages, which will look something like this:
Now that you have your basic message IDs, update the function to show the content related to those messages. To do this, modify the same Execute Task as follows:
- In your Execute task, select everything after the line
message_list_page = message_list_url
and replace it with the following, which will get the messages fields and populate them with the email information:
After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll receive your email information in JSON format, which will look something like this:
Now that you have message data from Gmail, it’s time to format it. This will be a distinct process using the pandas library for Python, but Flex.io makes it easy to chain together logic by passing an output of any given task to the input of the following task.
Do the following to add a reformatting function:
Add another Task by clicking the “+” icon below your existing Execute task. Then, select another Execute Task.
Delete “hello world” sample code and replace it with the following snippet, which converts the email results from JSON and displays it as a text-based table.
After you’ve copied in your code, save your changes and then click the ‘TEST’ button again to re-run the pipe. After a couple seconds, you’ll see a reformatted list of your Gmail headers by date that looks like this:
With your correctly formatted data in hand, you’ll now finish off the pipe by adding an email notification, which will take the output from the previous execute step and pass it into the body of the email.
Do the following:
- Add another Task by clicking the “+” icon below your second Execute task. Then, select the Email Task.
Fill in the dialog with your name and email address. In the message area, add the following snippet:
Here are your most recent message by day:
You should now have an Email task that looks something like this:
After you’ve saved your changes, click the ‘TEST’ button again to re-run the pipe. After a couple seconds, check your inbox for the email notification.
Congratulations, you’ve defined your first serverless pipe!
Now, you can deploy this pipe into production. Flex.io gives you multiple options for Deployment. However, to finish up this guide, we’ll simply schedule it as follows:
First, turn on your pipe to activate it.
In your pipe, scroll down to the bottom Deployment section and check the box next to Run on a schedule.
Finally, click on “Edit” and set up the schedule you would like to use. By default, this pipe is scheduled to run every day at 8AM UTC. Update this by clicking on the “EDIT” button to configure the Scheduler and set it to run every five minutes. Click Save Changes and your schedule will update in the Pipe Builder.
Now that your pipe is on and scheduled, you’ll start seeing emails to your inbox every five minutes. Once you’ve seen how it works, simply go back to the pipe and turn it OFF.
Congratulations, you’ve created, run and deployed your first pipe!
While simplistic, this pipe demonstrates the end-to-end nature of a pipe and how Flex.io not only runs your functions in sequence, but also provides building blocks out-of-the-box, like OAuth refresh tokens, notifications and scheduling.
Now that you have the basics, you can dive into the additional resources below to build your own custom pipes. Should you have any questions at all, don’t hesitate to ask, we’re very happy to help!
To take a deeper dive into the core concepts of Flex.io data feeds, you can take a look at the following guides:
Flex.io API reference docs can be found here:
In addition to the reference material above, you can also take a look at some real-world use cases. Tutorials will provide step-by-step details on how to build various serverless pipes. Examples provide a variety of common starter functions that you can copy and paste into your Execute Tasks.