API reference¶
Auto-generated from the package docstrings.
Fetching data¶
ibge_variables ¶
ibge_variables(aggregate: int, variable: Any = None, periods: Any = -6, localities: Localities = 'BR', classification: Optional[Mapping[str, Any]] = None, view: Optional[str] = None, validate: bool = True, chunk: Any = True) -> pd.DataFrame
Retrieve variable results from an aggregate (the package's main function).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregate
|
int
|
Numeric aggregate identifier (SIDRA table). |
required |
variable
|
Any
|
|
None
|
periods
|
Any
|
Negative int for last-N (default |
-6
|
localities
|
Localities
|
|
'BR'
|
classification
|
Optional[Mapping[str, Any]]
|
Mapping of classification id -> category id(s), or |
None
|
view
|
Optional[str]
|
|
None
|
validate
|
bool
|
If |
True
|
chunk
|
Any
|
Controls automatic splitting of large queries. The IBGE API rejects
requests whose result is too large with an HTTP 500 error (the
documented limit is 100,000 values, but in practice requests fail
above about 50,000). |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Tidy (long) format: |
Notes
Large requests can be slow on the server side: queries covering all
municipalities (localities="N6", some 5,500 localities) may take one
to several minutes per request to be answered by the IBGE API, even
before any chunking. This is normal — the function is not hanging.
Source code in src/ibgepy/variables.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | |
ibge_aggregates ¶
ibge_aggregates(period: Optional[str] = None, subject: Optional[int] = None, classification: Optional[int] = None, periodicity: Optional[str] = None, level: Optional[str] = None) -> pd.DataFrame
List available aggregates (tables), optionally filtered.
Results are cached in memory per unique parameter combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
period
|
Optional[str]
|
Periodicity code followed by one or more period ids in brackets,
e.g. |
None
|
subject
|
Optional[int]
|
Numeric subject code (see :func: |
None
|
classification
|
Optional[int]
|
Numeric classification code, e.g. |
None
|
periodicity
|
Optional[str]
|
Periodicity code: |
None
|
level
|
Optional[str]
|
Geographic level: |
None
|
All
|
|
required | |
request
|
|
required | |
because
|
|
required | |
whole
|
|
required | |
aggregate
|
|
required | |
Returns
|
|
required |
Source code in src/ibgepy/aggregates.py
Metadata & discovery¶
ibge_metadata ¶
Retrieve complete metadata for an aggregate (cached per session).
Source code in src/ibgepy/metadata.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
ibge_periods ¶
Retrieve available periods for an aggregate.
Returns a DataFrame with columns id, literal, modification.
Source code in src/ibgepy/periods.py
ibge_localities ¶
ibge_localities(aggregate: int, level: Union[str, Sequence[str]] = 'N6', validate: bool = True) -> pd.DataFrame
Retrieve available localities for an aggregate.
level may be a single level ("N6") or a list (["N6", "N7"]).
With several levels one request is made per level and the results are
concatenated: the API's own multi-level endpoint returns an empty list
as soon as one of the levels has no localities for the aggregate.
Returns a DataFrame with columns id, name, level_id,
level_name (empty, but with those columns, when nothing is found).
Source code in src/ibgepy/localities.py
ibge_subjects ¶
Return IBGE subject codes and descriptions (built-in, no API call).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
Optional[str]
|
Optional regular expression to filter subject descriptions. If
|
None
|
ignore_case
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Columns |
Source code in src/ibgepy/subjects.py
Survey catalog¶
ibge_surveys ¶
List the full catalog of IBGE surveys with institutional metadata.
Uses the Metadata API (v2). If thematic_classifications is True
(default), a thematic_classifications column holds, per row, a nested
DataFrame of classification details.
Source code in src/ibgepy/surveys.py
ibge_survey_periods ¶
List the periods (year/month) for which a survey has metadata.
The survey code is validated against the IBGE catalog first; invalid
codes raise a helpful error with suggestions. Returns a DataFrame with
columns year, month (<NA> for structural surveys), order.
Source code in src/ibgepy/surveys.py
ibge_survey_metadata ¶
ibge_survey_metadata(survey: str, year: int, month: Optional[int] = None, order: int = 0) -> IbgeSurveyMetadata
Detailed metadata for a survey in a given reference period.
Both the survey code and the year/month combination are validated against the IBGE catalog before the request is sent.
Source code in src/ibgepy/surveys.py
SIDRA URLs¶
parse_sidra_url ¶
Convert a SIDRA API URL into a structured, name-enriched breakdown.
Source code in src/ibgepy/sidra_url.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
fetch_sidra_url ¶
Parse a SIDRA API URL and fetch the data via :func:ibge_variables.
Source code in src/ibgepy/sidra_url.py
Utilities¶
parse_ibge_value ¶
Coerce an IBGE value column to numeric.
Conversions, following IBGE's tabular presentation standards:
"-"(numeric zero, not rounding) ->0".."(not applicable),"..."(not available),"X"(suppressed) ->NaN- everything else -> :func:
pandas.to_numeric
Accepts a scalar, a list, or a :class:pandas.Series and returns the
matching shape (Series in, Series out; scalar in, float out).
Source code in src/ibgepy/values.py
ibge_clear_cache ¶
Remove all cached metadata (aggregates and surveys).
Forces fresh API calls on subsequent requests. Public alias:
:func:ibgepy.ibge_clear_cache.
Source code in src/ibgepy/_cache.py
set_verbose ¶
Returned objects¶
IbgeMetadata
dataclass
¶
IbgeMetadata(id: Any, name: Any, url: Any, survey: Any, subject: Any, periodicity: Dict[str, Any], territorial_level: Dict[str, List[str]], variables: DataFrame, classifications: DataFrame)
Complete metadata for an IBGE aggregate.
classifications is a DataFrame whose categories column holds, for
each row, a nested DataFrame of categories (the equivalent of the R
list-column).
IbgeSurveyMetadata
dataclass
¶
IbgeSurveyMetadata(status: Any, category: Any, type: Any, area: Any, acronym: Any, start_date: Any, deactivation_date: Any, sidra_url: Any, concla_url: Any, thematic_classifications: DataFrame, occurrences: List[Any])
Institutional/methodological metadata for a survey in a period.
SidraQuery
dataclass
¶
SidraQuery(aggregate: Dict[str, Any], variables: DataFrame, periods: str, localities: List[Dict[str, Any]], classifications: List[Dict[str, Any]], ibger_call: str, periodicity: Dict[str, Any])
Parsed SIDRA query, enriched with names from the aggregate metadata.
Exceptions¶
IbgeError ¶
Bases: RuntimeError
Raised when an IBGE API request fails.
ValidationError ¶
Bases: ValueError
Raised when a parameter does not match the aggregate metadata.