Skip to main content

This package validate and generate CPF and CNPJ for tests

Project description

c2validator

c2validator is used for validate CPF and CNPJ, and create CPF or CNPJ for tests.

INSTALLING

$ python -m pip install c2validator

CLONING THE REPOSITORY

git clone https://github.com/devguilhermecosta/c2validator.git

HOW USE THIS PACKAGE

Validating CPF or CNPJ

>>> import c2validator as c2
>>>
>>> cpf = c2.validate('725.849.240-21') 
>>> cpf.is_valid()
True

This is semple. If CPF or CNPJ is invalid, the return we will False.

If the value contains letters, symbols or punctuation, a private __clean() method will clean the data before validate.

Returning a clean value

When the CPF or CNPJ is valid, you can use the formatted() method. This method returns the value without symbols, letters or punctuation. But, if you need a formatted data with punctuation, you can use formatted(punctuation=True).

>>> import c2validator as c2
>>> 
>>> cpf = c2.validate('725.849.240-21') 
>>> cpf.is_valid()
True
>>> cpf.formatted()
'72584924021'
>>> cpf.formatted(punctuation=True) 
'725.849.240-21'

Now, if the CPF or CNPJ is invalid, the formatted() method returns invalid CPF or CNPJ.

>>> import c2validator as c2
>>> 
>>> cpf = c2.validate('111.111.111-11')
>>> cpf.is_valid()
False
>>> cpf.formatted()
'invalid CPF or CNPJ'

Generating CPF and CNPJ

You can use this package for generate CPF and CNPJ to test your code.

Generating and testing CNPJ

>>> import c2validator as c2
>>> 
>>> cnpj = c2.create_cnpj()
>>> cnpj
'89979419564354'
>>> c2.validate(cnpj).is_valid()
True

You can return this CNPJ with punctuation.

>>> import c2validator as c2
>>> 
>>> cnpj = c2.create_cnpj(punctuation=True)
>>> cnpj
'55.487.153/6933-80'
>>> c2.validate(cnpj).is_valid()
True

Generating and testing CPF

>>> import c2validator as c2
>>> 
>>> cpf = c2.create_cpf()
>>> cpf
'05170816367'
>>> c2.validate(cpf).is_valid()
True

You can return this CPF with punctuation.

>>> import c2validator as c2
>>> 
>>> cpf = c2.create_cpf(punctuation=True)
>>> cpf
'415.684.161-80'
>>> c2.validate(cpf).is_valid()
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

c2validator-1.0.2.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

c2validator-1.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file c2validator-1.0.2.tar.gz.

File metadata

  • Download URL: c2validator-1.0.2.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for c2validator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 c4bc8adc7899bb2ebcfa651ef3c2ff50c0b265ff53021a100e125d29474a36a9
MD5 5e19e24dfa2e212f44990922071db737
BLAKE2b-256 ee127fa5d33885b98826f0b57c464df773a0c1d78de173d9b49a10a8755e8c62

See more details on using hashes here.

File details

Details for the file c2validator-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: c2validator-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for c2validator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 925fc13abaff3ef1045a84a0016ddab452ee8e21e02856523768ee34d5aa8fa3
MD5 0b3a61f06cd8b400908c07a2b7fa9b04
BLAKE2b-256 588c8ede04699f0ef43d3088aefde46d8ac781becb88821deaf47831d799d70b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page