Portugal Public Contracts (BASE)

Bar chart of public contracts in Portugal by year: value grew from €3.7bn in 2012 to €23.8bn in 2025; 2026 to 14 November is €17.6bn

Portugal Public Contracts (repository: portal-base-data-analysis) is a pipeline for Portugal public procurement data. It downloads the yearly BASE exports from dados.gov.pt, checks and cleans them, and loads them into PostgreSQL. Grafana shows the result in six dashboards, and one command makes an A4 PDF report for any buyer or supplier.

The goal is simple: make Portugal public procurement data as easy to query as it should be from the start.

Why Portugal public procurement data needs a tool

BASE (base.gov.pt) shows every Portuguese public contract, but it has no API. Its search returns 25 rows per page, cold queries take about two minutes and often time out, and the export link stops at 250 rows. The only practical way to get all the Portugal public procurement data is the yearly Excel workbooks that dados.gov.pt republishes. This tool reads them in order and turns them into one database.

How it works

  1. Download. base-gov download-contracts lists the workbooks through the dados.gov.pt API and checks each download against the published sha1. Unchanged files are skipped; a local file is never replaced by an unverified download.
  2. Raw layer. Each contratosYYYY.xlsx becomes contracts_raw_YYYY.parquet, with the columns exactly as published.
  3. Treated layer. All years together become contracts.parquet plus two entity files (buyers and awardees). Party fields are parsed from both source formats, entities are keyed by NIPC, and contracts under €10 are flagged.
  4. Guards. Every run reports schema drift per year. The ingest fails, and keeps the last good output, if a required column is missing or more than 1% of the buyers do not parse.
  5. Database and dashboards. PostgreSQL 17 with pg_parquet loads the files into a procurement schema (contracts, buyers, awardees and a contract–awardee bridge). Grafana has six dashboards: overview, contract table, the same two for municipalities only, and one drill-down each for a buyer and an awardee.

Stack: Python 3.12, uv, polars, typer, PostgreSQL 17, pg_parquet, Grafana, Docker.

Portugal public procurement data, 2012–2026

Contracts2,295,288
Total contract value€159.4 billion
Years2012 to 2026 (2026 up to 14 November)
Buyers (adjudicantes)11,145
Awardees (adjudicatários)95,025
Source workbooks15 files, 843 MB of Excel
Parquet300 MB raw, 304 MB treated
PostgreSQL database4.7 GB with indexes

First findings

What the Portugal public procurement data shows (nominal euros; contracts under €10 included):

  • Direct award is the norm by count, not by value. Ajuste Direto is 57.6% of the contracts but 22.3% of the value. Concurso público is 11.8% of the contracts and 48.1% of the value.
  • Volume grew almost four times. 64,783 contracts (€3.7bn) in 2012, 248,276 contracts (€23.8bn) in 2025.
  • Municipalities signed 565,817 contracts worth €39.9bn, 25% of the total value.
  • Largest buyer by value: Infraestruturas de Portugal, €9.2bn in 7,447 contracts.
  • 10.4% of the contracts (238,601, €8.0bn) have no identified awardee, because the portal publishes no NIF for private persons or foreign companies.

Data problems it handles

  • Schema changes. The 2026-11-15 republication rewrote every year: TipoCriterioAdjudicacao was dropped, and the buyer and awardee columns changed from NIPC - Name to key=value text. The tool reads both formats.
  • Many names for one entity. NIPC 504615947 appears under 742 name strings; 47% of the awardee NIPCs have more than one name. The tool keys on NIPC, not on name.
  • Missing identifiers. Awardees with NIF - stay in the contract text but get no entity row.
  • No change signal. The API gives the same date to every year; the sha1 is the only way to see that a year changed.

How to install the Portugal public procurement data pipeline

You need uv, Docker and make. Then:

  1. git clone https://github.com/neiro-data/portal-base-data-analysis and uv sync
  2. uv run base-gov download-contracts — the last three years by default. Use --years 10 for ten years, or BACKFILL_CONFIRM=yes-download-all-years bin/backfill-contracts.sh for every year since 2012.
  3. bin/ingest-contracts.sh --year 2024 --year 2025 --year 2026 — builds the raw and treated parquet files.
  4. make env, make build-db (first time only, slow: it compiles pg_parquet) and make up
  5. make ingest-postgres — loads the parquet files into PostgreSQL.
  6. docker compose --profile dashboard up -d and open http://127.0.0.1:3001
  7. Optional: make report DASHBOARD=overview writes an A4 PDF to reports/.

Reading one Excel workbook needs 2 to 4 GB of RAM. Grafana runs with anonymous access and listens on 127.0.0.1 only; do not expose it.

Links