Skip to main content

Validators Brasilian documents

Project description

Validator Docs

A Python package to validate and format Brazilian CPF and CNPJ documents.

Features

  • CPF Validation: Check if a given CPF is valid by verifying its check digits.
  • CNPJ Validation: Validate CNPJ numbers by calculating their check digits.
  • CPF and CNPJ Formatting: Format CPF and CNPJ numbers to standard Brazilian formats.

Installation

You can install the package via pip:

pip install validator_docs

Usage

Import the package

from validator_docs import validar_doc, formatar_cpf, formatar_cnpj

Validate CPF and CNPJ

To validate a CPF or CNPJ, simply pass the document number (either as a string or integer) to the validar_doc function. The function will raise an exception if the document is invalid.

# Validate CPF
cpf = "123.456.789-09"
try:
    valid_cpf = validar_doc(cpf)
    print(f"CPF {valid_cpf} is valid.")
except ValueError as e:
    print(e)

# Validate CNPJ
cnpj = "12.345.678/0001-95"
try:
    valid_cnpj = validar_doc(cnpj)
    print(f"CNPJ {valid_cnpj} is valid.")
except ValueError as e:
    print(e)

Format CPF and CNPJ

You can format valid CPF and CNPJ numbers using the provided formatar_cpf and formatar_cnpj functions:

cpf = "12345678909"
formatted_cpf = formatar_cpf(cpf)
print(f"Formatted CPF: {formatted_cpf}")  # Output: 123.456.789-09

cnpj = "12345678000195"
formatted_cnpj = formatar_cnpj(cnpj)
print(f"Formatted CNPJ: {formatted_cnpj}")  # Output: 12.345.678/0001-95

Full Example

Here's a full example of how to use validator_docs to validate and format both CPF and CNPJ numbers:

from validator_docs import validar_doc

cpf = "123.456.789-09"
cnpj = "12.345.678/0001-95"

# Validate CPF and CNPJ
try:
    valid_cpf = validar_doc(cpf, formatado=True)
    print(f"Valid CPF: {valid_cpf}")
    
    valid_cnpj = validar_doc(cnpj, formatado=True)
    print(f"Valid CNPJ: {valid_cnpj}")
    
except ValueError as e:
    print(e)

Roadmap

  • Adding support for other document types.
  • Improving performance for batch document validations.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

validador_docs-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

validador_docs-0.0.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file validador_docs-0.0.1.tar.gz.

File metadata

  • Download URL: validador_docs-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for validador_docs-0.0.1.tar.gz
Algorithm Hash digest
SHA256 86c09d6168c1b3ac6a0de2ae35d54e980e8c596abf34f397a54a83fbde313ff5
MD5 dcde624838ffed9d32aeac3dd4fd7fef
BLAKE2b-256 2f2a30a2413a15a4c2de52334ad8098b50a9da91256f596face6dfdf6a02cf3b

See more details on using hashes here.

File details

Details for the file validador_docs-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: validador_docs-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for validador_docs-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5c81e296391a4a32ff3a999f05bd309c041394f793e9be5680f894f88ab68834
MD5 320dcd83dfe35cc52f7e9df1ed5e9f02
BLAKE2b-256 87ced69b671b8e2f2c28b2054180548b9702fe25c2092a9ba529fc87dff08a85

See more details on using hashes here.

Supported by

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