# INE Spain Population by Municipality Scraper (Padron) (`steadfetch/ine-padron-municipal-extractor`) Actor

Resident population by Spanish municipality and sex from the INE Padron municipal (official INE Tempus API). One validated row per municipality, year and indicator, for all 8,132 municipalities including the 88 of Canarias. Statistical secret kept as null plus a note.

- **URL**: https://apify.com/steadfetch/ine-padron-municipal-extractor.md
- **Developed by:** [Steadfetch](https://apify.com/steadfetch) (community)
- **Categories:** Travel, Business
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 result delivereds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## INE Spain Population by Municipality Scraper (Padron)

Resident population of every Spanish municipality, by sex, from the **INE Padron municipal** (Spain's official municipal register of inhabitants), read through the INE's own public Tempus API.

- **Source:** [INE - Padron municipal, operation 22](https://www.ine.es/jaxiT3/Tabla.htm?t=2856) (public, no login, no CAPTCHA). Source: INE, www.ine.es.
- **One row per municipality, year and indicator:** total, male and female residents.
- **Coverage:** all 8,132 municipalities of Spain, including the 88 of the Canary Islands, Ceuta and Melilla.
- **No personal data:** only aggregated counts per municipality.

### What it does

1. Validates your input before anything is downloaded: municipality codes must be five-digit INE codes that exist, and the year must be a four-digit year.
2. Groups the codes by province and asks the INE only for the provincial tables it needs: one request per province, with one second between requests. An empty list reads all 52 tables.
3. Matches each series name of the INE table ("Calp. Hombres. Total habitantes. Personas.") to the INE municipality code, and emits one validated row per municipality, year and indicator.

Nothing is delivered until every table has been downloaded and every row validated, so a failed run delivers nothing.

When the INE hides a figure for statistical secrecy, the row is still delivered with `value: null` and `valueNote: "secret"`. It is never turned into 0 and never dropped.

### Input

```json
{ "municipalityCodes": ["03047"] }
```

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `municipalityCodes` | array of strings | No | Five-digit INE municipality codes, e.g. `03047` for Calp. Empty or missing means all municipalities. A malformed code (`3047`, `03047 `, an unknown `99999`) stops the run before any download, naming the value and the expected format. |
| `period` | string | No | Year as `YYYY` (reference date 1 January). Empty or missing means the latest year the INE has published. A monthly value such as `2026-11` is rejected. A year the INE has not published yet fails the run and names the latest available year; it is never replaced by another year. |

### Output

#### Example output

```json
{
  "url": "https://www.ine.es/jaxiT3/Tabla.htm?t=2856",
  "title": "Calp - Population (female), 2025",
  "scrapedAt": "2026-11-16T14:07:32.644Z",
  "municipalityCode": "03047",
  "municipalityName": "Calp",
  "source": "INE - Padron municipal",
  "period": "2025",
  "indicator": "population_female",
  "value": 13958,
  "valueNote": null,
  "unit": "persons",
  "breakdown": { "sex": "female" }
}
```

#### Output fields

| Field | Type | Description |
| --- | --- | --- |
| `municipalityCode` | string | Five-digit INE code (two of province, three of municipality). |
| `municipalityName` | string | Official INE name. |
| `period` | string | Year (`YYYY`); the padron reference date is 1 January. |
| `indicator` | string | `population_total`, `population_male` or `population_female`. |
| `value` | number or null | Residents. `null` when the INE hides the figure. |
| `valueNote` | string or null | `secret` for statistical secrecy, `no value` when the INE has no figure; `null` otherwise. |
| `unit` | string | Always `persons`. |
| `breakdown` | object or null | `{"sex":"male"}` or `{"sex":"female"}`; `null` for the total. |
| `source` | string | `INE - Padron municipal`. |
| `url` | string | Public INE page of the provincial table the row comes from. |
| `title` | string | Readable label of the row. |
| `scrapedAt` | date-time | ISO 8601 UTC timestamp of the extraction. |

### Pricing

Pay-per-event with the two synthetic platform events:

| Event | When it fires | Price |
| --- | --- | --- |
| `apify-actor-start` | once per run (automatic) | 0.00005 USD |
| `apify-default-dataset-item` | one validated row saved to the dataset (automatic) | 0.001 USD per row = **1.00 USD per 1,000 results** |

There is no custom per-item event and no `monitor-check` event (this is an extractor, not a monitor), so a row is never billed twice. A run that fails delivers no rows and charges no result events.

Measured locally on 2026-11-16 with `{"municipalityCodes":["03047"]}` (Calp): 3 rows, about 1.8 s in Node and a 148 MB peak memory (about 17 s with the `apify run` wrapper). A full run over all 52 provincial tables is about 24,400 rows (8,132 municipalities x 3 indicators for one year) and takes about a minute because of the one-second pause between requests; it was estimated, not run.

**Works on the Apify free plan:** the 5 USD monthly credit covers about 5,000 rows (a little under: (5.00 - 0.00005) / 0.001 = 4,999), which is about 1,600 municipalities for one year (3 rows each); the full national table costs about 24 USD.

### FAQ

**Which municipalities are covered?** All 8,132 in the INE list at 1 January 2026, including the 88 municipalities of Las Palmas and Santa Cruz de Tenerife, Ceuta and Melilla.

**Which years are available?** The latest year is the default. With `period` you can ask for earlier years of the same tables; a year the INE does not have fails with an error that names the latest year.

**Why do I get fewer rows than I expected?** A series whose name does not match any municipality of its province is skipped and written to the run log (warning), never guessed. The province total series is not a municipality and is also skipped.

**What if the INE hides a number?** The row stays with `value: null` and `valueNote: "secret"`.

**What if the INE blocks or answers without data?** HTTP 401, 403, 429 or 451, or an HTTP 200 whose body is not data (for example "No puede mostrarse por restricciones de volumen"), fails the run with an error that names the INE. There is no browser, no proxy and no retry around a block.

**Licence and attribution?** The INE legal notice sets Creative Commons Reconocimiento 4.0 (CC BY 4.0) for the statistical information of its website, including commercial reuse, citing the source: "Fuente: INE, www.ine.es". Municipality codes and names come from the INE list at 1 January 2026. See `docs/legal-gate.md`.

### Maintenance

Tested daily by Steadfetch against the live INE API with the Calp input. If the INE changes the table layout the Actor fails with an error instead of delivering wrong figures.

### Development

```bash
npm install
npm test                 # lint + typecheck + offline tests on saved INE answers
npm run publish:check
npm run build && npm run verify:build
```

`src/shared/` holds byte-identical copies of `tools/lib/es-municipios/` (checked by `test/shared-copies.test.ts`). The data map is in `docs/data-map.md`.

### Other Steadfetch Actors

- [Spain Tourism Statistics Scraper](https://apify.com/steadfetch/exceltur-indicadores-extractor) - Exceltur tourism indicators.
- [AENA Airport Statistics Scraper](https://apify.com/steadfetch/aena-estadisticas-extractor) - monthly traffic of Spanish airports.

# Actor input Schema

## `municipalityCodes` (type: `array`):

Five-digit INE municipality codes (two digits of province plus three of municipality, e.g. 03047 for Calp, 38001 for Adeje). Leave empty for all 8,132 municipalities; the Actor then reads the 52 provincial tables.

## `period` (type: `string`):

Year of the padron as YYYY (reference date 1 January), e.g. "2025". Leave empty for the latest year the INE has published. A monthly value such as 2026-11 is rejected: this source is annual.

## Actor input object example

```json
{
  "municipalityCodes": [
    "03047"
  ],
  "period": "2025"
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset items validated against the item schema in dataset_schema.json (fields).

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "municipalityCodes": [
        "03047"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("steadfetch/ine-padron-municipal-extractor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "municipalityCodes": ["03047"] }

# Run the Actor and wait for it to finish
run = client.actor("steadfetch/ine-padron-municipal-extractor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "municipalityCodes": [
    "03047"
  ]
}' |
apify call steadfetch/ine-padron-municipal-extractor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,steadfetch/ine-padron-municipal-extractor"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/4txCBcXfzICnoT5AC/builds/KMlgEIA6SooUQBacU/openapi.json
