Package: weatherkit-python
weatherkit-pythonA Python wrapper for Apple's WeatherKit APIInstallationYou can install the WeatherKit library from PyPI:$ pip install weatherkit-pythonThe library is supported on Python 3.6 and above.DependenciesThe following dependencies are installed with the library:ArrowCryptographyPyJWTRequestsJSON Web Token GenerationThe 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:https://dev.iachieved.it/iachievedit/weatherkit-rest-api/https://allthecode.co/blog/post/setting-up-weatherkit-rest-api-in-node-jshttps://gist.github.com/pizzapanther/8a29b5462c786f0bb94a257ea535cc0fDates and TimezonesThe library will convert all datetime values to the timezone of your choosing. You can specifyUTCto return GMT datetimes. All values are returned in ISO8106 format.Unit ConversionThe 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.ConditionsThe Apple APIs returnconditionCodevalues that are automatically mapped to human-readable conditions strings. The available conditions are:CodeConditionClearClearCloudyCloudyDustDustFogFogHazeHazeMostlyClearMostly ClearMostlyCloudyMostly CloudyPartlyCloudyPartly CloudyScatteredThunderstormsScattered ThunderstormsSmokeSmokeBreezyBreezyWindyWindyDrizzleDrizzleHeavyRainHeavy RainRainRainShowersShowersFlurriesFlurriesHeavySnowHeavy SnowMixedRainAndSleetMixed Rain and SleetMixedRainAndSnowMixed Rain and SnowMixedRainfallMixed RainfallMixedSnowAndSleetMixed Snow and SleetScatteredShowersScattered ShowersScatteredSnowShowersScattered Snow ShowersSleetSleetSnowSnowSnowShowersSnow ShowersBlizzardBlizzardBlowingSnowBlowing SnowFreezingDrizzleFreezing DrizzleFreezingRainFreezing RainFrigidFrigidHailHailHotHotHurricaneHurricaneIsolatedThunderstormsIsolated ThunderstormsSevereThunderstormSevere ThunderstormThunderstormThunderstormTornadoTornadoTropicalStormTropical StormPrecipitation TypesTheDailyForecast,NextHourForecast, andHourlyForecastobjects have aprecip_typestring that can have the following values:typedescriptionhailA form of precipitation consisting of solid ice]mixedMixed precipitationrainRainsleetA form of precipitation consisting of ice pelletssnowSnownoneNo precipitationHow to Useimport 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 testsFrom the/weatherkitdirectory:$ python -m unittest tests/tests.pyContributionsPull requests are welcome so long as they do not add unnecessary complexity to the user.