Registry / serialization / validate-docbr

validate-docbr

JSON →
library2.0.0pypypi✓ verified 86d ago

validate-docbr is a Python library designed to validate Brazilian documents such as CPF, CNPJ, CNH, PIS, RENAVAM, and more. It is currently at version 2.0.0 and actively maintained with periodic releases that add new document types and improvements.

pip install validate-docbr
INSTALL
IMPORT
SIG · VALIDATE-DOCBR
V
validate-docbr
serializationpythonv2.0.0
Install
1.5s avg
Import
33ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.034s · 17.9MB
glibc
py 3.103.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')}")
Debug
Known issues
breakingVersion 2.0.0 and above require Python 3.10 or newer. Users on older Python versions (e.g., 3.9) will encounter installation errors.
fix
Upgrade your Python environment to 3.10 or higher, or pin your `validate-docbr` dependency to `<2.0.0` for Python 3.9 environments.
affects: >=2.0.0
gotchaThe `validate` method returns `True` or `False` directly and does not raise exceptions for invalid inputs. Ensure your code explicitly checks the boolean return value.
fix
Always check the boolean result of `validator.validate(doc)` before proceeding with operations that assume a valid document.
affects: all
gotchaThe library's validation methods generally handle documents with or without standard formatting (e.g., '123.456.789-00' vs '12345678900'). However, methods like `is_formatted` are strict about the exact formatting.
fix
Use `validator.validate(doc)` for general validity checks, and `validator.is_formatted(doc)` only when you need to specifically verify the string format.
affects: all
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
fix
cpf.validate('123.456.789-09') or strip first: cpf_str.replace('.','').replace('-','')
ModuleNotFoundError: No module named 'validate_docbr'
validate-docbr not installed
fix
pip install validate-docbr
AttributeError: module 'validate_docbr' has no attribute 'CPF'
Accessing validator from module instead of importing the class
fix
from validate_docbr import CPF
TypeError: argument of type 'NoneType' is not iterable
None passed to validate() instead of a string
fix
cpf.validate(document or '')
Install Issues
1 verified issue
ImportError: cannot import name 'ie' from 'validate_docbr'All platforms · Python 3.8 · 3.9 · 3.10 · 3.11
Upgrade
Version history
2.0.0latest on PyPI · released Apr 4, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
15
Amazon
1
OpenAI (training)
1
Resources
validate-docbr — pip install validate-docbr · libregistry