Documents validator (CNPJ numeric and alphanumeric)
Project description
docs-validator
A lightweight Python library for validating and generating document numbers, starting with Brazilian documents.
The project focuses on:
- CPF validation
- CNPJ validation
- Experimental alphanumeric CNPJ
- Automatic document detection
- Document generators
- CLI usage
- PyPI distribution
- CI/CD and test coverage
Installation
pip install docs-validator
For development:
git clone https://github.com/thinkbruno/docs-validator
cd docs-validator
python -m venv .venv
source .venv/bin/activate
pip install -e .
Quick Usage
from docs_validator import validate
validate("52998224725")
validate("11222333000181")
API Overview
Generic Validation
The validate() function automatically detects the document type.
from docs_validator import validate
validate("52998224725") # CPF
validate("11222333000181") # CNPJ
Auto Detection
from docs_validator import detect
detect("52998224725")
detect("11222333000181")
detect("12ABC34501DE35")
Possible results:
CPF
CNPJ
CNPJ_ALPHANUMERIC
CPF Validation
from docs_validator import validate_cpf
validate_cpf("52998224725")
CNPJ Validation
from docs_validator import validate_cnpj
validate_cnpj("11222333000181")
Generators
Generate valid documents for testing environments.
from docs_validator import generate_cpf, generate_cnpj
generate_cpf()
generate_cnpj()
Example:
41799543807
30167399000130
Experimental: Alphanumeric CNPJ
Brazil's tax authority announced a future format allowing alphanumeric CNPJ identifiers.
The library includes an experimental validator for this format.
from docs_validator import validate
validate("12ABC34501DE35", mode="experimental")
⚠️ Important
As of 2026, no real alphanumeric CNPJs are publicly issued.
Any example used in tests or documentation is synthetic and only intended to validate the algorithm.
CLI Usage
After installation:
docs-validator validate 52998224725
docs-validator validate 11222333000181
Example output:
VALID
Testing
Run tests with:
pytest
Run with coverage:
pytest --cov=docs_validator
Project Structure
docs-validator
│
├── src
│ └── docs_validator
│ ├── validator.py
│ ├── detect.py
│ │
│ ├── br
│ │ ├── cpf.py
│ │ ├── cnpj.py
│ │ └── generators.py
│ │
│ └── experimental
│ └── cnpj_alphanumeric.py
│
├── tests
├── README.md
└── pyproject.toml
Example Test Script
from docs_validator import *
print(validate("52998224725"))
print(validate("11222333000181"))
print(detect("52998224725"))
print(detect("11222333000181"))
cpf = generate_cpf()
cnpj = generate_cnpj()
print(cpf, validate_cpf(cpf))
print(cnpj, validate_cnpj(cnpj))
print(validate("12ABC34501DE35", mode="experimental"))
Roadmap
Future goals for the library:
- Multi-country document validation
- Support for VAT / SSN style identifiers
- Additional generators
- Performance optimization
- Extended CLI capabilities
Portfolio
Author portfolio:
License
MIT License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file docs_validator-1.0.0.tar.gz.
File metadata
- Download URL: docs_validator-1.0.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aed127fc9c10dbf8820deb2e8d3139686e8ad92bd802480e224d88ace2c6c987
|
|
| MD5 |
4008c25bf18b1ec9f0a1ae73a1639beb
|
|
| BLAKE2b-256 |
6f6d2da2b01c103831e3a7e6821e147219950320859e9ed9324b2820efecb3bd
|
File details
Details for the file docs_validator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: docs_validator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
754e550b559345f75b3c3cfeee52107b022ec06003f2d89446ac94fe2bc6e71a
|
|
| MD5 |
19d70aaec149813c5bed746d9b2339a5
|
|
| BLAKE2b-256 |
924f1c18b7274056b582129ec8ac38ec61457d5ddce6aa1d0da3d56852b627ac
|