Build and learn
August 24, 2023

Adding third-party API data into Viam

Saul N. Jinnear
Consulting Engineer
On this page

Viam’s data platform is super cool and useful for storing data generated by your robot. But, there are times where it could be helpful to store some data from external sources alongside that generated by your robot.

For example, I’ve got a plant monitoring bot that I’ve built and I’ve got loads of data from the sensors surrounding my plant. I do not, however, have weather data to go with it. I know I can get weather data from weatherapi.com. But how can I get that store alongside the data from my robot?

Stick with me kid! We’ll get this thing going in no time!!!

Adding external data to Viam’s data platform is nice and easy. All we’ve got to do is wrap the API calls we want to make in a simple modular sensor component.

The process

I started out by making a very small python script that simply queries weatherapi.com for the current weather.

With the logic refined and functioning, I set out to create a modular sensor. How could I do this with as little effort as possible? I just copied the simple module example from https://github.com/viamrobotics/viam-python-sdk/tree/main/examples/simple_module. Then I modified the class name and model to make this a sensor of my own.

Then to make this sensor function as an API-querier, I moved the logic from my initial script into the get_readings function. Sweet! Now this component can query that API and return the data via get_readings().

The data service can now be configured to query this endpoint at whatever cadence I see fit. Almost too easy!

I wanted to commit this to the repo where others could find and use it, so I moved the api_key from being hardcoded (as it was in my original script) into an attribute for the component. I did similar work to move the other query params (in this case “zipcode”) out to a config attribute as well.

What an exciting adventure we’ve just gone on together!!

Final code

twitter iconfacebook iconlinkedin iconreddit icon

Find us at our next event

May 14, 2025
,

AuthCon

In Person
New York
Don't let your toaster order unauthorized parts! The adoption of devices that monitor and automate our world continues to grow at a rapid pace, including mobile robots, smart appliances, cameras & sensors at the edge.
Register now
May 15, 2025
,
6:30-9:00PM

Fireside Chat & Networking Reception

In Person
New York
​Join us for an intimate evening with Viam and Joyful Health. Hear directly from Viam Founder and CEO, Eliot Horowitz, on his entrepreneurial journey, gain valuable insights into the future of technology and AI, network with industry professionals, and meet hiring managers at Viam and Joyful Health.
Join us
Jun 4, 2025
,
5:00PM-8:00PM

NY Robotics - ROS Meetup w/ OSRA and Viam

In Person
New York
Stop by the Viam office during NY tech week to learn how Viam complements ROS with cloud-ready architectures with senior developer advocate, Nick Hehr.
Check it out
Jun 12, 2025
Jun 16, 2025
,

JS Nation

In Person
Amsterdam
WebRTC is most often associated with building video and text chat into browsers but this peer-to-peer technology can also be used to monitor and control machines from anywhere in the world! Join Nick Hehr to learn about industrial arms, DIY rovers, and dashboards of data in real time.
Register Now
Jun 23, 2025
Jun 25, 2025
,

Open Source Summit North America 2025

In Person
Denver, CO
Edge-based computer vision gives us real-time insights, but getting that data where it needs to go without high bandwidth, lag, or hardware strain is a big challenge. Learn how to build a fast, event-driven vision pipeline.
Learn More