{"id":10333,"library":"validate-docbr","title":"Validate Brazilian Documents","description":"validate-docbr is a Python library designed to validate Brazilian documents such as CPF, CNPJ, CNH, PIS, RENAVAM, and more. It is currently at version 2.0.0 and actively maintained with periodic releases that add new document types and improvements.","status":"active","version":"2.0.0","language":"en","source_language":"en","source_url":"https://github.com/alvarofpp/validate-docbr","tags":["validation","brazilian documents","cpf","cnpj","cnh","pis","renavam","document validation"],"install":[{"cmd":"pip install validate-docbr","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"CPF","correct":"from validate_docbr import CPF"},{"symbol":"CNPJ","correct":"from validate_docbr import CNPJ"},{"symbol":"PIS","correct":"from validate_docbr import PIS"},{"symbol":"RENAVAM","correct":"from validate_docbr import RENAVAM"}],"quickstart":{"code":"from validate_docbr import CPF, CNPJ\n\n# Example CPF validation\ncpf_validator = CPF()\nprint(f\"Is '123.456.789-00' a valid CPF? {cpf_validator.validate('123.456.789-00')}\")\nprint(f\"Is '111.111.111-11' a valid CPF? {cpf_validator.validate('111.111.111-11')}\")\n\n# Example CNPJ validation\ncnpj_validator = CNPJ()\nprint(f\"Is '11.222.333/0001-81' a valid CNPJ? {cnpj_validator.validate('11.222.333/0001-81')}\")\nprint(f\"Is '00.000.000/0000-00' a valid CNPJ? {cnpj_validator.validate('00.000.000/0000-00')}\")\n\n# Check if a document is formatted correctly\nprint(f\"Is '123.456.789-00' formatted as a CPF? {cpf_validator.is_formatted('123.456.789-00')}\")\nprint(f\"Is '12345678900' formatted as a CPF? {cpf_validator.is_formatted('12345678900')}\")","lang":"python","description":"This quickstart demonstrates how to import and use the CPF and CNPJ validators. It shows how to validate documents with and without formatting, and how to check if a document string adheres to the standard formatting."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or higher, or pin your `validate-docbr` dependency to `<2.0.0` for Python 3.9 environments.","message":"Version 2.0.0 and above require Python 3.10 or newer. Users on older Python versions (e.g., 3.9) will encounter installation errors.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always check the boolean result of `validator.validate(doc)` before proceeding with operations that assume a valid document.","message":"The `validate` method returns `True` or `False` directly and does not raise exceptions for invalid inputs. Ensure your code explicitly checks the boolean return value.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `validator.validate(doc)` for general validity checks, and `validator.is_formatted(doc)` only when you need to specifically verify the string format.","message":"The library's validation methods generally handle documents with or without standard formatting (e.g., '123.456.789-00' vs '12345678900'). However, methods like `is_formatted` are strict about the exact formatting.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install validate-docbr` to install the package.","cause":"The package 'validate-docbr' is not installed or the Python environment is not correctly configured.","error":"ModuleNotFoundError: No module named 'validate_docbr'"},{"fix":"Ensure you import the specific validator class: `from validate_docbr import CPF`.","cause":"You are trying to access a specific document validator (e.g., CPF) directly from the top-level `validate_docbr` module without importing it explicitly.","error":"AttributeError: module 'validate_docbr' has no attribute 'CPF'"},{"fix":"Always ensure the document string passed to `validate()` or `is_formatted()` is a non-None string, even if empty. Example: `cpf_validator.validate(document or '')`.","cause":"You are passing `None` as the document value to a validation method which expects a string.","error":"TypeError: argument of type 'NoneType' is not iterable"}]}