This Python class allows you to make calls to OpenWeather’s One Call API.

Access to the API is controlled by key. You will need to register for developer access in order to obtain your key.


This class does not parse the incoming data, which is highly complex. It is up to your application to extract the data you require.

Method Chaining

Most methods return a reference to the driver instance (self) to allow method chaining with dot syntax:

  .request_forecast(secrets["lat"], secrets["lng"])

Source Code

You can find the source code on GitHub.

Class Constructor

class OpenWeather(request_object, key, do_debug=False)

To instantiate an OpenWeather object, pass in a Requests module and your OpenWeather API key.

By default, the library will requests forecast data in metric units and in the English language. Use the methods set_units() and set_language() to change this behaviour.

  • request_object (Requests object) – A Requests object.

  • key (String) – Your OpenWeather API key.

  • do_debug (Boolean) – Emit additional debug messages. Default: False.


# CircuitPython
import adafruit_requests as requests

open_weather = OpenWeather(requests, secrets["apikey"], True)
# MicroPython
import urequests as requests

open_weather = OpenWeather(requests, secrets["apikey"], True)

Class Methods

OpenWeather.request_forecast(latitude, longitude)

This method is called to get the current weather forecast at the specified location.

The dictionary returned by the method contains one of two keys: data if the request was successful, in which case it will contain the forecast returned by the API, or err if the request failed. The value of err is a error message string.

  • latitude (Float) – The target location’s latitude co-ordinate.

  • longitude (Float) – The target location’s longitude co-ordinate.


Dictionary with keys data or err.


Specify the units of measurement subsequent forecasts will use. Options are standard, metric and imperial. The last two choices are self-explanatory. If you choose standard, which is the default, OpenWeather will return units appropriate to the target location. For example, European locations will use metric measurements, but US locations will use Imperial measurements.


requested_units (String) – The type of unit. Default: standard.


The instance (self).


OpenWeather supports a wide range of languages, and this method sets the preferred language for subsequent forecasts.


language (String) – A language code. Default: en.


The instance (self).


Select data items to be excluded from the forecast. This can be useful if you need to receive only a subset of forecast data, the better to reduce the memory footprint of returned data.

Data sections that you can exclude are: current, minutely, hourly, daily and alerts.


list (Array of strings) – The items to exclude. Default: none.


The instance (self).


# We only want the next hour's forecast,
# so exclude other data sets
open_weather.exclude(["alerts", "minutely", "daily", "current"])