# BPS API — Indonesian Statistics Data API (`galih_rakasiwi/bps-data-api`) Actor

FastAPI wrapper for the BPS (Badan Pusat Statistik) Web API. Access Indonesian statistical data - domains, subjects, dynamic data, static tables, press releases, publications, foreign trade, census, and SDGs - using human-readable names. No BPS codes needed.

- **URL**: https://apify.com/galih_rakasiwi/bps-data-api.md
- **Developed by:** [RD.Galih Rakasiwi](https://apify.com/galih_rakasiwi) (community)
- **Categories:** Business, Developer tools
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.20 / 1,000 api requests

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

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

## BPS Data API

FastAPI wrapper for **BPS (Badan Pusat Statistik)** Web API — Indonesian Central Bureau of Statistics data access.

Access Indonesian statistical data: domains, subjects, dynamic data, static tables, press releases, publications, foreign trade, census, SIMDASI, SDGs, and more.

Designed as an Apify actor for publishing on [Apify Store](https://apify.com).

📖 **Full documentation:** [docs/](docs/) — index, architecture, API reference, code map, deployment, troubleshooting

### Quick Start

```bash
## 1. Sync dependencies (uv auto-creates venv)
uv sync

## 2. Set your BPS API key
cp .env.example .env
## Edit .env and add your BPS_API_KEY

## 3. Run the service
uv run bps-data-api

## Or with hot-reload during development
uv run uvicorn src.main:app --reload --port 8000

## 4. Open API docs
open http://localhost:8000/docs
```

### Authentication

BPS requires an API key. Three ways to provide it:

| Method | How |
|---|---|
| Header | `X-BPS-API-Key: your_key` |
| Env Var | `BPS_API_KEY=your_key` |
| Apify Input | `bpsApiKey` in actor input |

Priority: Header → Env Var → Apify Input

### API Endpoints

#### Simplified API (Recommended — User-Friendly)

All endpoints accept human-readable **names** — no BPS codes needed.

```
## Data Discovery
GET /api/v1/subjects?prov=Jawa Barat
GET /api/v1/subjects/Kependudukan?prov=jabar
GET /api/v1/variables?prov=jabar&keyword=population

## Statistical Data (Core)
GET /api/v1/data?prov=jabar&subject=Kependudukan
GET /api/v1/data/376?prov=Aceh
GET /api/v1/data?kabkot=Bandung&subject=Kependudukan   # regency-level!

## Content
GET /api/v1/tables?prov=jabar&keyword=poverty
GET /api/v1/tables/347?prov=Aceh
GET /api/v1/tables/347/excel?prov=Aceh                  # download Excel
GET /api/v1/news?prov=DKI Jakarta&year=2024
GET /api/v1/news/1092/pdf?prov=Aceh                     # download PDF
GET /api/v1/publications?prov=pusat&keyword=inflation
GET /api/v1/publications/{id}/pdf?prov=Aceh             # download PDF
GET /api/v1/publications/{id}/cover?prov=Aceh           # cover image

## Indicators
GET /api/v1/indicators?prov=Jawa Timur
GET /api/v1/infographics?prov=Jawa Barat
GET /api/v1/sdgs?goal=1

## Unified Search
GET /api/v1/search?q=inflation                           # across all data types!
GET /api/v1/search?q=poverty&prov=Jawa Barat

## Glossary
GET /api/v1/glossary?keyword=inflasi
GET /api/v1/glossary/{id}

## Census (name-based drill-down)
GET /api/v1/census/events
GET /api/v1/census/{event}/topics
GET /api/v1/census/{event}/areas
GET /api/v1/census/{event}/datasets?topic=Penduduk
GET /api/v1/census/{event}/data?topic=X&area=ACEH&dataset=1

## SIMDASI
GET /api/v1/simdasi/areas
GET /api/v1/simdasi/subjects?area=DKI Jakarta
GET /api/v1/simdasi/tables?area=DKI Jakarta
GET /api/v1/simdasi/tables/{id}?area=DKI Jakarta&year=2023
```

#### Province & Regency Lookup

```
GET /api/v1/provinces                                    # all 34 provinces
GET /api/v1/provinces/Jawa Barat                         # by name
GET /api/v1/provinces/jabar                              # by alias
GET /api/v1/kabkot?prov=Jawa Barat                       # regencies in province
GET /api/v1/kabkot/3271                                  # by domain ID
```

**New in v3.0:** `kabkot` parameter on all simplified endpoints for regency-level data.
When a name is ambiguous (e.g. "Bandung" = Kab + Kota), the API returns available domain IDs.

#### Health Check

```
GET /health
GET /api/v1/health
```

#### Legacy BPS-Compatible API

```
GET /api/v1/domain?type=all
GET /api/v1/list?model=subject&domain=1100&lang=ind
GET /api/v1/list?model=data&domain=1100&var=100&th=1
GET /api/v1/view?model=statictable&domain=1100&id=123&lang=ind
GET /api/v1/dataexim?sumber=1&periode=2&kodehs=01&jenishs=1&Tahun=2023
GET /api/v1/interoperabilitas/datasource/sensus/id/37
GET /api/v1/interoperabilitas/datasource/simdasi/id/26
```

### Project Structure

```
bps-data-api/
├── .actor/actor.json      # Apify actor configuration
├── src/
│   ├── main.py            # FastAPI app + entrypoint (v3.0)
│   ├── config.py          # Environment-based settings
│   ├── bps_client.py      # Async HTTP client for BPS API
│   ├── models.py          # Pydantic request/response models
│   ├── dependencies.py    # FastAPI dependency injection
│   ├── wilayah_data.py    # Province/regency name→code index
│   ├── simplified/
│   │   ├── router.py      # ★ Primary API (25+ endpoints)
│   │   ├── subject_cache.py   # Subject name→ID per domain
│   │   ├── census_helper.py   # Census name→ID resolution
│   │   └── simdasi_helper.py  # SIMDASI area code resolution
│   └── routers/
│       ├── health.py      # Health check
│       ├── wilayah.py     # /provinces, /kabkot
│       ├── domain.py      # /domain
│       ├── list.py        # /list (18 models)
│       ├── view.py        # /view
│       ├── dataexim.py    # Foreign trade
│       └── interoperability.py # Census + SIMDASI
├── docs/                  # Full documentation (9 files)
├── Dockerfile
└── .env.example
```

### BPS API Documentation

Full documentation: <https://webapi.bps.go.id/documentation/>

### License

MIT

### Related searches

bps api, badan pusat statistik api, indonesia statistics api, indonesian economic data, bps data json, statistik indonesia api

# Actor input Schema

## `bpsApiKey` (type: `string`):

Your BPS Web API key. If not provided, the X-BPS-API-Key header or BPS_API_KEY env var will be used.

## `rateLimitPerMinute` (type: `integer`):

Maximum requests per minute to BPS API

## `debug` (type: `boolean`):

Enable debug logging

## Actor input object example

```json
{
  "rateLimitPerMinute": 60,
  "debug": false
}
```

# Actor output Schema

## `api` (type: `string`):

Base URL of the running BPS Data API. Append /api/v1/... to call endpoints.

## `openapi` (type: `string`):

Full OpenAPI specification — use this to register the API as an LLM tool.

## `swagger` (type: `string`):

Interactive API documentation — try every endpoint directly in the browser.

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("galih_rakasiwi/bps-data-api").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("galih_rakasiwi/bps-data-api").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 '{}' |
apify call galih_rakasiwi/bps-data-api --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,galih_rakasiwi/bps-data-api"
        }
    }
}
```

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/wUTLbq2b1cpYZrILS/builds/i9hVwjbh1vNC3hBPz/openapi.json
