Skip to main content

A basic OpenWeatherMap.org API client.

News on experimental caching:

The version here in the repository is currently ahead of the latest version distributed on PyPy (0.9). It features Caching.

If the cache isn’t explicitly deactivated, the function “get_historic_weather()” stores data fetched from the API in an SQLite database. On subsequent requests, data is fetched directly from the database, if available.

In order to deactivate the cache, use

ow = openweather.OpenWeather(cache=False)

and in order to explicitly set a path for the cache DB file, use

ow = openweather.OpenWeather(cache="path/to/cache.db")

Install

To install the latest release:

pip install openweather

For the latest version from the repository, use:

pip install git+https://github.com/marians/openweather.git

Python module example

import openweather
from datetime import datetime

# create client
ow = openweather.OpenWeather()

# find weather stations near me
stations = ow.find_stations_near(
    7.0,  # longitude
    50.0, # latitude
    100   # kilometer radius
)

# iterate results
for station in stations:
    print station

# get current weather at Cologne/Bonn airport
# (station id = 4885)
print ow.get_weather(4885)

# historic weather
start_date = datetime(2013, 09, 10)
end_date = datetime(2013, 09, 15)

# default: hourly interval
print ow.get_historic_weather(4885, start_date, end_date)

# daily aggregates
print ow.get_historic_weather(4885, start_date, end_date, "day")

Command line client example

Print current weather at station ID 4885:

$ openweather -s 4885

Print historic weather for 2013-10-01 at station ID 4885:

$ openweather -s 4885 -d 20131001

For valid formats of the -d or --date parameter, see daterangestr.

Print historic data in CSV format

$ python openweather.py -s 4885 -d 20131022 --csv

This is particularly usefull if you want to store that data to a file…

$ openweather -s 4885 -d 20131022 --csv > weather.csv

… or want to manipulate and display it (using csvkit):

$ openweather -s 4885 -d 20131027 --csv|csvcut -c 9,26,30,35,43|csvlook
|-------------+-------------+------------+------------+---------------|
|  dt         | main_temp_v | pressure_v | wind_deg_v | wind_speed_v  |
|-------------+-------------+------------+------------+---------------|
|  1382824800 | 287.15      | 1005       |            | 4.1           |
|  1382835600 | 290.4       | 1008.25    | 170        | 5.93          |
|  1382839200 | 289.15      | 1007.5     | 175        | 5.1           |
...
|  1382904000 | 287.15      | 1007       | 210        | 5.9           |
|  1382907600 | 287.15      | 1007       | 200        | 6.2           |
|  1382911200 | 287.15      | 1006       | 177        | 5.1           |
|             |             |            |            |               |
|-------------+-------------+------------+------------+---------------|

Like openweather?

Feel free to tip me!

Metadata

Release files for openweather 0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openweather 0.11
File Size Uploaded
openweather-0.11.tar.gz 4.9 kB Details

Release files / openweather-0.11.tar.gz

Download URL openweather-0.11.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
912cc5cf2c2d0b3e277faff5973ee857b3cbca855770303811fdbff13aa07ef4
BLAKE2b-256 checksum
How to use checksums
6c95deacd729c73d51abdef4083694d551c133614f4dd109ee1cde2987b25361
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.11 This release

1 release file

0.10

1 release file

0.9

1 release file

0.8

1 release file

0.7

2 release files

0.6

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page