Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.034s · 17.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.031s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
CPF
✓ from validate_docbr import CPF
CNPJ
✓ from validate_docbr import CNPJ
CNH
✓ from validate_docbr import CNH
PIS
✓ from validate_docbr import PIS
RENAVAM
✓ from validate_docbr import RENAVAM
This quickstart demonstrates how to import and use the CPF and CNPJ validators. It shows how to validate documents with and without formatting, and how to check if a document string adheres to the standard formatting.
from validate_docbr import CPF, CNPJ
# Example CPF validation
cpf_validator = CPF()
print(f"Is '123.456.789-00' a valid CPF? {cpf_validator.validate('123.456.789-00')}")
print(f"Is '111.111.111-11' a valid CPF? {cpf_validator.validate('111.111.111-11')}")
# Example CNPJ validation
cnpj_validator = CNPJ()
print(f"Is '11.222.333/0001-81' a valid CNPJ? {cnpj_validator.validate('11.222.333/0001-81')}")
print(f"Is '00.000.000/0000-00' a valid CNPJ? {cnpj_validator.validate('00.000.000/0000-00')}")
# Check if a document is formatted correctly
print(f"Is '123.456.789-00' formatted as a CPF? {cpf_validator.is_formatted('123.456.789-00')}")
print(f"Is '12345678900' formatted as a CPF? {cpf_validator.is_formatted('12345678900')}")
Errors
Common errors & fixes
CPF CNPJ validate() returns False for valid unformatted number
validate() accepts both formats but passing raw digits without formatting may silently return False
fixcpf.validate('123.456.789-09') or strip first: cpf_str.replace('.','').replace('-','') ModuleNotFoundError: No module named 'validate_docbr'
validate-docbr not installed
fixpip install validate-docbr
AttributeError: module 'validate_docbr' has no attribute 'CPF'
Accessing validator from module instead of importing the class
fixfrom validate_docbr import CPF
TypeError: argument of type 'NoneType' is not iterable
None passed to validate() instead of a string
fixcpf.validate(document or '')
Upgrade
Version history
2.0.0latest on PyPI · released Apr 4, 2026
Audit
Dependencies
No dependency data recorded yet.