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
- Download.
base-gov download-contractslists 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. - Raw layer. Each
contratosYYYY.xlsxbecomescontracts_raw_YYYY.parquet, with the columns exactly as published. - Treated layer. All years together become
contracts.parquetplus 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. - 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.
- Database and dashboards. PostgreSQL 17 with
pg_parquetloads the files into aprocurementschema (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
| Contracts | 2,295,288 |
| Total contract value | €159.4 billion |
| Years | 2012 to 2026 (2026 up to 14 November) |
| Buyers (adjudicantes) | 11,145 |
| Awardees (adjudicatários) | 95,025 |
| Source workbooks | 15 files, 843 MB of Excel |
| Parquet | 300 MB raw, 304 MB treated |
| PostgreSQL database | 4.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:
TipoCriterioAdjudicacaowas dropped, and the buyer and awardee columns changed fromNIPC - Nametokey=valuetext. 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:
git clone https://github.com/neiro-data/portal-base-data-analysisanduv syncuv run base-gov download-contracts— the last three years by default. Use--years 10for ten years, orBACKFILL_CONFIRM=yes-download-all-years bin/backfill-contracts.shfor every year since 2012.bin/ingest-contracts.sh --year 2024 --year 2025 --year 2026— builds the raw and treated parquet files.make env,make build-db(first time only, slow: it compiles pg_parquet) andmake upmake ingest-postgres— loads the parquet files into PostgreSQL.docker compose --profile dashboard up -dand openhttp://127.0.0.1:3001- Optional:
make report DASHBOARD=overviewwrites an A4 PDF toreports/.
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
- Code: github.com/neiro-data/portal-base-data-analysis
- Blog post: Portugal’s public contracts are public. Getting them is not.
- Source data: dados.gov.pt, published by IMPIC on base.gov.pt