HALPIITax ID

HALPII Tax ID for Python

Last reviewed 2026-11-21 · HALPII S.A.C.

The package halpii-taxid is a client for the HALPII Tax ID API for Python 3.9 and later. It uses only the standard library (urllib); requests is an option when you already use it. Answers come back as dictionaries, described by TypedDict types for editors and type checkers.

Status. Not on PyPI yet. The package halpii-taxid is built and tested, but it is not published, so pip install halpii-taxid does not work yet. To use it now, write to contacto@halpii.com and we send you the wheel; or call the REST API with the standard library, as at the end of this page.

Quick start

import os
from halpii_taxid import HalpiiTaxId

taxid = HalpiiTaxId(api_key=os.environ.get("HALPII_TAXID_KEY"))

r = taxid.check("PE", "20615614841")  # HALPII S.A.C.
r["assessment"]["verdict"]   # "pass" | "review" | "fail"
r["assessment"]["reasons"]   # why, in plain words
r["verification_level"]      # "official_registry" | "format_and_lists" | "format"
r.get("legal_name")          # when the source publishes it

The key travels in the X-API-Key header. For countries with several ID types: taxid.check("FR", "FR00123456789", "vat"). Shortcut: from halpii_taxid import check.

Many IDs: check_batch

results = taxid.check_batch(
    [("PE", "20615614841"), ("MX", "XAXX010101000"), {"country": "FR", "id": "FR00123456789", "id_type": "vat"}],
    concurrency=4,
)
for e in results:
    print(e.country, e.id, e.verdict if e.ok else f"error: {e.error}")

One request per item, a few at a time in threads, the same order, repeated items sent once, and never an exception for a single item. After a 429 that cannot be retried, or a 401, the remaining items are not sent unless stop_on_limit=False.

Methods

MethodAPI call
check(country, id, id_type=None)The deepest check for that country
check_batch(items, concurrency=4, stop_on_limit=True)One lookup per item, a few at a time
peru_ruc, mexico_rfc, colombia_nit, costa_rica_cedulaThe four dedicated routes
countries()GET /v1/countries, not metered
usage(), limits()GET /v1/usage, GET /v1/limits (need a key; not lookups)
set_daily_cap(n)PUT /v1/limits (Monthly plan)
create_key(email)POST /v1/keys: a no-cost key with 100 lookups a month

Errors, retries and requests

A malformed ID is returned, not raised: format_valid is False and the verdict is fail. Other failures raise AuthenticationError, PermissionDeniedError, NotSupportedError, RateLimitError (with reset_at), SourceUnavailableError (not billed, with retry_after) or HalpiiConnectionError, all subclasses of HalpiiTaxIdError.

from halpii_taxid import RateLimitError, SourceUnavailableError

try:
    taxid.check("PE", "20615614841")
except RateLimitError as e:
    print("Limit reached until", e.reset_at)
except SourceUnavailableError as e:
    print("Try again in", e.retry_after, "s")
import requests
from halpii_taxid import HalpiiTaxId, requests_transport

taxid = HalpiiTaxId(api_key, transport=requests_transport(requests.Session()))

Retries are on by default (retry=2, max_retry_delay=60): a 503 is retried after Retry-After, and a 429 only when the limit resets within max_retry_delay. retry=False turns it off.

Without the package

import json, os, urllib.request

req = urllib.request.Request(
    "https://taxid.halpii.com/v1/pe/ruc/20615614841",
    headers={"X-API-Key": os.environ["HALPII_TAXID_KEY"]},
)
with urllib.request.urlopen(req, timeout=30) as res:
    print(json.load(res)["assessment"]["verdict"])
CountryEndpoint
Peru (RUC)GET /v1/pe/ruc/{ruc}
Mexico (RFC)GET /v1/mx/rfc/{rfc}
Colombia (NIT)GET /v1/co/nit/{nit}
Costa Rica (cédula)GET /v1/cr/cedula/{cedula}
Every other countryGET /v1/validate?country=XX&id=… (optional &id_type=…)

Note that urlopen raises on a 400; the package returns that answer for you.

What the verdict means

VerdictMeaning
passRegistered and in good standing per the official source
reviewNeeds a human look: an unusual status, a not-found the source cannot rule out, or a check that stopped at the format. Mexico RFCs never get pass, because Mexico publishes no RFC registry
failMalformed, wrong check digit, not active, or on a tax-authority list

MIT licence. Source: folder python of the halpii-taxid-integraciones repository. HALPII Tax ID is an independent service run by HALPII S.A.C. and is not affiliated with or endorsed by any tax authority.