Skip to content

pycensus.census.countries.spain.ine.loader

Loader for Spain's INE Padron municipal, returning a common-schema GeoDataFrame.

Technical aspects

Mirrors :mod:pycensus.mexico.inegi.loader's shape: reads as much as possible from pyCensus' parquet cache (:mod:pycensus.cache), fetching only the logical columns actually missing. Unlike Mexico's per-state ITER file, INE's Tempus API (:mod:pycensus.spain.api) returns every Spanish municipality in a single request, so the raw response is downloaded once (cached on disk, independent of the parquet cache) and then sliced per requested region/level.

Only population/malePopulation/femalePopulation are implemented -- see :mod:pycensus.spain.ine.schema module docstring for why fields present in earlier (fabricated) versions of this module (age brackets, employment, income, housing) were removed rather than kept with invented INE codes: they were never verified against a real downloaded INE file. Real values for those exist in INE's Census 2021 (Censo de Poblacion y Viviendas) microdata/tables, which is a separate, unverified follow-up (see this module's download_census_data docstring).

Source

INE Padron municipal (table 29005): https://servicios.ine.es/wstempus/js/ES/DATOS_TABLA/29005

load(aoi=None, regions=None, level='municipality', year='latest', api_key=None, cache_dir=None, cache=True, data_dir=None)

Load INE's Padron municipal population data as a common-schema GeoDataFrame.

Parameters:

Name Type Description Default
aoi Optional[GeoDataFrame]

Area of interest. Used to auto-detect regions if not given, and to clip the final result.

None
regions Optional[Union[str, List[str]]]

Region code(s) -- autonomous community code, province code, or 5-digit municipality code, matching level. Derived from aoi if omitted (aoi is then required).

None
level str

Standard geometry level name. Spain supports nation, autonomous_community, province, municipality, section directly; other standard levels fall back via :data:pycensus.spain.constants.LEVEL_FALLBACK (tract/ blockgroup -> section). district/block are not implemented (see :mod:pycensus.spain.geography). section population comes from a different, per-province INE source (2022 vintage) than municipality+ (2025 vintage) -- see :mod:pycensus.spain.api module docstring.

'municipality'
year Union[int, str]

Vintage year, or "latest". INE's Padron API always returns its single latest published year (2025 as of this module's implementation) -- year is accepted for interface parity but not otherwise used to select a vintage.

'latest'
api_key Optional[str]

Not used -- INE's Padron Tempus API requires no API key.

None
cache_dir Optional[str]

Root of pyCensus' parquet cache. Defaults to :func:pycensus.cache.default_cache_dir.

None
cache bool

If False, bypass the parquet cache entirely.

True
data_dir Optional[str]

Root directory for raw INE/GISCO downloads (separate from cache_dir). Defaults to :data:pycensus.spain.constants.DEFAULT_DATA_DIR.

None

Returns:

Type Description
GeoDataFrame

GeoDataFrame with GEOID, geometry, and one ine_-prefixed

GeoDataFrame

column per logical column in :data:pycensus.spain.ine.schema.SCHEMA.

Raises:

Type Description
ValueError

If neither regions nor aoi is given.

NotImplementedError

If level resolves to a level without a real boundary source (see :mod:pycensus.spain.geography).

download_census_data(level='municipality', regions=None, data_dir=None, overwrite=False)

Force a fresh download of INE's Padron municipal table to the raw cache.

Parameters:

Name Type Description Default
level str

Accepted for interface parity; the Padron API returns every municipality in one request regardless of level.

'municipality'
regions Optional[Union[str, List[str]]]

Accepted for interface parity; not used to filter the download (the raw file always holds every municipality).

None
data_dir Optional[str]

Root directory for raw downloads.

None
overwrite bool

If True, delete the cached raw JSON file first so it is re-downloaded from INE.

False

Returns:

Type Description
str

Path to the raw cache file that was downloaded/refreshed.

Note

Only the Padron (population by sex) is implemented here. INE's Census 2021 (Censo de Poblacion y Viviendas) publishes households, housing, education, and employment data at municipality level too, via the same Tempus API under a different operation/table id, but that was not identified and verified against a real downloaded file in this rebuild -- see the module docstring.