stdnum.br.cnpj

CNPJ (Cadastro Nacional da Pessoa Jurídica, Brazilian company identifier).

Numbers from the national register of legal entities have 14 digits. The first 8 digits identify the company, the following 4 digits identify a business unit and the last 2 digits are check digits.

>>> validate('16.727.230/0001-97')
'16727230000197'
>>> validate('16.727.230.0001-98')
Traceback (most recent call last):
    ...
InvalidChecksum: ...
>>> validate('16.727.230/0001=97')  # invalid delimiter
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> format('16727230000197')
'16.727.230/0001-97'
stdnum.br.cnpj.calc_check_digits(number: str) str

Calculate the check digits for the number.

stdnum.br.cnpj.compact(number: str) str

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.br.cnpj.format(number: str) str

Reformat the number to the standard presentation format.

stdnum.br.cnpj.is_valid(number: str) bool

Check if the number is a valid CNPJ.

stdnum.br.cnpj.validate(number: str) str

Check if the number is a valid CNPJ. This checks the length and whether the check digits are correct.