Sample code

  • Learn how to access the forecast grid API using Python and the requests and xarray libraries.

  • Discover how to visualize forecast grid data using the provided Public Contrails API Tester notebook.

  • Understand how to access the forecast region API with Python and the requests and geopandas libraries.

Access the forecast grid API with Python:

import io
import requests
import xarray as xr

API_KEY = "AIza...(replace with your API key)"
params = {"time": "2025-05-15T20:00:00Z"}

response = requests.get(
    url="https://contrails.googleapis.com/v2/grids",
    params=params,
    headers={"x-goog-api-key": API_KEY},
)
response.raise_for_status()

dataset = xr.load_dataset(io.BytesIO(response.content))

To visualize the data, use the Public_Contrails_API_Tester notebook.

To access the forecast region API with Python:

import requests
import geopandas as gpd

API_KEY = "AIza...(replace with your API key)"
params = {"time": "2025-05-15T20:00:00Z"}

response = requests.get(
    url="https://contrails.googleapis.com/v2/regions",
    params=params,
    headers={"x-goog-api-key": API_KEY},
)
response.raise_for_status()

geodataframe = gpd.GeoDataFrame.from_features(response.json())