The Pirate Weather API wrapper
Project description
Pirate Weather Python
This library for the Pirate Weather API which is an alternative to the deprecated DarkSky API, and provides access to detailed weather information from around the globe.
Now supporting Pirate Weather API v2.8+ with new data fields including smoke levels, solar radiation, fire indices, and detailed precipitation breakdowns.
This library was made by updating the darksky library by Detrous so all credits go to them.
Installation
pip3 install pirateweather
Get started
Before you start using this library, you need to get your API key here.
Notes on functionality
The Pirate Weather timemachine data is limited in availability, it is only possible to fetch data about 1-2 months ago. For recent historical weather data use the get_recent_time_machine_forecast which will have data from about 1-5 days prior. Unfortunately, at the time of writing this it is not possible to get data from 2 weeks ago for example.
All classes are fully annotated, source code is your best doc : )
Use of synchronous client:
from pirate_weather.api import PirateWeather
from pirate_weather.types.languages import Languages
from pirate_weather.types.units import Units
from pirate_weather.types.weather import Weather
API_KEY = "0123456789"
pirate_weather = PirateWeather(API_KEY)
latitude = 42.3601
longitude = -71.0589
forecast = pirate_weather.get_forecast(
latitude, longitude,
extend=False, # default `False`
lang=Languages.ENGLISH, # default `ENGLISH`
values_units=Units.AUTO, # default `auto`
exclude=[Weather.MINUTELY, Weather.ALERTS], # default `[]`,
timezone='UTC' # default None - will be set by Pirate Weather API automatically
)
Use of synchronous timemachine client:
from pirate_weather.api import PirateWeather
from pirate_weather.types.languages import Languages
from pirate_weather.types.units import Units
from pirate_weather.types.weather import Weather
from datetime import datetime as dt
API_KEY = "0123456789"
pirate_weather = PirateWeather(API_KEY)
t = dt(2022, 5, 6, 12)
latitude = 42.3601
longitude = -71.0589
forecast = pirate_weather.get_time_machine_forecast(
latitude, longitude,
extend=False, # default `False`
lang=Languages.ENGLISH, # default `ENGLISH`
values_units=Units.AUTO, # default `auto`
exclude=[Weather.MINUTELY, Weather.ALERTS], # default `[]`,
timezone='UTC', # default None - will be set by Pirate Weather API automatically
time=t
)
Use of synchronous client getting recent timemachine data:
from pirate_weather.api import PirateWeather
from pirate_weather.types.languages import Languages
from pirate_weather.types.units import Units
from pirate_weather.types.weather import Weather
from datetime import datetime as dt
API_KEY = "0123456789"
pirate_weather = PirateWeather(API_KEY)
t = dt(2023, 4, 4)
latitude = 42.3601
longitude = -71.0589
forecast = pirate_weather.get_recent_time_machine_forecast(
latitude, longitude,
extend=False, # default `False`
lang=Languages.ENGLISH, # default `ENGLISH`
values_units=Units.AUTO, # default `auto`
exclude=[Weather.MINUTELY, Weather.ALERTS], # default `[]`,
timezone='UTC', # default None - will be set by Pirate Weather API automatically
time=t
)
Use of asynchronous client:
from pirate_weather.api import PirateWeatherAsync
from pirate_weather.types.languages import Languages
from pirate_weather.types.units import Units
from pirate_weather.types.weather import Weather
import asyncio
import aiohttp
async def main(api_key):
async with aiohttp.ClientSession() as session:
pirate_weather = PirateWeatherAsync(api_key)
latitude = 42.3601
longitude = -71.0589
forecast = await pirate_weather.get_forecast(
latitude, longitude,
extend=False, # default `False`
lang=Languages.ENGLISH, # default `ENGLISH`
values_units=Units.AUTO, # default `auto`
exclude=[Weather.MINUTELY, Weather.ALERTS], # default `[]`,
timezone='UTC', # default None - will be set by Pirate Weather API automatically
client_session=session # default aiohttp.ClientSession()
)
api_key = "0123456789"
asyncio.run(main(api_key))
New Features
API v2.8+ Support
This library now supports all Pirate Weather API v2.8+ fields:
New Weather Data Fields:
smoke- Air quality smoke levels (µg/m³)solar- Solar radiation (W/m²)feelsLike- Apparent temperature based on wind and humiditycape- Convective Available Potential EnergyfireIndex- Fire weather indexliquidAccumulation,snowAccumulation,iceAccumulation- Precipitation by typerainIntensity,snowIntensity,iceIntensity- Intensity by precipitation typecurrentDayIce,currentDayLiquid,currentDaySnow- Accumulations for the current daydawnTime,duskTime- Civil twilight times
New Metadata Fields:
sourceTimes- Model update timestampssourceIDX- Grid coordinates for each modelversion- API versionprocessTime- Request processing timeingestVersion- Data ingest versionnearestCity,nearestCountry,nearestSubNational- Location information
Day/Night Forecast Block:
The library now supports the optional day_night forecast block which provides 12-hour forecast periods:
forecast = pirate_weather.get_forecast(latitude, longitude)
# Access day/night forecast data
for period in forecast.day_night.data:
print(f"Time: {period.time}, Temp: {period.temperature}, Smoke: {period.smoke}")
Example accessing new fields:
forecast = pirate_weather.get_forecast(latitude, longitude)
# Current conditions with new fields
print(f"Current smoke level: {forecast.currently.smoke} µg/m³")
print(f"Solar radiation: {forecast.currently.solar} W/m²")
print(f"Feels like: {forecast.currently.feels_like}°")
print(f"Fire index: {forecast.currently.fire_index}")
# Hourly forecasts with precipitation breakdowns
for hour in forecast.hourly.data:
if hour.rain_intensity > 0:
print(f"Rain intensity: {hour.rain_intensity} mm/h")
if hour.snow_intensity > 0:
print(f"Snow intensity: {hour.snow_intensity} cm/h")
# Daily forecasts with new max fields
for day in forecast.daily.data:
print(f"Max smoke: {day.smoke_max} at {day.smoke_max_time}")
print(f"Max solar: {day.solar_max} at {day.solar_max_time}")
print(f"Dawn: {day.dawn_time}, Dusk: {day.dusk_time}")
# Metadata
print(f"API Version: {forecast.flags.version}")
print(f"Nearest City: {forecast.flags.nearest_city}")
print(f"Process Time: {forecast.flags.process_time}ms")
License.
Library is released under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pirateweather-1.0.0.tar.gz.
File metadata
- Download URL: pirateweather-1.0.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2961720c3e76120212f7273b3bc5c6ac71989912626ed0891b616aa326c7b3ac
|
|
| MD5 |
4f32b52e89de895ee3c9881f771d8f2d
|
|
| BLAKE2b-256 |
bb2dd79a1927f2a6de92f99c8da112c27bab2ed8e0ba8fd61ddd3dafc3b07575
|
Provenance
The following attestation bundles were made for pirateweather-1.0.0.tar.gz:
Publisher:
release.yml on Pirate-Weather/pirate-weather-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pirateweather-1.0.0.tar.gz -
Subject digest:
2961720c3e76120212f7273b3bc5c6ac71989912626ed0891b616aa326c7b3ac - Sigstore transparency entry: 751010347
- Sigstore integration time:
-
Permalink:
Pirate-Weather/pirate-weather-python@a1c025d11b610b8f412a93ac4fac64e6a694b0f2 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/Pirate-Weather
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a1c025d11b610b8f412a93ac4fac64e6a694b0f2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pirateweather-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pirateweather-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
07a829bdc175721aac1409c487a7c659d7ffdcc124f8ce78dfdca9557401e448
|
|
| MD5 |
1e75ea2a9ff66b78eb759fccd5932938
|
|
| BLAKE2b-256 |
73d7c30d78e1413c607b050317e29424b5e6f905c77ef3ff264f5d2be14091c8
|
Provenance
The following attestation bundles were made for pirateweather-1.0.0-py3-none-any.whl:
Publisher:
release.yml on Pirate-Weather/pirate-weather-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pirateweather-1.0.0-py3-none-any.whl -
Subject digest:
07a829bdc175721aac1409c487a7c659d7ffdcc124f8ce78dfdca9557401e448 - Sigstore transparency entry: 751010393
- Sigstore integration time:
-
Permalink:
Pirate-Weather/pirate-weather-python@a1c025d11b610b8f412a93ac4fac64e6a694b0f2 -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/Pirate-Weather
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a1c025d11b610b8f412a93ac4fac64e6a694b0f2 -
Trigger Event:
push
-
Statement type: