docs-validator 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bruno Ramos
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,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: docs-validator
3
+ Version: 0.1.0
4
+ Summary: Brazilian document validator (CNPJ numeric and alphanumeric)
5
+ Author: Bruno Ramos
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # docs-validator
13
+
14
+ ![CI](https://github.com/thinkbruno/docs-validator/actions/workflows/ci.yml/badge.svg?branch=main)
15
+ ![Python](https://img.shields.io/badge/python-3.9%2B-blue)
16
+ ![License](https://img.shields.io/badge/license-MIT-green)
17
+
18
+ A lightweight Python library for validating Brazilian document
19
+ identifiers.
20
+
21
+ Currently the project supports:
22
+
23
+ - CNPJ (numeric)
24
+ - **Experimental support for alphanumeric CNPJ**
25
+
26
+ The project is designed with:
27
+
28
+ - clean architecture
29
+ - automated testing
30
+ - CI/CD
31
+ - PyPI-ready packaging
32
+
33
+ ---
34
+
35
+ # ⚠️ About Alphanumeric CNPJ
36
+
37
+ As of **2026**, there are **no alphanumeric CNPJ numbers in public
38
+ circulation**.
39
+
40
+ The future format has been announced by the Receita Federal do Brasil,
41
+ but the official database still contains **only numeric CNPJ
42
+ identifiers**.
43
+
44
+ Therefore:
45
+
46
+ ⚠️ Any alphanumeric CNPJ used in this project is **only for algorithm
47
+ testing purposes** and **does not represent a real company**.
48
+
49
+ ---
50
+
51
+ # Experimental Validation Mode
52
+
53
+ To allow experimentation with the future format, the library supports an
54
+ **experimental validation mode**.
55
+
56
+ Example:
57
+
58
+ ```python
59
+ from docs_validator import validate
60
+
61
+ validate("12ABC34501DE35", mode="experimental")
62
+ ```
63
+
64
+ When using `mode="experimental"`:
65
+
66
+ - letters **A-Z** are allowed in the first 12 positions
67
+ - letters are converted using **base36 mapping**
68
+ - the **same modulo‑11 check digit algorithm** is applied
69
+
70
+ Mapping example:
71
+
72
+ A = 10
73
+ B = 11
74
+ ...
75
+ Z = 35
76
+
77
+ Without experimental mode:
78
+
79
+ ```python
80
+ validate("12ABC34501DE35")
81
+ # returns False
82
+ ```
83
+
84
+ ---
85
+
86
+ # Installation
87
+
88
+ ```bash
89
+ pip install docs-validator
90
+ ```
91
+
92
+ ---
93
+
94
+ # Usage
95
+
96
+ ## Validate numeric CNPJ
97
+
98
+ ```python
99
+ from docs_validator import validate
100
+
101
+ validate("11222333000181")
102
+ ```
103
+
104
+ ## Validate experimental alphanumeric CNPJ
105
+
106
+ ```python
107
+ validate("12ABC34501DE35", mode="experimental")
108
+ ```
109
+
110
+ ## Format CNPJ
111
+
112
+ ```python
113
+ from docs_validator import format_cnpj
114
+
115
+ format_cnpj("11222333000181")
116
+ ```
117
+
118
+ Output:
119
+
120
+ 11.222.333/0001-81
121
+
122
+ ---
123
+
124
+ # Running tests
125
+
126
+ ```bash
127
+ pytest --cov=docs_validator
128
+ ```
129
+
130
+ Generate HTML coverage report:
131
+
132
+ ```bash
133
+ pytest --cov=docs_validator --cov-report=html
134
+ ```
135
+
136
+ ---
137
+
138
+ # Project structure
139
+
140
+ docs-validator
141
+
142
+ ├── src/
143
+ │ └── docs_validator/
144
+
145
+ ├── tests/
146
+
147
+ ├── pyproject.toml
148
+ └── README.md
149
+
150
+ ---
151
+
152
+ # Roadmap
153
+
154
+ Planned features:
155
+
156
+ - CPF validation
157
+ - document generators
158
+ - CLI interface
159
+ - support for additional Brazilian identifiers
160
+ - benchmarking tools
161
+
162
+ ---
163
+
164
+ # Author
165
+
166
+ Bruno Ramos
167
+
168
+ LinkedIn\
169
+ https://www.linkedin.com/in/ramosbruno90/
170
+
171
+ GitHub\
172
+ https://github.com/thinkbruno
173
+
174
+ ---
175
+
176
+ # License
177
+
178
+ MIT
@@ -0,0 +1,167 @@
1
+ # docs-validator
2
+
3
+ ![CI](https://github.com/thinkbruno/docs-validator/actions/workflows/ci.yml/badge.svg?branch=main)
4
+ ![Python](https://img.shields.io/badge/python-3.9%2B-blue)
5
+ ![License](https://img.shields.io/badge/license-MIT-green)
6
+
7
+ A lightweight Python library for validating Brazilian document
8
+ identifiers.
9
+
10
+ Currently the project supports:
11
+
12
+ - CNPJ (numeric)
13
+ - **Experimental support for alphanumeric CNPJ**
14
+
15
+ The project is designed with:
16
+
17
+ - clean architecture
18
+ - automated testing
19
+ - CI/CD
20
+ - PyPI-ready packaging
21
+
22
+ ---
23
+
24
+ # ⚠️ About Alphanumeric CNPJ
25
+
26
+ As of **2026**, there are **no alphanumeric CNPJ numbers in public
27
+ circulation**.
28
+
29
+ The future format has been announced by the Receita Federal do Brasil,
30
+ but the official database still contains **only numeric CNPJ
31
+ identifiers**.
32
+
33
+ Therefore:
34
+
35
+ ⚠️ Any alphanumeric CNPJ used in this project is **only for algorithm
36
+ testing purposes** and **does not represent a real company**.
37
+
38
+ ---
39
+
40
+ # Experimental Validation Mode
41
+
42
+ To allow experimentation with the future format, the library supports an
43
+ **experimental validation mode**.
44
+
45
+ Example:
46
+
47
+ ```python
48
+ from docs_validator import validate
49
+
50
+ validate("12ABC34501DE35", mode="experimental")
51
+ ```
52
+
53
+ When using `mode="experimental"`:
54
+
55
+ - letters **A-Z** are allowed in the first 12 positions
56
+ - letters are converted using **base36 mapping**
57
+ - the **same modulo‑11 check digit algorithm** is applied
58
+
59
+ Mapping example:
60
+
61
+ A = 10
62
+ B = 11
63
+ ...
64
+ Z = 35
65
+
66
+ Without experimental mode:
67
+
68
+ ```python
69
+ validate("12ABC34501DE35")
70
+ # returns False
71
+ ```
72
+
73
+ ---
74
+
75
+ # Installation
76
+
77
+ ```bash
78
+ pip install docs-validator
79
+ ```
80
+
81
+ ---
82
+
83
+ # Usage
84
+
85
+ ## Validate numeric CNPJ
86
+
87
+ ```python
88
+ from docs_validator import validate
89
+
90
+ validate("11222333000181")
91
+ ```
92
+
93
+ ## Validate experimental alphanumeric CNPJ
94
+
95
+ ```python
96
+ validate("12ABC34501DE35", mode="experimental")
97
+ ```
98
+
99
+ ## Format CNPJ
100
+
101
+ ```python
102
+ from docs_validator import format_cnpj
103
+
104
+ format_cnpj("11222333000181")
105
+ ```
106
+
107
+ Output:
108
+
109
+ 11.222.333/0001-81
110
+
111
+ ---
112
+
113
+ # Running tests
114
+
115
+ ```bash
116
+ pytest --cov=docs_validator
117
+ ```
118
+
119
+ Generate HTML coverage report:
120
+
121
+ ```bash
122
+ pytest --cov=docs_validator --cov-report=html
123
+ ```
124
+
125
+ ---
126
+
127
+ # Project structure
128
+
129
+ docs-validator
130
+
131
+ ├── src/
132
+ │ └── docs_validator/
133
+
134
+ ├── tests/
135
+
136
+ ├── pyproject.toml
137
+ └── README.md
138
+
139
+ ---
140
+
141
+ # Roadmap
142
+
143
+ Planned features:
144
+
145
+ - CPF validation
146
+ - document generators
147
+ - CLI interface
148
+ - support for additional Brazilian identifiers
149
+ - benchmarking tools
150
+
151
+ ---
152
+
153
+ # Author
154
+
155
+ Bruno Ramos
156
+
157
+ LinkedIn\
158
+ https://www.linkedin.com/in/ramosbruno90/
159
+
160
+ GitHub\
161
+ https://github.com/thinkbruno
162
+
163
+ ---
164
+
165
+ # License
166
+
167
+ MIT
@@ -0,0 +1,18 @@
1
+ [project]
2
+ name = "docs-validator"
3
+ version = "0.1.0"
4
+ description = "Brazilian document validator (CNPJ numeric and alphanumeric)"
5
+ authors = [{ name = "Bruno Ramos" }]
6
+ readme = "README.md"
7
+ requires-python = ">=3.9"
8
+ license = { text = "MIT" }
9
+
10
+ [build-system]
11
+ requires = ["setuptools>=61"]
12
+ build-backend = "setuptools.build_meta"
13
+
14
+ [tool.setuptools]
15
+ package-dir = {"" = "src"}
16
+
17
+ [tool.setuptools.packages.find]
18
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,4 @@
1
+ from .validator import validate
2
+ from .formatter import format_cnpj
3
+
4
+ __all__ = ["validate", "format_cnpj"]
@@ -0,0 +1,15 @@
1
+ from .utils import char_to_value
2
+
3
+ WEIGHTS_FIRST = [5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2]
4
+ WEIGHTS_SECOND = [6] + WEIGHTS_FIRST
5
+
6
+
7
+ def calculate_digit(base: str, weights: list[int]) -> int:
8
+ total = 0
9
+
10
+ for char, weight in zip(base, weights):
11
+ total += char_to_value(char) * weight
12
+
13
+ remainder = total % 11
14
+
15
+ return 0 if remainder < 2 else 11 - remainder
@@ -0,0 +1,10 @@
1
+ from .utils import normalize
2
+
3
+
4
+ def format_cnpj(value: str) -> str:
5
+ value = normalize(value)
6
+
7
+ if len(value) != 14:
8
+ raise ValueError("Invalid CNPJ length")
9
+
10
+ return f"{value[:2]}.{value[2:5]}.{value[5:8]}/{value[8:12]}-{value[12:]}"
@@ -0,0 +1,18 @@
1
+ import re
2
+
3
+
4
+ def normalize(value: str) -> str:
5
+ """
6
+ Remove non alphanumeric characters and uppercase value
7
+ """
8
+ return re.sub(r"[^A-Z0-9]", "", value.upper())
9
+
10
+
11
+ def char_to_value(char: str) -> int:
12
+ """
13
+ Convert alphanumeric character to numeric value
14
+ """
15
+ if char.isdigit():
16
+ return int(char)
17
+
18
+ return ord(char) - 55 # A=10 ... Z=35
@@ -0,0 +1,17 @@
1
+ from .utils import normalize
2
+ from .dv import calculate_digit, WEIGHTS_FIRST, WEIGHTS_SECOND
3
+
4
+
5
+ def validate(cnpj: str) -> bool:
6
+ cnpj = normalize(cnpj)
7
+
8
+ if len(cnpj) != 14:
9
+ return False
10
+
11
+ base = cnpj[:12]
12
+ dv = cnpj[12:]
13
+
14
+ digit1 = calculate_digit(base, WEIGHTS_FIRST)
15
+ digit2 = calculate_digit(base + str(digit1), WEIGHTS_SECOND)
16
+
17
+ return dv == f"{digit1}{digit2}"
@@ -0,0 +1,178 @@
1
+ Metadata-Version: 2.4
2
+ Name: docs-validator
3
+ Version: 0.1.0
4
+ Summary: Brazilian document validator (CNPJ numeric and alphanumeric)
5
+ Author: Bruno Ramos
6
+ License: MIT
7
+ Requires-Python: >=3.9
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # docs-validator
13
+
14
+ ![CI](https://github.com/thinkbruno/docs-validator/actions/workflows/ci.yml/badge.svg?branch=main)
15
+ ![Python](https://img.shields.io/badge/python-3.9%2B-blue)
16
+ ![License](https://img.shields.io/badge/license-MIT-green)
17
+
18
+ A lightweight Python library for validating Brazilian document
19
+ identifiers.
20
+
21
+ Currently the project supports:
22
+
23
+ - CNPJ (numeric)
24
+ - **Experimental support for alphanumeric CNPJ**
25
+
26
+ The project is designed with:
27
+
28
+ - clean architecture
29
+ - automated testing
30
+ - CI/CD
31
+ - PyPI-ready packaging
32
+
33
+ ---
34
+
35
+ # ⚠️ About Alphanumeric CNPJ
36
+
37
+ As of **2026**, there are **no alphanumeric CNPJ numbers in public
38
+ circulation**.
39
+
40
+ The future format has been announced by the Receita Federal do Brasil,
41
+ but the official database still contains **only numeric CNPJ
42
+ identifiers**.
43
+
44
+ Therefore:
45
+
46
+ ⚠️ Any alphanumeric CNPJ used in this project is **only for algorithm
47
+ testing purposes** and **does not represent a real company**.
48
+
49
+ ---
50
+
51
+ # Experimental Validation Mode
52
+
53
+ To allow experimentation with the future format, the library supports an
54
+ **experimental validation mode**.
55
+
56
+ Example:
57
+
58
+ ```python
59
+ from docs_validator import validate
60
+
61
+ validate("12ABC34501DE35", mode="experimental")
62
+ ```
63
+
64
+ When using `mode="experimental"`:
65
+
66
+ - letters **A-Z** are allowed in the first 12 positions
67
+ - letters are converted using **base36 mapping**
68
+ - the **same modulo‑11 check digit algorithm** is applied
69
+
70
+ Mapping example:
71
+
72
+ A = 10
73
+ B = 11
74
+ ...
75
+ Z = 35
76
+
77
+ Without experimental mode:
78
+
79
+ ```python
80
+ validate("12ABC34501DE35")
81
+ # returns False
82
+ ```
83
+
84
+ ---
85
+
86
+ # Installation
87
+
88
+ ```bash
89
+ pip install docs-validator
90
+ ```
91
+
92
+ ---
93
+
94
+ # Usage
95
+
96
+ ## Validate numeric CNPJ
97
+
98
+ ```python
99
+ from docs_validator import validate
100
+
101
+ validate("11222333000181")
102
+ ```
103
+
104
+ ## Validate experimental alphanumeric CNPJ
105
+
106
+ ```python
107
+ validate("12ABC34501DE35", mode="experimental")
108
+ ```
109
+
110
+ ## Format CNPJ
111
+
112
+ ```python
113
+ from docs_validator import format_cnpj
114
+
115
+ format_cnpj("11222333000181")
116
+ ```
117
+
118
+ Output:
119
+
120
+ 11.222.333/0001-81
121
+
122
+ ---
123
+
124
+ # Running tests
125
+
126
+ ```bash
127
+ pytest --cov=docs_validator
128
+ ```
129
+
130
+ Generate HTML coverage report:
131
+
132
+ ```bash
133
+ pytest --cov=docs_validator --cov-report=html
134
+ ```
135
+
136
+ ---
137
+
138
+ # Project structure
139
+
140
+ docs-validator
141
+
142
+ ├── src/
143
+ │ └── docs_validator/
144
+
145
+ ├── tests/
146
+
147
+ ├── pyproject.toml
148
+ └── README.md
149
+
150
+ ---
151
+
152
+ # Roadmap
153
+
154
+ Planned features:
155
+
156
+ - CPF validation
157
+ - document generators
158
+ - CLI interface
159
+ - support for additional Brazilian identifiers
160
+ - benchmarking tools
161
+
162
+ ---
163
+
164
+ # Author
165
+
166
+ Bruno Ramos
167
+
168
+ LinkedIn\
169
+ https://www.linkedin.com/in/ramosbruno90/
170
+
171
+ GitHub\
172
+ https://github.com/thinkbruno
173
+
174
+ ---
175
+
176
+ # License
177
+
178
+ MIT
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/docs_validator/__init__.py
5
+ src/docs_validator/dv.py
6
+ src/docs_validator/formatter.py
7
+ src/docs_validator/utils.py
8
+ src/docs_validator/validator.py
9
+ src/docs_validator.egg-info/PKG-INFO
10
+ src/docs_validator.egg-info/SOURCES.txt
11
+ src/docs_validator.egg-info/dependency_links.txt
12
+ src/docs_validator.egg-info/top_level.txt
13
+ tests/test_validator.py
@@ -0,0 +1 @@
1
+ docs_validator
@@ -0,0 +1,13 @@
1
+ from cnpj_validator import validate
2
+
3
+
4
+ def test_valid_cnpj():
5
+ assert validate("11222333000181") is True
6
+
7
+
8
+ def test_invalid_cnpj():
9
+ assert validate("11222333000182") is False
10
+
11
+
12
+ def test_formatted_cnpj():
13
+ assert validate("11.222.333/0001-81") is True