Python module for brazilian register numbers for persons (CPF) and companies (CNPJ) and mask generator to string or int CPF/CNPJ.
Project description
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. ;)
Python 3 ready!
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).
- Library forked from pycpfcnpj
- The main purpose of the fork was to add mask for cpf or cnpj from int or string.
How to install
Now you can install this module with pip! Yeah! :D
pip install cpf-cnpj-validate
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'
print cpfcnpj.validate(cpf_number)
print cpfcnpj.validate(masked_cpf_number)
print cpfcnpj.validate(cnpj_number)
print cpfcnpj.validate(masked_cnpj_number)
Expected output:
>>>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
And you also 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
And you also can format a cpf or cnpj number with valid mask
from pycpfcnpj import mask
only_number_cnpj: str = "63212638036135"
with_mask_cnpj: str = mask.mask_cpf_cnpj(only_number_cnpj)
only_number_cpf: int = 4889186697
with_mask_cpf: str = mask.mask_cpf_cnpj(only_number_cpf)
print(with_mask_cnpj)
print(with_mask_cpf)
Expected output:
>>> 63.212.638/0361-35
>>> 048.891.866-97
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/
pip install cpf-cnpj-validate
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'
print cpfcnpj.validate(cpf_number)
print cpfcnpj.validate(cpf_number_mascara)
print cpfcnpj.validate(cnpj_number)
print cpfcnpj.validate(cnpj_number_mascara)
Expected output:
>>>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 especificos 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.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
sys
rather thansix
to 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.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
sys
em vez dosix
para 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cpf_cnpj_validate-1.4.tar.gz
.
File metadata
- Download URL: cpf_cnpj_validate-1.4.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 611dfc08bf3c1c040ce47294d1c04e77e12b6b2d4e1029cc7a5ee2d2079c0ece |
|
MD5 | 90c535f2d49b86270f54165086ca79e3 |
|
BLAKE2b-256 | 991a77fc2502bba9153c557dd93d04f465d33acbfb350bad2952721eb2f04cc9 |
File details
Details for the file cpf_cnpj_validate-1.4-py3-none-any.whl
.
File metadata
- Download URL: cpf_cnpj_validate-1.4-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e30e125a1c4d4749b80e7f87ea192ccbcfbafb6c85b27833ecffc41da9df47ff |
|
MD5 | eef0e7aaf9b94a3999390b27169ec134 |
|
BLAKE2b-256 | 2c2a82dd91fc434db68c716856e7f43a2f6ccb5213f6918d9c01f2e6db86e8c0 |