brazilian_ids.functions.location package¶
Submodules¶
brazilian_ids.functions.location.cep module¶
Functions to work with CEP (“Código de Endereçamento Postal”, in Brazilian Portuguese), which is the equivalent of zipcodes.
The meaning of numeric codes for region, sub region, etc, are in strict control of a private company in Brazil called Correios. The company has the monopoly in Brazil and doesn’t provide data besides simply queries with limited results and restricted by captchas to making data scraping more difficult.
See also:
- class brazilian_ids.functions.location.cep.CEP(formatted_cep, region, sub_region, sector, sub_sector, division, suffix)¶
Bases:
objectRepresentation of a CEP.
Should be obtained from the
parsefunction.- Parameters:
formatted_cep (str)
region (str)
sub_region (str)
sector (str)
sub_sector (str)
division (str)
suffix (str)
- division: str¶
- formatted_cep: str¶
- region: str¶
- sector: str¶
- sub_region: str¶
- sub_sector: str¶
- suffix: str¶
- brazilian_ids.functions.location.cep.format(cep)¶
Applies typical 00000-000 formatting to CEP.
- Parameters:
cep (str)
- Return type:
str
brazilian_ids.functions.location.municipio module¶
Functions to handle Brazilian município (county) codes.
Although the municipio code has a verification digit, there are 9 known codes where those digits are invalid.
This module contains those municipio codes in the INVALID dict.
See also: - ‘Nota ténica 2008’ - IBGE
- exception brazilian_ids.functions.location.municipio.InvalidMunicipioFederalUnitError(federal_unit)¶
Bases:
ValueError
- exception brazilian_ids.functions.location.municipio.InvalidMunicipioLengthError(municipio, expected_digits=7)¶
Bases:
InvalidMunicipioTypeMixin,InvalidIdLengthErrorException for invalid município length error.
- Parameters:
municipio (str)
expected_digits (int)
- Return type:
None
- class brazilian_ids.functions.location.municipio.InvalidMunicipioTypeMixin¶
Bases:
objectMixin class for município errors.
- id_type()¶
- class brazilian_ids.functions.location.municipio.Municipio(unidade_federativa, municipio, control_digits)¶
Bases:
objectRepresentation of a município based on it’s complete code.
- Parameters:
unidade_federativa (str)
municipio (str)
control_digits (str)
- property control_digits: str¶
Return the ‘control digits’ created by IBGE.
- property federal_unit: str¶
Return the name of the Brazilian UF.
- property federal_unit_code: str¶
Return the code of the ‘unidade federativa’ (UF), corresponding to one of the Brazil states or the capital.
- static federal_units()¶
- Return type:
dict[str, str]
- property municipio: str¶
Return the município code.
- brazilian_ids.functions.location.municipio.is_valid(municipio)¶
Check whether município code is valid.
It’s hard to check if a code is valid completely since the control digits are defined internally by IBGE and, to this date, there are 5,570 municípios in Brazil.
This function tries to check more basic aspects that are possible without copying a large amount of text to the Python code.
Also, those codes are always changing.
- Parameters:
municipio (str)
- Return type:
bool