cnpj-val 1.0.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.
cnpj_val-1.0.0/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Julio L. Muller
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: cnpj-val
3
+ Version: 1.0.0
4
+ Summary: Utility function to validate CNPJ (Brazilian employer ID)
5
+ Author: Julio L. Muller
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://cnpj-utils.vercel.app/
8
+ Project-URL: Source, https://github.com/LacusSolutions/br-utils-py
9
+ Project-URL: Tracker, https://github.com/LacusSolutions/br-utils-py/issues
10
+ Keywords: cnpj,valid,validate,validator,validador,validar,pt-br,br
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Natural Language :: English
14
+ Classifier: Natural Language :: Portuguese (Brazilian)
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX
18
+ Classifier: Operating System :: Unix
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Software Development :: Libraries
26
+ Classifier: Topic :: Utilities
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: cnpj-cd>=1.0.0
31
+ Dynamic: license-file
32
+
33
+ ![cnpj-val for Python](https://github.com/user-attachments/assets/798de57c-445e-49f0-ba50-6fd72f12d8e4)
34
+
35
+ [![PyPI Version](https://img.shields.io/pypi/v/cnpj-val)](https://pypi.org/project/cnpj-val)
36
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/cnpj-val)](https://pypi.org/project/cnpj-val)
37
+ [![Python Version](https://img.shields.io/pypi/pyversions/cnpj-val)](https://www.python.org/)
38
+ [![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-py/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-py/actions)
39
+ [![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py)
40
+ [![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE)
41
+
42
+ Utility function/class to validate CNPJ (Brazilian employer ID).
43
+
44
+ ## Python Support
45
+
46
+ | ![Python 3.10](https://img.shields.io/badge/Python-3.10-3776AB?logo=python&logoColor=white) | ![Python 3.11](https://img.shields.io/badge/Python-3.11-3776AB?logo=python&logoColor=white) | ![Python 3.12](https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white) | ![Python 3.13](https://img.shields.io/badge/Python-3.13-3776AB?logo=python&logoColor=white) | ![Python 3.14](https://img.shields.io/badge/Python-3.14-3776AB?logo=python&logoColor=white) |
47
+ |--- | --- | --- | --- | --- |
48
+ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ $ pip install cnpj-val
54
+ ```
55
+
56
+ ## Import
57
+
58
+ ```python
59
+ # Using class-based resource
60
+ from cnpj_val import CnpjValidator
61
+
62
+ # Or using function-based one
63
+ from cnpj_val import cnpj_val
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ### Object-Oriented Usage
69
+
70
+ ```python
71
+ validator = CnpjValidator()
72
+ cnpj = '98765432000198'
73
+
74
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
75
+
76
+ cnpj = '98.765.432/0001-98'
77
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
78
+
79
+ cnpj = '98765432000199'
80
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Invalid'
81
+ ```
82
+
83
+ ### Functional programming
84
+
85
+ The helper function `cnpj_val()` is just a functional abstraction. Internally it creates an instance of `CnpjValidator` and calls the `is_valid()` method right away.
86
+
87
+ ```python
88
+ cnpj = '98765432000198'
89
+
90
+ print('Valid' if cnpj_val(cnpj) else 'Invalid') # returns 'Valid'
91
+
92
+ print('Valid' if cnpj_val('98.765.432/0001-98') else 'Invalid') # returns 'Valid'
93
+
94
+ print('Valid' if cnpj_val('98765432000199') else 'Invalid') # returns 'Invalid'
95
+ ```
96
+
97
+ ### Validation Examples
98
+
99
+ ```python
100
+ # Valid CNPJ numbers
101
+ cnpj_val('98765432000198') # returns True
102
+ cnpj_val('98.765.432/0001-98') # returns True
103
+ cnpj_val('03603568000195') # returns True
104
+
105
+ # Invalid CNPJ numbers
106
+ cnpj_val('98765432000199') # returns False
107
+ cnpj_val('12345678901234') # returns False
108
+ cnpj_val('00000000000000') # returns False
109
+ cnpj_val('11111111111111') # returns False
110
+ cnpj_val('123') # returns False (too short)
111
+ cnpj_val('') # returns False (empty)
112
+ ```
113
+
114
+ ## Features
115
+
116
+ - ✅ **Format Agnostic**: Accepts CNPJ with or without formatting (dots, slashes, dashes)
117
+ - ✅ **Strict Validation**: Validates both check digits according to Brazilian CNPJ algorithm
118
+ - ✅ **Type Safety**: Built with Python 3.10+ type hints
119
+ - ✅ **Lightweight**: Minimal dependencies, only requires `cnpj-gen` for check digit calculation
120
+ - ✅ **Dual API**: Both object-oriented and functional programming styles supported
121
+
122
+ ## API Reference
123
+
124
+ ### CnpjValidator Class
125
+
126
+ #### `is_valid(cnpj_string: str) -> bool`
127
+
128
+ Validates a CNPJ string and returns `True` if valid, `False` otherwise.
129
+
130
+ **Parameters:**
131
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
132
+
133
+ **Returns:**
134
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
135
+
136
+ ### cnpj_val() Function
137
+
138
+ #### `cnpj_val(cnpj_string: str) -> bool`
139
+
140
+ Functional wrapper around `CnpjValidator.is_valid()`.
141
+
142
+ **Parameters:**
143
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
144
+
145
+ **Returns:**
146
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
147
+
148
+ ## Validation Algorithm
149
+
150
+ The package validates CNPJ using the official Brazilian algorithm:
151
+
152
+ 1. **Length Check**: Ensures the CNPJ has exactly 14 digits
153
+ 2. **First Check Digit**: Calculates and validates the 13th digit
154
+ 3. **Second Check Digit**: Calculates and validates the 14th digit
155
+ 4. **Format Tolerance**: Automatically strips non-numeric characters before validation
156
+
157
+ ## Error Handling
158
+
159
+ The validator is designed to be forgiving with input format but strict with validation:
160
+
161
+ - Invalid formats (too short, too long) return `False`
162
+ - Invalid check digits return `False`
163
+ - Empty strings return `False`
164
+ - Non-numeric strings (after stripping formatting) return `False`
165
+
166
+ ## Dependencies
167
+
168
+ - **Python**: >= 3.10
169
+ - **cnpj-gen**: >= 1.0.0 (for check digit calculation)
170
+
171
+ ## Contribution & Support
172
+
173
+ We welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-py/blob/main/CONTRIBUTING.md) for details. But if you find this project helpful, please consider:
174
+
175
+ - ⭐ Starring the repository
176
+ - 🤝 Contributing to the codebase
177
+ - 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-py/issues)
178
+ - 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-py/issues)
179
+
180
+ ## License
181
+
182
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE) file for details.
183
+
184
+ ## Changelog
185
+
186
+ See [CHANGELOG](https://github.com/LacusSolutions/br-utils-py/blob/main/packages/cnpj-val/CHANGELOG.md) for a list of changes and version history.
187
+
188
+ ---
189
+
190
+ Made with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)
@@ -0,0 +1,158 @@
1
+ ![cnpj-val for Python](https://github.com/user-attachments/assets/798de57c-445e-49f0-ba50-6fd72f12d8e4)
2
+
3
+ [![PyPI Version](https://img.shields.io/pypi/v/cnpj-val)](https://pypi.org/project/cnpj-val)
4
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/cnpj-val)](https://pypi.org/project/cnpj-val)
5
+ [![Python Version](https://img.shields.io/pypi/pyversions/cnpj-val)](https://www.python.org/)
6
+ [![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-py/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-py/actions)
7
+ [![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py)
8
+ [![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE)
9
+
10
+ Utility function/class to validate CNPJ (Brazilian employer ID).
11
+
12
+ ## Python Support
13
+
14
+ | ![Python 3.10](https://img.shields.io/badge/Python-3.10-3776AB?logo=python&logoColor=white) | ![Python 3.11](https://img.shields.io/badge/Python-3.11-3776AB?logo=python&logoColor=white) | ![Python 3.12](https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white) | ![Python 3.13](https://img.shields.io/badge/Python-3.13-3776AB?logo=python&logoColor=white) | ![Python 3.14](https://img.shields.io/badge/Python-3.14-3776AB?logo=python&logoColor=white) |
15
+ |--- | --- | --- | --- | --- |
16
+ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ $ pip install cnpj-val
22
+ ```
23
+
24
+ ## Import
25
+
26
+ ```python
27
+ # Using class-based resource
28
+ from cnpj_val import CnpjValidator
29
+
30
+ # Or using function-based one
31
+ from cnpj_val import cnpj_val
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### Object-Oriented Usage
37
+
38
+ ```python
39
+ validator = CnpjValidator()
40
+ cnpj = '98765432000198'
41
+
42
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
43
+
44
+ cnpj = '98.765.432/0001-98'
45
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
46
+
47
+ cnpj = '98765432000199'
48
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Invalid'
49
+ ```
50
+
51
+ ### Functional programming
52
+
53
+ The helper function `cnpj_val()` is just a functional abstraction. Internally it creates an instance of `CnpjValidator` and calls the `is_valid()` method right away.
54
+
55
+ ```python
56
+ cnpj = '98765432000198'
57
+
58
+ print('Valid' if cnpj_val(cnpj) else 'Invalid') # returns 'Valid'
59
+
60
+ print('Valid' if cnpj_val('98.765.432/0001-98') else 'Invalid') # returns 'Valid'
61
+
62
+ print('Valid' if cnpj_val('98765432000199') else 'Invalid') # returns 'Invalid'
63
+ ```
64
+
65
+ ### Validation Examples
66
+
67
+ ```python
68
+ # Valid CNPJ numbers
69
+ cnpj_val('98765432000198') # returns True
70
+ cnpj_val('98.765.432/0001-98') # returns True
71
+ cnpj_val('03603568000195') # returns True
72
+
73
+ # Invalid CNPJ numbers
74
+ cnpj_val('98765432000199') # returns False
75
+ cnpj_val('12345678901234') # returns False
76
+ cnpj_val('00000000000000') # returns False
77
+ cnpj_val('11111111111111') # returns False
78
+ cnpj_val('123') # returns False (too short)
79
+ cnpj_val('') # returns False (empty)
80
+ ```
81
+
82
+ ## Features
83
+
84
+ - ✅ **Format Agnostic**: Accepts CNPJ with or without formatting (dots, slashes, dashes)
85
+ - ✅ **Strict Validation**: Validates both check digits according to Brazilian CNPJ algorithm
86
+ - ✅ **Type Safety**: Built with Python 3.10+ type hints
87
+ - ✅ **Lightweight**: Minimal dependencies, only requires `cnpj-gen` for check digit calculation
88
+ - ✅ **Dual API**: Both object-oriented and functional programming styles supported
89
+
90
+ ## API Reference
91
+
92
+ ### CnpjValidator Class
93
+
94
+ #### `is_valid(cnpj_string: str) -> bool`
95
+
96
+ Validates a CNPJ string and returns `True` if valid, `False` otherwise.
97
+
98
+ **Parameters:**
99
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
100
+
101
+ **Returns:**
102
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
103
+
104
+ ### cnpj_val() Function
105
+
106
+ #### `cnpj_val(cnpj_string: str) -> bool`
107
+
108
+ Functional wrapper around `CnpjValidator.is_valid()`.
109
+
110
+ **Parameters:**
111
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
112
+
113
+ **Returns:**
114
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
115
+
116
+ ## Validation Algorithm
117
+
118
+ The package validates CNPJ using the official Brazilian algorithm:
119
+
120
+ 1. **Length Check**: Ensures the CNPJ has exactly 14 digits
121
+ 2. **First Check Digit**: Calculates and validates the 13th digit
122
+ 3. **Second Check Digit**: Calculates and validates the 14th digit
123
+ 4. **Format Tolerance**: Automatically strips non-numeric characters before validation
124
+
125
+ ## Error Handling
126
+
127
+ The validator is designed to be forgiving with input format but strict with validation:
128
+
129
+ - Invalid formats (too short, too long) return `False`
130
+ - Invalid check digits return `False`
131
+ - Empty strings return `False`
132
+ - Non-numeric strings (after stripping formatting) return `False`
133
+
134
+ ## Dependencies
135
+
136
+ - **Python**: >= 3.10
137
+ - **cnpj-gen**: >= 1.0.0 (for check digit calculation)
138
+
139
+ ## Contribution & Support
140
+
141
+ We welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-py/blob/main/CONTRIBUTING.md) for details. But if you find this project helpful, please consider:
142
+
143
+ - ⭐ Starring the repository
144
+ - 🤝 Contributing to the codebase
145
+ - 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-py/issues)
146
+ - 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-py/issues)
147
+
148
+ ## License
149
+
150
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE) file for details.
151
+
152
+ ## Changelog
153
+
154
+ See [CHANGELOG](https://github.com/LacusSolutions/br-utils-py/blob/main/packages/cnpj-val/CHANGELOG.md) for a list of changes and version history.
155
+
156
+ ---
157
+
158
+ Made with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)
@@ -0,0 +1,71 @@
1
+ [project]
2
+ name = "cnpj-val"
3
+ dynamic = [ "version" ]
4
+ description = "Utility function to validate CNPJ (Brazilian employer ID)"
5
+ license = "MIT"
6
+ license-files = [ "LICENSE" ]
7
+ keywords = [
8
+ "cnpj",
9
+ "valid",
10
+ "validate",
11
+ "validator",
12
+ "validador",
13
+ "validar",
14
+ "pt-br",
15
+ "br",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Intended Audience :: Developers",
20
+ "Natural Language :: English",
21
+ "Natural Language :: Portuguese (Brazilian)",
22
+ "Operating System :: MacOS :: MacOS X",
23
+ "Operating System :: Microsoft :: Windows",
24
+ "Operating System :: POSIX",
25
+ "Operating System :: Unix",
26
+ "Programming Language :: Python :: 3 :: Only",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Programming Language :: Python :: 3.14",
32
+ "Topic :: Software Development :: Libraries",
33
+ "Topic :: Utilities",
34
+ ]
35
+ requires-python = ">=3.10"
36
+ dependencies = [
37
+ "cnpj-cd>=1.0.0",
38
+ ]
39
+
40
+ [[project.authors]]
41
+ name = "Julio L. Muller"
42
+
43
+ [project.readme]
44
+ file = "README.md"
45
+ content-type = "text/markdown"
46
+
47
+ [project.urls]
48
+ Homepage = "https://cnpj-utils.vercel.app/"
49
+ Source = "https://github.com/LacusSolutions/br-utils-py"
50
+ Tracker = "https://github.com/LacusSolutions/br-utils-py/issues"
51
+
52
+ [build-system]
53
+ requires = [ "setuptools>=80.9.0", "wheel" ]
54
+ build-backend = "setuptools.build_meta"
55
+
56
+ [tool.setuptools.dynamic.version]
57
+ attr = "cnpj_val.__version__"
58
+
59
+ [tool.setuptools.packages.find]
60
+ where = [ "src/" ]
61
+
62
+ [tool.pytest.ini_options]
63
+ minversion = "8.0"
64
+ testpaths = [ "tests/" ]
65
+ python_files = [ "*_test.py" ]
66
+ python_functions = [ "test_*" ]
67
+ python_classes = [ "*Test" ]
68
+
69
+ [tool.coverage.run]
70
+ source = [ "src/" ]
71
+ omit = [ "tests/*" ]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,6 @@
1
+ from .cnpj_val import cnpj_val
2
+ from .cnpj_validator import CnpjValidator
3
+
4
+ __all__ = ["CnpjValidator", "cnpj_val"]
5
+
6
+ __version__ = "1.0.0"
@@ -0,0 +1,6 @@
1
+ from .cnpj_validator import CnpjValidator
2
+
3
+
4
+ def cnpj_val(cnpj_string: str) -> bool:
5
+ """Validates a CNPJ string."""
6
+ return CnpjValidator().is_valid(cnpj_string)
@@ -0,0 +1,24 @@
1
+ from cnpj_cd import CnpjCheckDigits
2
+
3
+ CNPJ_LENGTH = 14
4
+
5
+
6
+ class CnpjValidator:
7
+ """Class to validate a CNPJ string."""
8
+
9
+ def is_valid(self, cnpj_string: str) -> bool:
10
+ """Executes the CNPJ validation, returning a boolean value."""
11
+ cnpj_str_digits = "".join(filter(str.isdigit, cnpj_string))
12
+
13
+ if len(cnpj_str_digits) != CNPJ_LENGTH:
14
+ return False
15
+
16
+ cnpj_num_digits = [int(digit) for digit in cnpj_str_digits]
17
+ cnpj_first_check_digit = cnpj_num_digits[-2]
18
+ cnpj_second_check_digit = cnpj_num_digits[-1]
19
+ cnpj_check_digits = CnpjCheckDigits(cnpj_num_digits)
20
+
21
+ return (
22
+ cnpj_first_check_digit == cnpj_check_digits.first_digit
23
+ and cnpj_second_check_digit == cnpj_check_digits.second_digit
24
+ )
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.4
2
+ Name: cnpj-val
3
+ Version: 1.0.0
4
+ Summary: Utility function to validate CNPJ (Brazilian employer ID)
5
+ Author: Julio L. Muller
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://cnpj-utils.vercel.app/
8
+ Project-URL: Source, https://github.com/LacusSolutions/br-utils-py
9
+ Project-URL: Tracker, https://github.com/LacusSolutions/br-utils-py/issues
10
+ Keywords: cnpj,valid,validate,validator,validador,validar,pt-br,br
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Natural Language :: English
14
+ Classifier: Natural Language :: Portuguese (Brazilian)
15
+ Classifier: Operating System :: MacOS :: MacOS X
16
+ Classifier: Operating System :: Microsoft :: Windows
17
+ Classifier: Operating System :: POSIX
18
+ Classifier: Operating System :: Unix
19
+ Classifier: Programming Language :: Python :: 3 :: Only
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Software Development :: Libraries
26
+ Classifier: Topic :: Utilities
27
+ Requires-Python: >=3.10
28
+ Description-Content-Type: text/markdown
29
+ License-File: LICENSE
30
+ Requires-Dist: cnpj-cd>=1.0.0
31
+ Dynamic: license-file
32
+
33
+ ![cnpj-val for Python](https://github.com/user-attachments/assets/798de57c-445e-49f0-ba50-6fd72f12d8e4)
34
+
35
+ [![PyPI Version](https://img.shields.io/pypi/v/cnpj-val)](https://pypi.org/project/cnpj-val)
36
+ [![PyPI Downloads](https://img.shields.io/pypi/dm/cnpj-val)](https://pypi.org/project/cnpj-val)
37
+ [![Python Version](https://img.shields.io/pypi/pyversions/cnpj-val)](https://www.python.org/)
38
+ [![Test Status](https://img.shields.io/github/actions/workflow/status/LacusSolutions/br-utils-py/ci.yml?label=ci/cd)](https://github.com/LacusSolutions/br-utils-py/actions)
39
+ [![Last Update Date](https://img.shields.io/github/last-commit/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py)
40
+ [![Project License](https://img.shields.io/github/license/LacusSolutions/br-utils-py)](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE)
41
+
42
+ Utility function/class to validate CNPJ (Brazilian employer ID).
43
+
44
+ ## Python Support
45
+
46
+ | ![Python 3.10](https://img.shields.io/badge/Python-3.10-3776AB?logo=python&logoColor=white) | ![Python 3.11](https://img.shields.io/badge/Python-3.11-3776AB?logo=python&logoColor=white) | ![Python 3.12](https://img.shields.io/badge/Python-3.12-3776AB?logo=python&logoColor=white) | ![Python 3.13](https://img.shields.io/badge/Python-3.13-3776AB?logo=python&logoColor=white) | ![Python 3.14](https://img.shields.io/badge/Python-3.14-3776AB?logo=python&logoColor=white) |
47
+ |--- | --- | --- | --- | --- |
48
+ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ | Passing ✔ |
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ $ pip install cnpj-val
54
+ ```
55
+
56
+ ## Import
57
+
58
+ ```python
59
+ # Using class-based resource
60
+ from cnpj_val import CnpjValidator
61
+
62
+ # Or using function-based one
63
+ from cnpj_val import cnpj_val
64
+ ```
65
+
66
+ ## Usage
67
+
68
+ ### Object-Oriented Usage
69
+
70
+ ```python
71
+ validator = CnpjValidator()
72
+ cnpj = '98765432000198'
73
+
74
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
75
+
76
+ cnpj = '98.765.432/0001-98'
77
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Valid'
78
+
79
+ cnpj = '98765432000199'
80
+ print('Valid' if validator.is_valid(cnpj) else 'Invalid') # returns 'Invalid'
81
+ ```
82
+
83
+ ### Functional programming
84
+
85
+ The helper function `cnpj_val()` is just a functional abstraction. Internally it creates an instance of `CnpjValidator` and calls the `is_valid()` method right away.
86
+
87
+ ```python
88
+ cnpj = '98765432000198'
89
+
90
+ print('Valid' if cnpj_val(cnpj) else 'Invalid') # returns 'Valid'
91
+
92
+ print('Valid' if cnpj_val('98.765.432/0001-98') else 'Invalid') # returns 'Valid'
93
+
94
+ print('Valid' if cnpj_val('98765432000199') else 'Invalid') # returns 'Invalid'
95
+ ```
96
+
97
+ ### Validation Examples
98
+
99
+ ```python
100
+ # Valid CNPJ numbers
101
+ cnpj_val('98765432000198') # returns True
102
+ cnpj_val('98.765.432/0001-98') # returns True
103
+ cnpj_val('03603568000195') # returns True
104
+
105
+ # Invalid CNPJ numbers
106
+ cnpj_val('98765432000199') # returns False
107
+ cnpj_val('12345678901234') # returns False
108
+ cnpj_val('00000000000000') # returns False
109
+ cnpj_val('11111111111111') # returns False
110
+ cnpj_val('123') # returns False (too short)
111
+ cnpj_val('') # returns False (empty)
112
+ ```
113
+
114
+ ## Features
115
+
116
+ - ✅ **Format Agnostic**: Accepts CNPJ with or without formatting (dots, slashes, dashes)
117
+ - ✅ **Strict Validation**: Validates both check digits according to Brazilian CNPJ algorithm
118
+ - ✅ **Type Safety**: Built with Python 3.10+ type hints
119
+ - ✅ **Lightweight**: Minimal dependencies, only requires `cnpj-gen` for check digit calculation
120
+ - ✅ **Dual API**: Both object-oriented and functional programming styles supported
121
+
122
+ ## API Reference
123
+
124
+ ### CnpjValidator Class
125
+
126
+ #### `is_valid(cnpj_string: str) -> bool`
127
+
128
+ Validates a CNPJ string and returns `True` if valid, `False` otherwise.
129
+
130
+ **Parameters:**
131
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
132
+
133
+ **Returns:**
134
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
135
+
136
+ ### cnpj_val() Function
137
+
138
+ #### `cnpj_val(cnpj_string: str) -> bool`
139
+
140
+ Functional wrapper around `CnpjValidator.is_valid()`.
141
+
142
+ **Parameters:**
143
+ - `cnpj_string` (str): The CNPJ to validate (with or without formatting)
144
+
145
+ **Returns:**
146
+ - `bool`: `True` if the CNPJ is valid, `False` otherwise
147
+
148
+ ## Validation Algorithm
149
+
150
+ The package validates CNPJ using the official Brazilian algorithm:
151
+
152
+ 1. **Length Check**: Ensures the CNPJ has exactly 14 digits
153
+ 2. **First Check Digit**: Calculates and validates the 13th digit
154
+ 3. **Second Check Digit**: Calculates and validates the 14th digit
155
+ 4. **Format Tolerance**: Automatically strips non-numeric characters before validation
156
+
157
+ ## Error Handling
158
+
159
+ The validator is designed to be forgiving with input format but strict with validation:
160
+
161
+ - Invalid formats (too short, too long) return `False`
162
+ - Invalid check digits return `False`
163
+ - Empty strings return `False`
164
+ - Non-numeric strings (after stripping formatting) return `False`
165
+
166
+ ## Dependencies
167
+
168
+ - **Python**: >= 3.10
169
+ - **cnpj-gen**: >= 1.0.0 (for check digit calculation)
170
+
171
+ ## Contribution & Support
172
+
173
+ We welcome contributions! Please see our [Contributing Guidelines](https://github.com/LacusSolutions/br-utils-py/blob/main/CONTRIBUTING.md) for details. But if you find this project helpful, please consider:
174
+
175
+ - ⭐ Starring the repository
176
+ - 🤝 Contributing to the codebase
177
+ - 💡 [Suggesting new features](https://github.com/LacusSolutions/br-utils-py/issues)
178
+ - 🐛 [Reporting bugs](https://github.com/LacusSolutions/br-utils-py/issues)
179
+
180
+ ## License
181
+
182
+ This project is licensed under the MIT License - see the [LICENSE](https://github.com/LacusSolutions/br-utils-py/blob/main/LICENSE) file for details.
183
+
184
+ ## Changelog
185
+
186
+ See [CHANGELOG](https://github.com/LacusSolutions/br-utils-py/blob/main/packages/cnpj-val/CHANGELOG.md) for a list of changes and version history.
187
+
188
+ ---
189
+
190
+ Made with ❤️ by [Lacus Solutions](https://github.com/LacusSolutions)
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/cnpj_val/__init__.py
5
+ src/cnpj_val/cnpj_val.py
6
+ src/cnpj_val/cnpj_validator.py
7
+ src/cnpj_val.egg-info/PKG-INFO
8
+ src/cnpj_val.egg-info/SOURCES.txt
9
+ src/cnpj_val.egg-info/dependency_links.txt
10
+ src/cnpj_val.egg-info/requires.txt
11
+ src/cnpj_val.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ cnpj-cd>=1.0.0
@@ -0,0 +1 @@
1
+ cnpj_val