brazilian_ids.functions.company package¶
Submodules¶
brazilian_ids.functions.company.cnpj module¶
Functions to handle Brazilian company identifiers (CNPJ).
CNPJ means “Cadastro Nacional da Pessoa Jurídica” in Brazilian Portuguese.
See also a the Wikipedia entry about it for more details.
- class brazilian_ids.functions.company.cnpj.CNPJ(cnpj, firm, establishment, first_digit, second_digit)¶
Bases:
objectRepresentation of a CNPJ.
The attributes are as follow:
cnpj: the formatted CNPJ. Also returned from
__str__.firm: the number of the firm/company, as registered at Receita Federal.
establishment: the sequence number
first_digit: the first verification digit
second_digit: the second verification digit
Should be obtained from the
parsefunction.- Parameters:
cnpj (str)
firm (int)
establishment (int)
first_digit (int)
second_digit (int)
- cnpj: str¶
- establishment: int¶
- firm: int¶
- first_digit: int¶
- second_digit: int¶
- exception brazilian_ids.functions.company.cnpj.InvalidCnpjError(cnpj)¶
Bases:
InvalidCnpjTypeMixin,InvalidIdError- Parameters:
cnpj (str)
- Return type:
None
- exception brazilian_ids.functions.company.cnpj.InvalidCnpjLengthError(cnpj, expected_digits=12)¶
Bases:
InvalidCnpjTypeMixin,InvalidIdLengthError- Parameters:
cnpj (str)
expected_digits (int)
- Return type:
None
- class brazilian_ids.functions.company.cnpj.InvalidCnpjTypeMixin¶
Bases:
objectMixin class for CNPJ errors.
- id_type()¶
- brazilian_ids.functions.company.cnpj.format(cnpj)¶
Applies typical 00.000.000/0000-00 formatting to CNPJ.
- Parameters:
cnpj (str)
- Return type:
str
- brazilian_ids.functions.company.cnpj.from_firm_id(firm, establishment='0001', formatted=False)¶
Takes first 8 digits of a CNPJ (firm identifier) and builds a valid, complete CNPJ by appending an establishment identifier and calculating necessary check digits.
- Parameters:
firm (str)
establishment (str)
formatted (bool)
- Return type:
str
- brazilian_ids.functions.company.cnpj.is_valid(cnpj, autopad=True)¶
Check whether CNPJ is valid. Optionally pad if is too short.
- Parameters:
cnpj (str)
autopad (bool)
- Return type:
bool
- brazilian_ids.functions.company.cnpj.pad(cnpj, validate_after=False)¶
Takes a CNPJ and pads it with leading zeros.
- Parameters:
cnpj (str)
validate_after (bool)
- Return type:
str
- brazilian_ids.functions.company.cnpj.parse(cnpj)¶
Split CNPJ into firm, establishment and check digits.
Additionally, the CNPJ is also padded and validated before returning.
- Parameters:
cnpj (str)
- Return type:
- brazilian_ids.functions.company.cnpj.random(formatted=True)¶
Create a random, valid CNPJ identifier.
- Parameters:
formatted (bool)
- Return type:
str
- brazilian_ids.functions.company.cnpj.verification_digits(cnpj)¶
Find two check digits needed to make a CNPJ valid.
- Parameters:
cnpj (str)
- Return type:
tuple[int, int]