Spain Gas API

API to retrieve gas station prices in Spain.

Spain Gas API

Spain’s official fuel-price data, wrapped in a clean JSON API.

Live API · Source

Spain’s Ministry for Ecological Transition (MITECO) publishes fuel prices for every gas station in the country — but the public API is a pain to use: you need to chain a municipality-ID lookup before you can even ask for prices, and the response is a huge, Spanish-formatted payload (comma decimals, national field names). I built a thin layer on top that does the chaining and formatting for you, so one request gets you clean data.

What it does

  • One request, by municipality and province, returns every gas station’s prices for petrol, diesel, CNG, LNG and hydrogen — as plain numbers
  • No date? No problem — defaults to yesterday, since today’s government data is often still incomplete
  • No API key, no signup — hit the endpoint and get JSON back

How it’s built

A serverless Python Lambda behind API Gateway: the function receives the request, resolves the municipality to MITECO’s internal ID, calls the government API, and reshapes the response before handing it back. Zero third-party dependencies — just the Python standard library — and unit-tested with mocked government-API responses covering the validation, parsing and error paths.

  • No wasted round-trips — the municipality → ID lookup table (thousands of entries) is bundled with the Lambda as a local file, so every request skips straight to fetching prices instead of resolving IDs first
  • Built to grow — each endpoint lives in its own folder with its own Lambda and README; new ones get added the same way, with releases tracked in a Keep-a-Changelog, semantically versioned CHANGELOG.md
  • Documented and deployed — an OpenAPI 3.0 spec ships in the repo, and the API itself runs on AWS Lambda + API Gateway

Try the live endpoint — real prices, right now.