Registry / security / pycpfcnpj

pycpfcnpj

JSON →
library1.9pypypi✓ verified 86d ago

Python module for Brazilian register numbers for persons (CPF) and companies (CNPJ). It provides functions to validate, format, and generate CPF and CNPJ numbers. Current version: 1.9, requires Python >=3.8, <4. Release cadence is irregular.

pip install pycpfcnpj
INSTALL
IMPORT
SIG · PYCPFCNPJ
P
pycpfcnpj
securitypythonv1.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cpf
from pycpfcnpj import cpf
import pycpfcnpj; pycpfcnpj.cpf.validate()
Direct import is cleaner and avoids attribute confusion
cnpj
from pycpfcnpj import cnpj
from pycpfcnpj.pycpfcnpj import cnpj
Do not nest imports into submodule path

Basic usage: validate and generate CPF/CNPJ numbers.

from pycpfcnpj import cpf, cnpj # CPF validation and generation print('CPF 123.456.789-09 válido?', cpf.validate('123.456.789-09')) print('CPF 52998224725 válido?', cpf.validate('52998224725')) print('CPF gerado formatado:', cpf.generate()) # CNPJ validation and generation print('CNPJ 11.222.333/0001-81 válido?', cnpj.validate('11.222.333/0001-81')) print('CNPJ gerado:', cnpj.generate())
Debug
Known issues
breakingIn version 1.7, the `validate` function was changed to return boolean instead of raising exceptions for invalid numbers. Old code that expects exceptions will break.
fix
Update code to check return value instead of catching exceptions.
affects: <1.7
deprecatedThe `pycpfcnpj.compatible` module is deprecated and may be removed in future versions. Use `cpf` and `cnpj` submodules directly.
fix
Import from `pycpfcnpj.cpf` and `pycpfcnpj.cnpj` directly.
affects: all
gotchaCPF validation accepts both formatted (with dots and dashes) and unformatted strings, but CNPJ validation expects exactly 14 digits if unformatted. Leading zeros matter – numbers like '00000000000191' are valid CNPJs but might be mistaken as invalid if truncated.
fix
Always pass the full 11-digit (CPF) or 14-digit (CNPJ) string without extra characters.
affects: all
Errors
Common errors & fixes
AttributeError: module 'pycpfcnpj' has no attribute 'validate'
Attempted to call `pycpfcnpj.validate()` directly instead of using `cpf.validate()` or `cnpj.validate()`.
fix
Use `from pycpfcnpj import cpf; cpf.validate('12345678909')`.
AttributeError: module 'pycpfcnpj' has no attribute 'cnpj'
Legacy import path `from pycpfcnpj import pycpfcnpj` used.
fix
Correct import: `from pycpfcnpj import cnpj`.
ValueError: The number 111222333000181 is not a valid CNPJ
CNPJ validation failed because the check digits are incorrect or the number was truncated (e.g., missing leading zeros).
fix
Ensure CNPJ is exactly 14 digits, and use a valid number. Generate a valid one with `cnpj.generate()`.
Upgrade
Version history
1.9latest on PyPI · released Jan 25, 2026
Audit
Dependencies
pycpfcnpjrequiredno third-party dependencies; pure Python
Agent activity
12 hits · last 30 days
node
12
Resources

No resource links recorded.

pycpfcnpj — pip install pycpfcnpj · libregistry