In this tutorial you’ll learn how to create a new Gridarrow App using the Python editor in our web console.
As a data source for the App we’ll use a simple API that simulates a network of Internet of Things sensors. There’s a feed of temperature, humidity, radiation and brightness for 10 appliances updated every 5 seconds, accessible via HTTP. We’ll convert that data to an automatically-updated table in Excel with the metrics as columns, and the names of the sensors as rows.
This tutorial assumes that you are already familiar with Python. There are many excellent resources online if you aren’t, Udacity’s course is particularly highly recommended, as is the Codeacademy course.
Open the Gridarrow console, log in and click the
+ icon in the lower right corner.
On the New App screen, specify a name, display name and description for the app.
Since we’re building an IoT App, we’ll give it the name
Sensor Data and the
This data feed provides information from a network of artificial sensors.
Once the App is created you’ll see the editor screen. Right now it contains the minimum Python code required for the App to start up and to stream the current timestamp into a single Excel cell every 10 seconds.
Let’s turn it into a proper App which will download data from our demo API and stream it into an Excel table.
A typical Gridarrow App will consist of 3 sections:
In our example we’d like to download fresh data from our Internet of Things sensors API every 5 seconds and send it to Excel.
Let’s go step-by-step through the code explaining how to do it.
We need to import the
Arrow class from the Gridarrow library. This class is the main integration point between
the application code and the Gridarrow infrastructure. It’s full API and capabilities are described in the
We also import the
requests library to be able to easily download HTTP data and
os library to be able to
read environment variables.
LIVE_DATAURL from which we’ll download the sensors data. The
keyparam is used for authentication to our data endpoint. We’ll set its value using
You can read more about configuring your Apps and handling sensitive data in the
handling sensitive data section
@arrow.initializeto create a grid with the name
live. This is what will appear in the list of grids in the Excel Add-In.
["humidity", "temp", "radiation", "brightness"]
As we shall see in the next section, the return value of the
function is passed as the argument to the
@arrow.on-timerdecorator to make the
on_timer()function execute periodically.
gridargument is the same grid that was created in the initialize function.
requests.get()function from the Requests library
dictfor easier processing.
Our data is now ready to be sent to Excel, so we enumerate through our data dict and update the
grid using the
square brackets  operator. As you can see from the API docs
there’s a wide range of possibilities for updating the data in a grid, but the simplest way to understand this operation is
grid[row_reference, column_reference] = value
Multiple rows and columns can be set at the same time, as long as the
value being passed matches the dimensions implied
by the row and column references.
In our example we’re using an integer row reference
i and the property
grid.columns as the
column reference. The list comprehension
[sensor['data'][c] for c in grid.columns] converts the
sensor dict into a
in the same order as
Here’s an example of how the expression might look as it’s evaluated:
grid[3, ["humidity", "temp", "radiation", "brightness"]] = [68.564, 28.9, 99.39, 199.05]
The complete source code of your App should now look like this:
Because we use the Python
Requests library to
download the data in our App, we need to make it available to the Python interpreter running on the Gridarrow server.
requests to your app dependencies, switch the editor to the
requirements.txt file by clicking on the file
menu and make sure its content looks like:
Full specification of the
requirements.txtfile is available in pip user guide.
Credentials for connecting to APIs or databases should never be stored in the source code. Gridarrow includes a
Secrets mechanism where sensitive data can be added to the system securely. The data is persisted in encrypted
storage and made available to the App as it is run in the form of environment variables.
To make the
API_KEY environment variable available to our App, go to
Secrets tab, click the
+ icon in the
lower right, and add the key
API_KEY with the value:
Save button to save the secret.
Remember that secrets are not available inside the App until you restart it.
Save and restart to start the App. In few seconds it should be up and available in your Excel spreadsheet.
You can connect to it and add the data grid to a new spredsheet by clicking on
add to new spreadsheet button.
After adding a little bit of conditional formatting and a few charts, you might end up with something like this: