validator-documents 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- validator_documents-0.1.0/.github/workflows/ci.yml +42 -0
- validator_documents-0.1.0/.github/workflows/publish-to-pypi.yml +37 -0
- validator_documents-0.1.0/.github/workflows/publish.yml +50 -0
- validator_documents-0.1.0/.gitignore +180 -0
- validator_documents-0.1.0/.vscode/settings.json +7 -0
- validator_documents-0.1.0/LICENSE +21 -0
- validator_documents-0.1.0/PKG-INFO +217 -0
- validator_documents-0.1.0/README.md +189 -0
- validator_documents-0.1.0/docs/EVOLUCAO.md +112 -0
- validator_documents-0.1.0/pyproject.toml +65 -0
- validator_documents-0.1.0/tests/test_dispatch.py +58 -0
- validator_documents-0.1.0/tests/test_models.py +112 -0
- validator_documents-0.1.0/tests/test_validators.py +379 -0
- validator_documents-0.1.0/validator_documents/__init__.py +77 -0
- validator_documents-0.1.0/validator_documents/_utils.py +23 -0
- validator_documents-0.1.0/validator_documents/cnh.py +67 -0
- validator_documents-0.1.0/validator_documents/cnpj.py +47 -0
- validator_documents-0.1.0/validator_documents/cpf.py +48 -0
- validator_documents-0.1.0/validator_documents/exceptions.py +13 -0
- validator_documents-0.1.0/validator_documents/models.py +115 -0
- validator_documents-0.1.0/validator_documents/pis.py +42 -0
- validator_documents-0.1.0/validator_documents/placa.py +71 -0
- validator_documents-0.1.0/validator_documents/renavam.py +45 -0
- validator_documents-0.1.0/validator_documents/titulo_eleitoral.py +70 -0
- validator_documents-0.1.0/validator_documents/validar.py +94 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint-and-test:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
python-version: ["3.10", "3.11", "3.12", "3.13"]
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: ${{ matrix.python-version }}
|
|
23
|
+
|
|
24
|
+
- name: Install dependencies
|
|
25
|
+
run: |
|
|
26
|
+
python -m pip install --upgrade pip
|
|
27
|
+
pip install ".[dev]"
|
|
28
|
+
|
|
29
|
+
- name: Lint (ruff)
|
|
30
|
+
run: ruff check .
|
|
31
|
+
|
|
32
|
+
- name: Format check (ruff)
|
|
33
|
+
run: ruff format --check .
|
|
34
|
+
|
|
35
|
+
- name: Test + coverage
|
|
36
|
+
run: pytest -q
|
|
37
|
+
|
|
38
|
+
- name: Upload coverage
|
|
39
|
+
uses: actions/upload-artifact@v4
|
|
40
|
+
with:
|
|
41
|
+
name: coverage-${{ matrix.python-version }}
|
|
42
|
+
path: coverage.xml
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
name: Publish Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*.*.*"
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
publish:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
steps:
|
|
13
|
+
- name: Checkout the code
|
|
14
|
+
uses: actions/checkout@v3
|
|
15
|
+
|
|
16
|
+
- name: Set up Python
|
|
17
|
+
uses: actions/setup-python@v4
|
|
18
|
+
with:
|
|
19
|
+
python-version: '3.x'
|
|
20
|
+
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: |
|
|
23
|
+
python -m pip install --upgrade pip
|
|
24
|
+
pip install setuptools wheel
|
|
25
|
+
pip install pytest
|
|
26
|
+
|
|
27
|
+
- name: Build the package
|
|
28
|
+
run: |
|
|
29
|
+
python setup.py sdist bdist_wheel
|
|
30
|
+
|
|
31
|
+
- name: Publish to PyPI
|
|
32
|
+
env:
|
|
33
|
+
TWINE_USERNAME: "__token__"
|
|
34
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
|
35
|
+
run: |
|
|
36
|
+
python -m pip install twine
|
|
37
|
+
twine upload dist/*
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
build:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Set up Python
|
|
20
|
+
uses: actions/setup-python@v5
|
|
21
|
+
with:
|
|
22
|
+
python-version: "3.12"
|
|
23
|
+
|
|
24
|
+
- name: Install build
|
|
25
|
+
run: python -m pip install --upgrade pip build
|
|
26
|
+
|
|
27
|
+
- name: Build package
|
|
28
|
+
run: python -m build
|
|
29
|
+
|
|
30
|
+
- name: Upload dist
|
|
31
|
+
uses: actions/upload-artifact@v4
|
|
32
|
+
with:
|
|
33
|
+
name: dist
|
|
34
|
+
path: dist/
|
|
35
|
+
|
|
36
|
+
publish:
|
|
37
|
+
needs: build
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
environment:
|
|
40
|
+
name: pypi
|
|
41
|
+
url: https://pypi.org/p/validator-documents
|
|
42
|
+
steps:
|
|
43
|
+
- name: Download dist
|
|
44
|
+
uses: actions/download-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: dist
|
|
47
|
+
path: dist/
|
|
48
|
+
|
|
49
|
+
- name: Publish to PyPI
|
|
50
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Created by https://www.toptal.com/developers/gitignore/api/python
|
|
2
|
+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
|
|
3
|
+
|
|
4
|
+
### Python ###
|
|
5
|
+
# Byte-compiled / optimized / DLL files
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*$py.class
|
|
9
|
+
|
|
10
|
+
# C extensions
|
|
11
|
+
*.so
|
|
12
|
+
|
|
13
|
+
# Distribution / packaging
|
|
14
|
+
.Python
|
|
15
|
+
build/
|
|
16
|
+
develop-eggs/
|
|
17
|
+
dist/
|
|
18
|
+
downloads/
|
|
19
|
+
eggs/
|
|
20
|
+
.eggs/
|
|
21
|
+
lib/
|
|
22
|
+
lib64/
|
|
23
|
+
parts/
|
|
24
|
+
sdist/
|
|
25
|
+
var/
|
|
26
|
+
wheels/
|
|
27
|
+
share/python-wheels/
|
|
28
|
+
*.egg-info/
|
|
29
|
+
.installed.cfg
|
|
30
|
+
*.egg
|
|
31
|
+
MANIFEST
|
|
32
|
+
|
|
33
|
+
# PyInstaller
|
|
34
|
+
# Usually these files are written by a python script from a template
|
|
35
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
36
|
+
*.manifest
|
|
37
|
+
*.spec
|
|
38
|
+
|
|
39
|
+
# Installer logs
|
|
40
|
+
pip-log.txt
|
|
41
|
+
pip-delete-this-directory.txt
|
|
42
|
+
|
|
43
|
+
# Unit test / coverage reports
|
|
44
|
+
htmlcov/
|
|
45
|
+
.tox/
|
|
46
|
+
.nox/
|
|
47
|
+
.coverage
|
|
48
|
+
.coverage.*
|
|
49
|
+
.cache
|
|
50
|
+
nosetests.xml
|
|
51
|
+
coverage.xml
|
|
52
|
+
*.cover
|
|
53
|
+
*.py,cover
|
|
54
|
+
.hypothesis/
|
|
55
|
+
.pytest_cache/
|
|
56
|
+
cover/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
db.sqlite3-journal
|
|
67
|
+
|
|
68
|
+
# Flask stuff:
|
|
69
|
+
instance/
|
|
70
|
+
.webassets-cache
|
|
71
|
+
|
|
72
|
+
# Scrapy stuff:
|
|
73
|
+
.scrapy
|
|
74
|
+
|
|
75
|
+
# Sphinx documentation
|
|
76
|
+
docs/_build/
|
|
77
|
+
|
|
78
|
+
# PyBuilder
|
|
79
|
+
.pybuilder/
|
|
80
|
+
target/
|
|
81
|
+
|
|
82
|
+
# Jupyter Notebook
|
|
83
|
+
.ipynb_checkpoints
|
|
84
|
+
|
|
85
|
+
# IPython
|
|
86
|
+
profile_default/
|
|
87
|
+
ipython_config.py
|
|
88
|
+
|
|
89
|
+
# pyenv
|
|
90
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
91
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
92
|
+
# .python-version
|
|
93
|
+
|
|
94
|
+
# pipenv
|
|
95
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
96
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
97
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
98
|
+
# install all needed dependencies.
|
|
99
|
+
#Pipfile.lock
|
|
100
|
+
|
|
101
|
+
# poetry
|
|
102
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
103
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
104
|
+
# commonly ignored for libraries.
|
|
105
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
106
|
+
#poetry.lock
|
|
107
|
+
|
|
108
|
+
# pdm
|
|
109
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
110
|
+
#pdm.lock
|
|
111
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
112
|
+
# in version control.
|
|
113
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
114
|
+
.pdm.toml
|
|
115
|
+
|
|
116
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
117
|
+
__pypackages__/
|
|
118
|
+
|
|
119
|
+
# Celery stuff
|
|
120
|
+
celerybeat-schedule
|
|
121
|
+
celerybeat.pid
|
|
122
|
+
|
|
123
|
+
# SageMath parsed files
|
|
124
|
+
*.sage.py
|
|
125
|
+
|
|
126
|
+
# Environments
|
|
127
|
+
.env
|
|
128
|
+
.venv
|
|
129
|
+
env/
|
|
130
|
+
venv/
|
|
131
|
+
ENV/
|
|
132
|
+
env.bak/
|
|
133
|
+
venv.bak/
|
|
134
|
+
|
|
135
|
+
# Spyder project settings
|
|
136
|
+
.spyderproject
|
|
137
|
+
.spyproject
|
|
138
|
+
|
|
139
|
+
# Rope project settings
|
|
140
|
+
.ropeproject
|
|
141
|
+
|
|
142
|
+
# mkdocs documentation
|
|
143
|
+
/site
|
|
144
|
+
|
|
145
|
+
# mypy
|
|
146
|
+
.mypy_cache/
|
|
147
|
+
.dmypy.json
|
|
148
|
+
dmypy.json
|
|
149
|
+
|
|
150
|
+
# Pyre type checker
|
|
151
|
+
.pyre/
|
|
152
|
+
|
|
153
|
+
# pytype static type analyzer
|
|
154
|
+
.pytype/
|
|
155
|
+
|
|
156
|
+
# Cython debug symbols
|
|
157
|
+
cython_debug/
|
|
158
|
+
|
|
159
|
+
# PyCharm
|
|
160
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
161
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
162
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
163
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
164
|
+
#.idea/
|
|
165
|
+
|
|
166
|
+
### Python Patch ###
|
|
167
|
+
# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration
|
|
168
|
+
poetry.toml
|
|
169
|
+
|
|
170
|
+
# ruff
|
|
171
|
+
.ruff_cache/
|
|
172
|
+
|
|
173
|
+
# LSP config files
|
|
174
|
+
pyrightconfig.json
|
|
175
|
+
|
|
176
|
+
# Graphify (knowledge graph output — local only, never committed)
|
|
177
|
+
graphify-out/
|
|
178
|
+
raw/
|
|
179
|
+
|
|
180
|
+
# End of https://www.toptal.com/developers/gitignore/api/python
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 edmaker89
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: validator-documents
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Validação e formatação de documentos brasileiros (CPF, CNPJ, PIS, Título Eleitoral, CNH, RENAVAM, Placa).
|
|
5
|
+
Project-URL: Homepage, https://github.com/edmaker89/validator_documents_package
|
|
6
|
+
Project-URL: Repository, https://github.com/edmaker89/validator_documents_package
|
|
7
|
+
Project-URL: Issues, https://github.com/edmaker89/validator_documents_package/issues
|
|
8
|
+
Author-email: edmaker89 <edmaker@gmail.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: brasil,cnh,cnpj,cpf,pis,placa,renavam,titulo-eleitoral,validador
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: pydantic>=2.5
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: build>=1.2; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest-cov>=5; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest>=8; extra == 'dev'
|
|
26
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# validator-documents
|
|
30
|
+
|
|
31
|
+
[](https://pypi.org/project/validator-documents/)
|
|
32
|
+
[](https://pypi.org/project/validator-documents/)
|
|
33
|
+
[](https://opensource.org/licenses/MIT)
|
|
34
|
+
[](https://github.com/edmaker89/validator_documents_package/actions/workflows/ci.yml)
|
|
35
|
+
[](https://github.com/edmaker89/validator_documents_package/actions/workflows/ci.yml)
|
|
36
|
+
|
|
37
|
+
Validação e formatação de documentos brasileiros com tipagem Pydantic v2.
|
|
38
|
+
|
|
39
|
+
**Documentos suportados:**
|
|
40
|
+
- CPF (Cadastro de Pessoas Físicas)
|
|
41
|
+
- CNPJ (Cadastro Nacional da Pessoa Jurídica)
|
|
42
|
+
- PIS/NIS/PASEP/NIT
|
|
43
|
+
- Título Eleitoral
|
|
44
|
+
- CNH (Carteira Nacional de Habilitação)
|
|
45
|
+
- RENAVAM (Registro Nacional de Veículos Automotores)
|
|
46
|
+
- Placa veicular (padrão antigo e Mercosul)
|
|
47
|
+
|
|
48
|
+
## Instalação
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install validator-documents
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Requer Python ≥ 3.10.
|
|
55
|
+
|
|
56
|
+
## Uso rápido
|
|
57
|
+
|
|
58
|
+
### Funções funcionais (por tipo)
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from validator_documents import (
|
|
62
|
+
validar_cpf,
|
|
63
|
+
formatar_cpf,
|
|
64
|
+
validar_cnpj,
|
|
65
|
+
formatar_cnpj,
|
|
66
|
+
validar_pis,
|
|
67
|
+
formatar_pis,
|
|
68
|
+
validar_titulo_eleitoral,
|
|
69
|
+
formatar_titulo_eleitoral,
|
|
70
|
+
validar_cnh,
|
|
71
|
+
formatar_cnh,
|
|
72
|
+
validar_renavam,
|
|
73
|
+
formatar_renavam,
|
|
74
|
+
validar_placa,
|
|
75
|
+
formatar_placa,
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
# Validação
|
|
79
|
+
validar_cpf("775.488.241-81") # True
|
|
80
|
+
validar_cnpj("67.646.869/6391-55") # True
|
|
81
|
+
validar_pis("435.20735.46-7") # True
|
|
82
|
+
validar_titulo_eleitoral("7634 6850 1392") # True
|
|
83
|
+
validar_cnh("636 778 226 35") # True
|
|
84
|
+
validar_renavam("1502137447-1") # True
|
|
85
|
+
validar_placa("ABC1234") # True (antigo)
|
|
86
|
+
validar_placa("ABC1D23") # True (Mercosul)
|
|
87
|
+
|
|
88
|
+
# Formatação
|
|
89
|
+
formatar_cpf("77548824181") # "775.488.241-81"
|
|
90
|
+
formatar_cnpj("67646869639155") # "67.646.869/6391-55"
|
|
91
|
+
formatar_placa("abc1234") # "ABC-1234"
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Geração de documentos válidos (para testes/fixtures)
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from validator_documents import (
|
|
98
|
+
gerar_cpf,
|
|
99
|
+
gerar_cnpj,
|
|
100
|
+
gerar_pis,
|
|
101
|
+
gerar_titulo_eleitoral,
|
|
102
|
+
gerar_cnh,
|
|
103
|
+
gerar_renavam,
|
|
104
|
+
gerar_placa,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
# Funções funcionais
|
|
108
|
+
cpf = gerar_cpf() # "775.488.241-81"
|
|
109
|
+
cnpj = gerar_cnpj() # "67.646.869/6391-55"
|
|
110
|
+
pis = gerar_pis() # "435.20735.46-7"
|
|
111
|
+
titulo = gerar_titulo_eleitoral() # "7634 6850 1392"
|
|
112
|
+
cnh = gerar_cnh() # "636 778 226 35"
|
|
113
|
+
renavam = gerar_renavam() # "1502137447-1"
|
|
114
|
+
placa_antigo = gerar_placa() # "ABC-1234"
|
|
115
|
+
placa_mercosul = gerar_placa(True) # "ABC1D23"
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Modelos Pydantic com `.gerar()`
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from validator_documents import CPF, CNPJ, PIS, TituloEleitoral, CNH, Renavam, Placa
|
|
122
|
+
|
|
123
|
+
# Classe método .gerar() retorna instância tipada válida
|
|
124
|
+
cpf = CPF.gerar()
|
|
125
|
+
cpf.valor # "77548824181" (apenas dígitos)
|
|
126
|
+
cpf.formatado # "775.488.241-81"
|
|
127
|
+
|
|
128
|
+
cnpj = CNPJ.gerar()
|
|
129
|
+
pis = PIS.gerar()
|
|
130
|
+
# ... idem para TituloEleitoral, CNH, Renavam, Placa
|
|
131
|
+
|
|
132
|
+
# Placa Mercosul via função + modelo
|
|
133
|
+
from validator_documents import gerar_placa
|
|
134
|
+
|
|
135
|
+
placa_mercosul = Placa(valor=gerar_placa(mercosul=True))
|
|
136
|
+
placa_mercosul.formatado # "ABC1D23" (sem hífen)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Despacho genérico
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from validator_documents import validar_documento, identificar_documento
|
|
143
|
+
|
|
144
|
+
# Tipo explícito (recomendado para evitar ambiguidade de 11 dígitos)
|
|
145
|
+
validar_documento("77548824181", tipo="CPF") # True
|
|
146
|
+
validar_documento("775.488.241-81", tipo="CPF", formatado=True) # "775.488.241-81"
|
|
147
|
+
|
|
148
|
+
# Identificação automática (funciona apenas quando não ambíguo)
|
|
149
|
+
identificar_documento("77548824181") # "CPF"
|
|
150
|
+
identificar_documento("ABC1234") # "PLACA"
|
|
151
|
+
|
|
152
|
+
# 11 dígitos é ambíguo (CPF/PIS/CNH/RENAVAM) — lança DocumentoNaoIdentificado
|
|
153
|
+
identificar_documento("12345678901") # Exception: use tipo explícito
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Modelos Pydantic (tipagem estática)
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
from validator_documents import CPF, CNPJ, PIS, TituloEleitoral, CNH, Renavam, Placa
|
|
160
|
+
|
|
161
|
+
cpf = CPF(valor="775.488.241-81")
|
|
162
|
+
cpf.valor # "77548824181" (apenas dígitos)
|
|
163
|
+
cpf.formatado # "775.488.241-81"
|
|
164
|
+
|
|
165
|
+
# Valida na construção — levanta DocumentoInvalido se inválido
|
|
166
|
+
try:
|
|
167
|
+
CPF(valor="11111111111")
|
|
168
|
+
except DocumentoInvalido as e:
|
|
169
|
+
print(e) # "CPF inválido: '11111111111'"
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Tipos de exceção
|
|
173
|
+
|
|
174
|
+
```python
|
|
175
|
+
from validator_documents import DocumentoInvalido, DocumentoNaoIdentificado
|
|
176
|
+
|
|
177
|
+
# DocumentoInvalido — DV/formato incorreto
|
|
178
|
+
# DocumentoNaoIdentificado — identificação automática ambígua
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Compatibilidade e decisões de design
|
|
182
|
+
|
|
183
|
+
| Documento | Tamanho | DV? | Padrão de formatação |
|
|
184
|
+
|-----------|---------|-----|----------------------|
|
|
185
|
+
| CPF | 11 | Sim | `XXX.XXX.XXX-XX` |
|
|
186
|
+
| CNPJ | 14 | Sim | `XX.XXX.XXX/XXXX-XX` |
|
|
187
|
+
| PIS | 11 | Sim | `XXX.XXXXX.XX-X` |
|
|
188
|
+
| Título Eleitoral | 12 | Sim | `XXXX XXXX XXXX` |
|
|
189
|
+
| CNH | 11 | Sim | `XXX XXX XXX XX` |
|
|
190
|
+
| RENAVAM | 11 | Sim | `XXXXXXXXXX-X` |
|
|
191
|
+
| Placa | 7 alfanum. | Não | `ABC-1234` (antigo) / `ABC1D23` (Mercosul) |
|
|
192
|
+
|
|
193
|
+
**Decisões relevantes:**
|
|
194
|
+
- **Identificação automática por comprimento** é limitada: 11 dígitos corresponde a CPF, PIS, CNH e RENAVAM — nesses casos, use `validar_documento(valor, tipo="...")` explícito.
|
|
195
|
+
- **Título Eleitoral**: segue a Resolução TSE 23.659/2021 (sem exceção SP/MG onde resto 0 vira 1). Se seu caso de uso exigir a exceção legada, abra uma issue.
|
|
196
|
+
- **Placa Mercosul**: formatada sem hífen (`ABC1D23`), conforme padrão oficial.
|
|
197
|
+
- **Dígitos repetidos** (ex.: `111.111.111-11`) são rejeitados para CPF, CNPJ, PIS e CNH.
|
|
198
|
+
|
|
199
|
+
## Desenvolvimento
|
|
200
|
+
|
|
201
|
+
```bash
|
|
202
|
+
# Instala dependências de dev
|
|
203
|
+
pip install ".[dev]"
|
|
204
|
+
|
|
205
|
+
# Lint
|
|
206
|
+
ruff check .
|
|
207
|
+
|
|
208
|
+
# Format
|
|
209
|
+
ruff format .
|
|
210
|
+
|
|
211
|
+
# Testes + cobertura
|
|
212
|
+
pytest -q
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Licença
|
|
216
|
+
|
|
217
|
+
MIT — veja [LICENSE](LICENSE).
|