Skip to main content

Library for validation and formatting of Brazilian data

Project description

Validator Brazil

Python library for validation and formatting of Brazilian data such as:

  • CPF
  • CNPJ
  • Vehicle license plates.
  • Postal codes (CEP)
  • Phone numbers # TODO

Installation

pip install br-eval

Usage example

CPF

from br_eval.cep import validate_cep, format_cep, generate_cep

# Validate CEP
try:
    validate_cep('01001-000')
    print("CEP is valid.")
except Exception as e:
    print(f"Invalid CEP: {e}")

# Validate CEP with extra characters
try:
    validate_cep('94445abcx162')
    print("CEP is valid.")
except Exception as e:
    print(f"Invalid CEP: {e}")  # This will now raise an exception

Note: The CEP validator requires that the input contains only numeric characters. If the CEP contains letters or other invalid characters, it will raise an InvalidCharacterCEPError.

CNPJ example

from validator_brazil import validate_cnpj, format_cnpj

# Validate CNPJ
try:
    validate_cnpj('13.347.016/0001-17')
    print("CNPJ is valid.")
except Exception as e:
    print(f"Invalid CNPJ: {e}")

# Format CNPJ
formatted_cnpj = format_cnpj('13347016000117')
print(f"Formatted CNPJ: {formatted_cnpj}")

Plate example

from validator_brazil import validate_plate, format_plate

# Validate Plate
try:
    plate_type = validate_plate('ABC1234')
    print(f"Plate is valid. Type: {plate_type}")
except Exception as e:
    print(f"Invalid plate: {e}")

# Validate Mercosul Car Plate
try:
    plate_type = validate_plate('ABC1D23')
    print(f"Plate is valid. Type: {plate_type}")
except Exception as e:
    print(f"Invalid plate: {e}")

# Validate Mercosul Motorcycle Plate
try:
    plate_type = validate_plate('ABC12D3')
    print(f"Plate is valid. Type: {plate_type}")
except Exception as e:
    print(f"Invalid plate: {e}")

# Format Plate
formatted_plate = format_plate('ABC1D23')
print(f"Formatted Plate: {formatted_plate}")  # Output: 'ABC-1D23'

CEP example

from br_eval.cep import validate_cep, format_cep, generate_cep

# Validate CEP
try:
    validate_cep('01001-000')
    print("CEP is valid.")
except Exception as e:
    print(f"Invalid CEP: {e}")

# Format CEP
formatted_cep = format_cep('01001000')
print(f"Formatted CEP: {formatted_cep}")

# Generate CEP
cep_generated = generate_cep(formatted=True)
print(f"Generated CEP: {cep_generated}")

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

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

IMPORTANT NOTICE

Disclaimer 1: The CPF and CNPJ generator functions provided by this library are intended solely for development and testing purposes. The generated numbers do not correspond to real individuals or companies and should not be used in production systems, official registrations, or for any illegal or fraudulent activities. Misuse of these functions is the sole responsibility of the user.

Disclaimer 2: The vehicle plate generator functions provided in this library are intended solely for development and testing purposes. The generated plates do not correspond to real vehicles and should not be used in production systems, official documents, registrations, or any activities involving real-world entities. Misuse of these functions is the sole responsibility of the user.

Disclaimer 3: The CEP generator function provided in this library is intended solely for development and testing purposes. The generated CEPs do not necessarily correspond to real addresses and should not be used in production systems, official documents, registrations, or any activities involving real-world entities. Misuse of this function is the sole responsibility of the user.

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

br-eval-0.5.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

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

br_eval-0.5.3-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file br-eval-0.5.3.tar.gz.

File metadata

  • Download URL: br-eval-0.5.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for br-eval-0.5.3.tar.gz
Algorithm Hash digest
SHA256 54bfc9d8ab88768530a79c7bed445443ebed46d52dedb4e4d441a460171bb86b
MD5 ae3f566d2031380d6a112ce05478d87f
BLAKE2b-256 6e8e82bddd7be63d02a3e341375659cb8896fa01ded68b3b73b406216fbc8216

See more details on using hashes here.

File details

Details for the file br_eval-0.5.3-py3-none-any.whl.

File metadata

  • Download URL: br_eval-0.5.3-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.13

File hashes

Hashes for br_eval-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 631c58005dbf9027f02ef81d2645c16f0d683de7664c5833dd51682486f092d7
MD5 81c65fd55626f2e1967187ddf3727d6e
BLAKE2b-256 4dac940bdd071ea03eafea5b058d66c3f7be8e4309f9f980fa02682a2d495117

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