Pycpfcnpj
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
Have fun!
In portuguese:
Módulo python para validar números de CPF e CNPJ.
Como instalar:
Agora você pode instalar o pycpfcnpj usando o pip!\m/
uv add pycpfcnpj
Projetos relacionados
Como usar
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
Simples assim! Você também pode usar os pacotes internos que tratam em separado os números de CPF e CNPJ. O módulo 'cpfcnpj' é um tipo de interface para os módulos mais específicos e se encarrega de saber quando você está passando um CPF ou um CNPJ.
Fique à vontade em contribuir com o projeto ou da maneira que quiser. Ah, sim: pure python (sem dependências ;) ).
Ah, e antes que eu me esqueça, você pode gerar, só e apenas somente para fins de teste, um número de CPF ou CNPJ utilizando o módulo 'gen'. Fácil como acima:
from pycpfcnpj import gen
gen.cpf()
gen.cnpj()
Expected output:
>>> 49384063495
>>> 20788274885880
E você também pode gerar CPF ou CNPJ com pontuação :)
from pycpfcnpj import gen
gen.cpf_with_punctuation()
gen.cnpj_with_punctuation()
Expected output:
>>> 048.891.866-97
>>> 63.212.638/0361-35
Divirta-se!
Changelog
1.9
- Added official support for alphanumeric CNPJ (2026+)
1.8
- Dropped travis and python versions under 3.8
1.7.2
- Use poetry to handle dev/test dependencies, building and publishing
1.7.1
- Fix for cpf/cnpjs containing special characters.
1.7.0
- Invalidates cpf/cnpjs containing non-numeric characters and spaces.
1.6.0
- Remove python 2.7 support
- Add python 3.8 support
1.1
- Handles CPF and CNPJ numbers with punctuation marks.
1.2
- Use
sysrather thansixto check python's version and keeps this project 100% free of dependencies.
1.3
- Generate CPF and CNPJ numbers with punctuation marks.
1.4
- Adding support to unicode values.
1.5
- Better CPF and CNPJ generation
1.5.1
- Use regex to remove punctuation
Log de mudanças
1.9
- Suporte oficial ao CNPJ alfanumérico (2026+)
1.8
- Travis fora e versões do Python abaixo de 3.8 não são mais suportadas
1.7.2
- Use Poetry para lidar com dependências de desenvolvimento/teste, construção e publicação
1.7.1
- Correção para cpf/cnpjs que contém caracteres especials.
1.7.0
- Invalida cpf/cnpjs que contém caracteres não numéricos e espaços.
1.6.0
- Remove suporte para python 2.7
- Adiciona suporte para python 3.8
1.1
- Trata números de CPF e CPNJ com sinais de pontuação
1.2
- Uso do
sysem vez dosixpara verificar a versão do Python e evitando o uso de libs terceiras
1.3
- Gera números de CPF e CNPJ com pontuação.
1.4
- Suporte a unicode.
1.5
- Geração de CPF e CNPJ mais eficiente.
1.5.1
- Regex para remover a pontuação.
Metadata
Release files for pycpfcnpj 1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pycpfcnpj-1.9.tar.gz | 4.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pycpfcnpj-1.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.8 kB
Release files / pycpfcnpj-1.9.tar.gz
| Download URL | pycpfcnpj-1.9.tar.gz |
|---|---|
| Size | 4.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ca27abce986b115a2f0db50c5cc691a883937f2678f93ae1ee15c0257f37f54
|
|
BLAKE2b-256 checksum How to use checksums |
1f68e189f6aab7965519203b0fc3ff853c65b15b031609e97990dc00a52386c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / pycpfcnpj-1.9-py3-none-any.whl
| Download URL | pycpfcnpj-1.9-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
311c6dcf396edd24fd1d869b3718944e24f61da14f8d82f5a1df111976affcde
|
|
BLAKE2b-256 checksum How to use checksums |
ba6549af7797bd4a53231a5647d7dab885dabb2e943c66ee10ff49763e39bc55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|