Gob APIcne.gob.mx ↗
Query current gasoline and diesel prices for all Mexican gas stations by state and municipality via the CNE cne.gob.mx API. Covers Regular, Premium, and Diesel.
What is the Gob API?
The CNE Mexico Fuel Prices API exposes 4 endpoints that return current Regular gasoline, Premium gasoline, and Diesel prices for gas stations across all 32 Mexican states. Starting with get_states to retrieve state IDs, you can drill down to municipality-level station data or pull all prices for an entire state in a single call using get_all_fuel_prices. Each station record includes address, product type, sub-product, and the active price.
No input parameters required.
curl -X GET 'https://api.parse.bot/scraper/8412a138-d867-4a05-a6e1-019af32d5f4e/get_states' \ -H 'X-API-Key: $PARSE_API_KEY'
Typed, relational, agent-ready
A generated client with real types, enums, and the links between objects — the structure a flat JSON response can't carry. Autocompletes in your editor and reads cleanly to coding agents.
- Fully typed · autocompletes
- Objects link to objects
- Typed errors & pagination
Typed Python client. Set up the SDK in your uv project, then pull this API’s typed client:
uv add parse-sdk uv run parse init uv run parse add --marketplace cne-gob-mx-api
uv run parse add --marketplace pulls a pinned snapshot of this canonical API — it won’t change underneath you. To customize it, subscribe and swap to your own copy.
"""Walkthrough: CNE Mexico Fuel Prices — browse states, drill into municipalities, compare prices."""
from parse_apis.cne_mexico_fuel_prices_api import CneMexicoFuelPrices, EntidadId, NotFoundError
client = CneMexicoFuelPrices()
# List all states — limit caps total items fetched.
for state in client.states.list(limit=5):
print(state.entidad_federativa_id, state.nombre)
# Drill into a specific state using the EntidadId enum.
aguascalientes = client.state(entidad_federativa_id=EntidadId._01)
# List municipalities in that state.
for muni in aguascalientes.municipalities.list(limit=3):
print(muni.municipio_id, muni.nombre)
# Take one municipality and get its fuel prices.
first_muni = aguascalientes.municipalities.list(limit=1).first()
if first_muni:
for price in first_muni.fuel_prices(limit=5):
print(price.numero, price.producto, price.precio_vigente)
# Get all fuel prices across the entire state (aggregates all municipalities).
try:
for station in aguascalientes.fuel_prices.list(limit=3):
print(station.direccion, station.producto, station.precio_vigente)
except NotFoundError as exc:
print(f"State not found: {exc}")
print("exercised: states.list / state() / municipalities.list / fuel_prices / fuel_prices.list")
Get all 32 Mexican states (entidades federativas) with their IDs. Use these IDs to query municipalities and fuel prices.
No input parameters required.
{
"type": "object",
"fields": {
"total": "integer — number of states returned",
"states": "array of objects with entidad_federativa_id (zero-padded 2-digit string) and nombre (state name)"
},
"sample": {
"data": {
"total": 32,
"states": [
{
"nombre": "Aguascalientes",
"entidad_federativa_id": "01"
},
{
"nombre": "Baja California",
"entidad_federativa_id": "02"
}
]
},
"status": "success"
}
}About the Gob API
Endpoints and Data Coverage
The API is organized as a two-level geographic hierarchy: states (entidades federativas) and municipalities. get_states returns all 32 Mexican states with their zero-padded two-digit IDs and names — these IDs are required inputs for every downstream query. get_municipalities accepts an entidad_id and returns a list of municipality objects, each with an entidad_federativa_id, a zero-padded three-digit municipio_id, and the municipality name.
Station-Level Fuel Prices
get_fuel_prices takes both entidad_id and municipio_id and returns all station-product entries for that municipality. Each entry in the stations array carries a station number (numero), direccion (street address), producto, sub_producto, and precio_vigente (the current numeric price). The total field tells you how many entries were returned. The three fuel products covered are Regular gasoline, Premium gasoline, and Diesel, so a single physical station typically produces three entries.
State-Wide Price Queries
get_all_fuel_prices accepts a required entidad_id and iterates across every municipality in that state, returning a unified stations array and a total_stations count. Because it aggregates across all municipalities, response time can range from 10 to 30 seconds for states with many municipalities. An errors array will appear in the response only when one or more municipality requests fail, letting you identify any gaps in coverage without silently discarding data.
The Gob API is a managed, monitored endpoint for cne.gob.mx — not a raw scraper you maintain. Every endpoint is automatically health-checked on a schedule, and when cne.gob.mx changes and a check fails, the API is automatically queued for repair and re-verified. It is built to keep working as the site underneath it changes.
This isn't an official cne.gob.mx API — it's an independent, maintained REST wrapper over public data. Where the source has no official API (or only a limited one), Parse gives you a stable contract over a source that never promised one, and keeps it current. Need a new endpoint or field? You can revise it yourself in plain English and the agent rebuilds it against the live site in minutes — contributing the change back to the shared API is free.
Will this API break when the source site changes?+
Is this an official API from the source site?+
Can I fix or extend this API myself if I need a new endpoint or field?+
What happens if I call an endpoint that has an issue?+
- Build a fuel price comparison map for Mexican drivers, plotting
precio_vigentebydireccionfor all stations in a municipality. - Track daily or weekly price changes for Regular and Premium gasoline across a state using
get_all_fuel_priceswith scheduled calls. - Identify the cheapest diesel corridor along a freight route by querying
get_fuel_pricesfor municipalities along the path. - Feed a logistics cost calculator with live diesel prices from specific states to estimate transportation expenses.
- Monitor regulatory compliance by flagging stations whose
precio_vigentedeviates significantly from the state average. - Populate a mobile app's 'nearest cheap fuel' feature using station addresses and current prices from
get_fuel_prices. - Aggregate historical price data by state for economic research on fuel inflation in Mexico.
| Tier | Price | Credits/month | Rate limit |
|---|---|---|---|
| Free | $0/mo | 100 | 5 req/min |
| Hobby | $30/mo | 1,000 | 20 req/min |
| Developer | $100/mo | 5,000 | 100 req/min |
One credit = one API call regardless of which marketplace API you call. Exceeding the rate limit returns a 429 response. Authenticate with the X-API-Key header.
Does CNE (cne.gob.mx) have an official developer API?+
What does each entry in the `stations` array actually contain?+
stations represents one fuel product at one station. It includes numero (station identifier), direccion (address), producto (fuel category), sub_producto (fuel sub-type), precio_vigente (the active price as a number), and entidad_federativa_id as an integer. A single physical station will appear as multiple entries — one per fuel product carried.Does the API include geographic coordinates (latitude/longitude) for each station?+
direccion (a street address) but no latitude or longitude fields. You can fork this API on Parse and revise it to add a geocoding step that resolves addresses to coordinates.How fresh are the fuel prices returned by the API?+
Can I filter `get_fuel_prices` results by a specific fuel type, such as only Diesel?+
producto or sub_producto. The full set of station-product entries for the municipality is returned, and filtering by fuel type must be done client-side on the stations array. You can fork this API on Parse and revise it to expose a producto filter parameter.