Portugal’s public contracts are public. Getting them is not.

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

All public contracts in Portugal are published on BASE4, the public procurement portal. In principle, anyone can see who bought what, from whom, and for how much. I wanted all of it in one database, so I could ask simple questions: who spends the most, how much goes through direct awards, which companies win the most money.

It took much more work than it should. This post explains why, and what I built.

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

Plan A: download public contracts in Portugal from BASE

I started where anyone would start: the search at base.gov.pt/Base4. It soon became clear that the portal is built to show contracts, not to give you the data:

  • No API. The search page is the only interface.
  • 25 results per page. For 2.3 million contracts, that is about 92,000 requests.
  • Cold queries take about two minutes, and many end in a timeout.
  • The “Exportar resultados” link stops at 250 rows.
  • In the browser, a filtered search sometimes fell back to the unfiltered default, without any message.

My first version was a scraper with retries and resumable batches. It worked, but slowly: one query for one entity and one month took 13 minutes, and the answer was zero contracts.

Plan B: public contracts in Portugal as Excel files

BASE has no API, but dados.gov.pt republishes the BASE bulk export as one Excel workbook per year, with all public contracts in Portugal since 2012. That is the only practical route. So the tool does this, in order:

  1. Download. It reads the dados.gov.pt API, downloads each contratosYYYY.xlsx and checks it against the published sha1. A file that did not change is skipped.
  2. Raw layer. Each workbook becomes one parquet file, with the columns exactly as published.
  3. Treated layer. All years together become one clean file: buyer and awardee fields parsed, entities keyed by NIPC, contracts under €10 flagged (not dropped), schema drift checked.
  4. Database. PostgreSQL 17 loads the parquet with pg_parquet. Grafana shows six dashboards, and one command makes an A4 PDF report for any buyer.

Today the database holds 2,295,288 contracts from 2012 to November 2026, worth €159.4 billion, from 11,145 buyers and 95,025 awardees.

What 2.3 million public contracts in Portugal show

Some first findings on public contracts in Portugal (nominal euros, 2026 is year-to-date):

ProcedureShare of contractsShare of value
Ajuste Direto (direct award)57.6%22.3%
Consulta Prévia14.5%6.7%
Concurso público (open tender)11.8%48.1%
Framework agreements (art. 259 + 258)12.1%14.4%
  • Volume grew from 64,783 contracts (€3.7bn) in 2012 to 248,276 contracts (€23.8bn) in 2025.
  • Municipalities signed 565,817 contracts, worth €39.9bn (25% of the total).
  • The largest buyer by value is Infraestruturas de Portugal: €9.2bn in 7,447 contracts.

What ARTE leaves for you to fix

Governamental agencies collect this data by law. What is published, you must repair yourself before you can use it:

  • The files change under you. A republication in October/November of 2026  rewrote every year back to 2012. The column TipoCriterioAdjudicacao disappeared, and the buyer and awardee columns changed from NIPC - Name to key=value text. My ingest failed. When that was fixed, 89% of the buyer names came out empty, because the parser expected the old format. Now each run checks the columns of every year, and it stops if more than 1% of the buyers do not parse.
  • No change signal. The API gives the same “last modified” date to every year. Only the checksum tells you that a file changed.
  • Winners you cannot identify. 238,601 contracts (10.4%, €8.0bn) have no awardee with a NIPC. The portal writes - as the NIF of every private person and every foreign company.
  • One company, hundreds of names. NIPC 504615947 (MEO) appears under 742 different name strings. 47% of the awardee NIPCs appear under more than one name, and for 10,972 of them the only difference is case, spaces or punctuation. The tool keys every entity on its NIPC, never on its name.
  • Values that make no sense. 215 contracts have a negative price, 6,774 have a price of zero, and 42,112 have no signature date. A column name has a typo upstream: ultActuliza.
  • Excel as the delivery format. One workbook needs 2 to 4 GB of RAM to read. A CSV or Parquet file would make this problem disappear.

None of these problems is hard to fix on the publisher’s side. A stable schema, a changelog, an API and the NIF where the law allows it would make the data on public contracts in Portugal truly open. Until then, transparency needs a data engineer.

What I learned

  1. Public data is not open data until a machine can read it and statistically analyze it.
  2. Key on identifiers, never on names. Names are free text, so they are never clean.
  3. Treat the source schema as hostile. Check every column on every run, and fail loudly.
  4. Keep a raw layer. When my parser was wrong, I rebuilt the clean data from the raw files, without downloading anything again.

Links

Picture of Nelson Eiró

Nelson Eiró

Senior Data Engineer

LinkedIn

Add comment: