Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

weatherkit-python

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weatherkit-python

A Python interface for Apple's WeatherKit APIs

  • 1.0.1
  • PyPI
  • Socket score

Maintainers
1

weatherkit-python

A Python wrapper for Apple's WeatherKit API

Installation

You can install the WeatherKit library from PyPI:

$ pip install weatherkit-python

The library is supported on Python 3.6 and above.

Dependencies

The following dependencies are installed with the library:

  • Arrow
  • Cryptography
  • PyJWT
  • Requests

JSON Web Token Generation

The library will take care of JWT generation for you since it's such a pain. The expiration time for the token is one hour after generation.

You will need to provide your Developer Team ID, Service ID, Key ID, and Private Key to the library. This is by far the most challenging part, but these sites had instructions that were very helpful:

Dates and Timezones

The library will convert all datetime values to the timezone of your choosing. You can specify UTC to return GMT datetimes. All values are returned in ISO8106 format.

Unit Conversion

The Apple WeatherKit APIs only return values in metric units, but the library also adds imperial properties for all values. All temperatures have both Fahrenheit and Celsius properties. See the API docs for all available object properties.

Conditions

The Apple APIs return conditionCode values that are automatically mapped to human-readable conditions strings. The available conditions are:

CodeCondition
ClearClear
CloudyCloudy
DustDust
FogFog
HazeHaze
MostlyClearMostly Clear
MostlyCloudyMostly Cloudy
PartlyCloudyPartly Cloudy
ScatteredThunderstormsScattered Thunderstorms
SmokeSmoke
BreezyBreezy
WindyWindy
DrizzleDrizzle
HeavyRainHeavy Rain
RainRain
ShowersShowers
FlurriesFlurries
HeavySnowHeavy Snow
MixedRainAndSleetMixed Rain and Sleet
MixedRainAndSnowMixed Rain and Snow
MixedRainfallMixed Rainfall
MixedSnowAndSleetMixed Snow and Sleet
ScatteredShowersScattered Showers
ScatteredSnowShowersScattered Snow Showers
SleetSleet
SnowSnow
SnowShowersSnow Showers
BlizzardBlizzard
BlowingSnowBlowing Snow
FreezingDrizzleFreezing Drizzle
FreezingRainFreezing Rain
FrigidFrigid
HailHail
HotHot
HurricaneHurricane
IsolatedThunderstormsIsolated Thunderstorms
SevereThunderstormSevere Thunderstorm
ThunderstormThunderstorm
TornadoTornado
TropicalStormTropical Storm

Precipitation Types

The DailyForecast, NextHourForecast, and HourlyForecast objects have a precip_type string that can have the following values:

typedescription
hailA form of precipitation consisting of solid ice]
mixedMixed precipitation
rainRain
sleetA form of precipitation consisting of ice pellets
snowSnow
noneNo precipitation

How to Use

import os
import json
import weatherkit

# Load the credentials from wherever you store them securely
team_id = os.environ.get('APPLE_TEAM_ID')
key_id = os.environ.get('APPLE_KEY_ID')
service_id = os.environ.get('APPLE_SERVICE_ID')
private_key = os.environ.get('APPLE_PRIVATE_KEY')

# Instantiate the WeatherKit object
wk_client = weatherkit.WeatherKit(team_id, service_id, private_key, key_id)

# Include any/all of the datasets we want to pull in the list
datasets = [
    'forecastHourly',
    'forecastDaily',
    'currentWeather',
    'forecastNextHour',
]

# Fetch the API
forecasts = wk_client.fetch(datasets, 39.5900, -104.726763, 'US', 'US/Mountain')

# There is a convenience method for converting the forecast response object to JSON
forecasts_json = forecasts.as_json()

Running the tests

From the /weatherkit directory:

$ python -m unittest tests/tests.py

Contributions

Pull requests are welcome so long as they do not add unnecessary complexity to the user.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc