brazilnum
Validate Brazilian CNPJ, CEI, CPF, PIS/PASEP, CEP, and municipal numbers
What it is and what it does
Brazilnum is a validation and formatting library for Brazilian identification numbers used by individuals, businesses, and government systems. It handles CNPJ (corporate tax ID), CEI (business registration), CPF (individual tax ID), PIS/PASEP (social security), CEP (postal codes), and IBGE municipal codes. The library accepts both formatted strings and raw numeric input, auto-corrects missing leading zeros in integers, and treats missing values (None, NaN) as invalid rather than raising errors—useful for data pipelines with incomplete records.
Beyond validation, it provides formatting functions to display identifiers in standard Brazilian notation, parsing functions to extract components (firm ID, establishment number, check digits), and utilities to clean formatting. It recently added support for alphanumeric CNPJ format introduced in 2026. The package has no external dependencies and supports Python 3.9 through 3.14, making it lightweight for integration into larger systems.
Use it for:
- Validate customer CNPJ or CPF during account registration or payment processing.
- Parse CNPJ to extract firm and establishment identifiers for business lookup.
- Format and clean Brazilian ID numbers from data imports or user input.
- Validate CEP postal codes when processing Brazilian shipping addresses.
- Batch-validate municipal codes from government or census data sources.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Validates and formats Brazilian identification numbers including CNPJ, CEI, CPF, PIS/PASEP, CEP, and municipal codes, with support for both numeric and alphanumeric formats.
Yes. The package is actively maintained, has zero known vulnerabilities, imposes no dependency overhead, and solves a specific domain problem well. Install it if you work with Brazilian identification numbers in production systems or data pipelines.
Install
brazilnum on PyPI
pip
pip install brazilnumuv
uv add brazilnumpoetry
poetry add brazilnumInstalling brazilnum
Before you install
Low install friction with no runtime dependencies. Active maintenance: last release 21 days ago, repository shows ongoing development with 99 stars.
License in practice
MIT license permits commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
pip install brazilnum
from brazilnum.cnpj import validate_cnpj
from brazilnum.cpf import validate_cpf
validate_cnpj('02.558.157/0001-62') # True
validate_cpf('968.811.342-58') # True
Requires Python 3.9 or newer.
Verify before relying
- Whether alphanumeric CNPJ support (added in version 0.9.0) is production-ready or still experimental.
- Performance characteristics when validating large batches of identifiers.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 21 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 337,580/month — #7,447 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: brazilnum-0.10.0-py3-none-any.whl
Keywords: brazil, brasil, cnpj, cei, cpf, pis, pasep, cep
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
validate-docbrValidates and generates Brazilian identity and…
permissive · top 15,000 on PyPI
python-stdnumParses, validates, and reformats standard…
copyleft · top 5,000 on PyPI
luhnGenerates and verifies Luhn check digits for…
permissive · top 15,000 on PyPI
BrazilFiscalReportConverts Brazilian electronic invoice XML files…
agpl · top 15,000 on PyPI
django-phonenumber-fieldProvides a Django model field for storing,…
permissive · top 5,000 on PyPI
django-phonenumbersProvides a Django model field and form field…
permissive · top 15,000 on PyPI
iso639-langResolves ISO 639 language codes and names to…
permissive · top 15,000 on PyPI
sigfigRounds numbers by significant figures, decimal…
permissive · top 5,000 on PyPI
fastnumbersConverts strings and other inputs to numbers…
permissive · top 15,000 on PyPI