Python module for brazilian register numbers for persons (CPF) and companies (CNPJ).
Maintained. Last release 10 months ago. Weaker on release cadence.
pip install pycpfcnpjPycpfcnpj
Description
Python module for brazilian register numbers for persons (CPF) and companies (CNPJ). If want this validation in your web application, please check my tiny web component that does exactly that. ;)
Related projects
- Pycnpj-crawler: Python module that crawls data for a given CNPJ on the government website of each state (please check the supported states).
How to install
Now you can install this module with pip! Yeah! :D
uv add pycpfcnpj
Quick Start
To use pycpfcnpj is simples like as every python module should be!
from pycpfcnpj import cpfcnpj
cpf_number = '11144477735'
masked_cpf_number = '111.444.777-35'
cnpj_number = '11444777000161'
masked_cnpj_number = '11.444.777/0001-61'
alphanumeric_cnpj = '12ABC34501DE35'
print(cpfcnpj.validate(cpf_number))
print(cpfcnpj.validate(masked_cpf_number))
print(cpfcnpj.validate(cnpj_number))
print(cpfcnpj.validate(masked_cnpj_number))
print(cpfcnpj.validate(alphanumeric_cnpj))
Expected output:
>>>True
>>>True
>>>True
>>>True
>>>True
Simple like that. =)
You can use, as well, the cpf and cnpj packages. The cpfcnpj is like a Facade to the other modules. Make yourself confortable.
Oh, fork and contribute either if you want to.
Obs.: There is no dependencies.
Oh, and before I forget, you can generate, only and only for test purposes, a CPF or CNPJ number using the 'gen' module. Easy like above:
from pycpfcnpj import gen
gen.cpf()
gen.cnpj()
Expected output:
>>> 49384063495
>>> 20788274885880
Also, you can generate CPF or CǸPJ with punctuation marks. :)
from pycpfcnpj import gen
gen.cpf_with_punctuation()
gen.cnpj_with_punctuation()
Expected output:
>>> 048.891.866-97
>>> 63.212.638/0361-35