Sample code
Stay organized with collections
Save and categorize content based on your preferences.
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())
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-02 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-02 UTC."],[[["Access the Contrails API using Python with libraries like `requests` and `xarray` to retrieve contrail environmental impact data."],["Define parameters such as bounding box, aircraft type, and time to specify your API query."],["Utilize the provided Google API key and endpoint URL for authentication and data retrieval."],["Refer to the linked Google Colab notebook for a comprehensive example on querying the API and visualizing the data."]]],[]]