How to verify a Spanish company by NIF in Python

A short tutorial that verifies a Spanish company's NIF (Número de Identificación Fiscal) in about 30 lines of Python: validate the identifier locally with its control-character checksum, then resolve the full company profile from the official BORME registry via the Prometiam API.

What the guide covers

  • The NIF format — a leading letter for the legal form (A = SA, B = SL, and others), 7 digits, and a control character — and how to compute and check that control character offline before you spend an API call.
  • Calling GET /companies/search and GET /companies/{id} with a Bearer key to return the registered name, address, legal form, directors, and corporate-event timeline.
  • A copy-paste Python function returning a verified company profile, with error handling for invalid or unknown NIFs.

Runs on the free tier (1,000 calls/month, no credit card). The same key covers France, the UK, Ireland, Poland, and Norway, plus sanctions + US export-control screening.

Read more · Get a free API key

Frequently asked questions

What is a Spanish NIF?
NIF (Número de Identificación Fiscal) is the Spanish tax identifier. For companies it is 9 characters: a letter prefix indicating legal form (A=SA, B=SL, F=Cooperative, etc.), 7 digits, and a control character that may be a digit or letter.
Can I validate a NIF without an API call?
Yes. The format and checksum are deterministic and can be checked entirely in Python with no network call. The Prometiam API call is needed afterward to confirm the NIF maps to a real registered company.
What if the NIF starts with X, Y, or Z?
Those prefixes are personal NIE (foreign-resident IDs), not corporate. Reject them at the validator step if you only accept companies.