Skip to main content

A Python wrapper for the WeatherKit API

Project description

PyWeatherKit

A simple Python wrapper for Apple's WeatherKit REST API.

You need an Apple developer account to use this library and you should first follow the setup instructions in their documentation.

It has a simple interface for retrieving a raw dictionary of weather data from the API, and a method for retrieving simplified daily forecasts as Pythonic objects. Pull requests are welcome!

Install

pip install pyweatherkit

Simple Forecast Usage

from weatherkit.client import WKClient 
client = WKClient("YOUR TEAM ID", "YOUR SERVICE ID", "YOUR KEY ID", "PATH TO YOUR PRIVATE KEY FILE")
forecast = client.get_simple_forecast(latitude, longitude)
for day in forecast:
    print(f"{day.day_of_week}: {day.daytime_icon} with a high of {round(day.temperature_high)} and a low of {round(day.temperature_low)}")

Assuming you input all of the correct client authentication parameters and a valid latitude and longitude, this should result in something like:

Thursday: 🌤️ with a high of 38 and a low of 23
Friday: 🌧️ with a high of 45 and a low of 22
Saturday: 🌧️ with a high of 67 and a low of 40
...

Pulling Full Data Sets

from weatherkit.client import WKClient 
client = WKClient("YOUR TEAM ID", "YOUR SERVICE ID", "YOUR KEY ID", "PATH TO YOUR PRIVATE KEY FILE")
res = client.get_weather(44.50572, -73.24026)

You can also specify the language of the response, the timezone, and the specific datasets you need.

Historical Data Pull

Only available from dates after 08/01/2021 (as of 2023-03-23)

from weatherkit.client import WKClient
from datetime import datetime

# Set dates 
dailyStart = datetime.strptime("2022-11-29", "%Y-%m-%d")
dailyEnd = datetime.strptime("2022-11-30", "%Y-%m-%d")
currentAsOf = datetime.strptime("2022-11-29", "%Y-%m-%d")

client = WKClient("YOUR TEAM ID", "YOUR SERVICE ID", "YOUR KEY ID", "PATH TO YOUR PRIVATE KEY FILE")
res = client.get_weather(44.50572, -73.24026, dailyStart=dailyStart, dailyEnd=dailyEnd, currentAsOf=currentAsOf)

Test/Example Program

Try running simple_test.py from the same directory as this package.

python3 simple_test.py your_team_id your_service_id your_key_id your_key_path your_latitude your_longitude

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyWeatherKit-0.0.4.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyweatherkit-0.0.4-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file PyWeatherKit-0.0.4.tar.gz.

File metadata

  • Download URL: PyWeatherKit-0.0.4.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for PyWeatherKit-0.0.4.tar.gz
Algorithm Hash digest
SHA256 86810e30df68084a85fc262c60290c2b16a89fcccc98de985228659b84ea6dc9
MD5 134ea9232a8b2341495d1c4b9c380c10
BLAKE2b-256 0e58a30e1fab3ac45f8ee01dafecb4f9ba649900a7e0933b17006cf43635d65f

See more details on using hashes here.

File details

Details for the file pyweatherkit-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyweatherkit-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.2

File hashes

Hashes for pyweatherkit-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 71d07f0bdc72946c82ab00c988aedfc8729d2c30b0a43bdf3e6a7a7f66386ac7
MD5 c25a10710b04cb2129e1f076a31c2aed
BLAKE2b-256 0a213d83b18836193ed7d515beef6f14d9b2c946cd80b09b9e452f4f77b64a2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page