PHPackages                             dekiakbar/indonesia-regions-php-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. dekiakbar/indonesia-regions-php-client

ActiveLibrary[API Development](/categories/api)

dekiakbar/indonesia-regions-php-client
======================================

This package will retrieve and extract regions of Indonesia from https://bps.go.id

1.2.1(5y ago)645310MITPHPPHP ^7.2|^7.3|^7.4|^8.0

Since Jul 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/dekiakbar/indonesia-regions-php-client)[ Packagist](https://packagist.org/packages/dekiakbar/indonesia-regions-php-client)[ Docs](https://github.com/dekiakbar/indonesia-regions-php-client)[ RSS](/packages/dekiakbar-indonesia-regions-php-client/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (2)Versions (6)Used By (0)

Indonesia Regions PHP Client
============================

[](#indonesia-regions-php-client)

 [![Build Status](https://camo.githubusercontent.com/8d6262a5ab706c8a23d56f60889435e962a806ef92bc0a21a22aa1d746e3c967/68747470733a2f2f7472617669732d63692e636f6d2f64656b69616b6261722f696e646f6e657369612d726567696f6e732d7068702d636c69656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/github/dekiakbar/indonesia-regions-php-client) [![Stable Version](https://camo.githubusercontent.com/2c5b1345df5f965a4d7a8ef4e73e71ce01bb96640cc2ebe120bf7a76303a5eac/68747470733a2f2f706f7365722e707567782e6f72672f64656b69616b6261722f696e646f6e657369612d726567696f6e732d7068702d636c69656e742f76657273696f6e)](https://packagist.org/packages/dekiakbar/indonesia-regions-php-client) [![Unstable Version](https://camo.githubusercontent.com/ae08379966a5053aae4011991a5efed66d50b655edf66e1799c7f380a6900306/68747470733a2f2f706f7365722e707567782e6f72672f64656b69616b6261722f696e646f6e657369612d726567696f6e732d7068702d636c69656e742f762f756e737461626c65)](https://packagist.org/packages/dekiakbar/indonesia-regions-php-client) [![StyleCI](https://camo.githubusercontent.com/e8975884f741ebd88ebb060e9b3c0bdd9b026e702f3dd5b44ccf90d1338693ce/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3238313435353236302f736869656c643f6272616e63683d6d6173746572)](https://packagist.org/packages/dekiakbar/indonesia-regions-php-client) [![License](https://camo.githubusercontent.com/f8a7d692d8ec7d886cd1695eb181cbac8476a2e7036aed8614a7fe3c29bed538/68747470733a2f2f706f7365722e707567782e6f72672f64656b69616b6261722f696e646f6e657369612d726567696f6e732d7068702d636c69656e742f6c6963656e7365)](https://github.com/dekiakbar/indonesia-regions-php-client/blob/master/LICENSE)

---

About Indonesia Regions PHP Client
----------------------------------

[](#about-indonesia-regions-php-client)

> This package can be used to retrieve provinces, cities, districts and villages data from [BPS](https://bps.go.id). **Note:** Wherever you use this package please specify [BPS](https://bps.go.id) as the data source.

Table of Contents
-----------------

[](#table-of-contents)

- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Usage](#usage)
- [License](#license)

---

Prerequisites
-------------

[](#prerequisites)

Before you install this package, make sure that the requirements below are met

```
PHP >= 7.2
ext-json
ext-curl
docker (optional)
docker-compose (optional)

```

---

Development (Docker)
--------------------

[](#development-docker)

For development you can use docker container for this project, here are step to reproduce docker env on your local env :

- Clone this repository: `git clone https://github.com/dekiakbar/indonesia-regions-php-client.git`
- Navigate to project directory : `cd indonesia-regions-php-client`
- Snd run : `docker-compose up -d`
- Wait a few minutes, the image for docker will build automatic, after the build has been done you will get an image with the name **indonesia-regions-php-client\_app** and a container with the name **indonesia-regions-php-client\_app\_1** and **indonesia-regions-php-client\_mysql\_1**.
- Check if the container are exit, you can run : `docker ps -a`
- If the container is not running, you can run : `docker start indonesia-regions-php-client_app_1` and `docker start indonesia-regions-php-client_mysql_1`
- You can run interactive shell (SSH) : `docker exec -it indonesia-regions-php-client_app_1 /bin/bash`
- **NOTE:**
    - The **indonesia-regions-php-client\_app\_1** container is used to mount the directory project.
    - The **indonesia-regions-php-client\_mysql\_1** container is used to save the database from project.
    - The default docker workdir is **app** for **indonesia-regions-php-client\_app\_1** container.
    - The **app** directory is mounted from **indonesia-regions-php-client** host directory, so if you edit the file inside **indonesia-regions-php-client** in the host Operating system, the file inside docker will be changed or vice versa, the reason I made docker container mount the project root a.k.a **indonesia-regions-php-client** to the app because I am too lazy to mount file from docker, so if docker mount file from **indonesia-regions-php-client** root directory I can simple edit the file directly from my favorite IDE 😝

---

Installation
------------

[](#installation)

- `$ composer require dekiakbar/indonesia-regions-php-client`
- And You're done.

---

Usage
-----

[](#usage)

- You can pass the parameter to the method, All of this package has 3 mode :
- For **BPS** and **POS** mode you can use **BPS Id/Code** to retrieve province / city / subdistrict / village data. But you **Can Not** use **BPS Id/Code** to retrieve province / city / subdistrict / village data if you use **dagri** mode, please use **dagri Id/code** to retrieve province / city / subdistrict / village data.
- If mode is **NULL**, then the method will use default mode, default mode is **bps**.
- **bps** : only return : **kode** and **nama** of province / city / subdistrict / village.
- **dagri** : return : **kode\_bps**, **nama\_bps**, **kode\_dagri**, **nama\_dagri** of province / city / subdistrict / village.
- **pos** : return : **kode\_bps**, **nama\_bps**, **kode\_pos**, **nama\_pos** of province / city / subdistrict / village.

Note
----

[](#note)

- **Not all method always return `list` and `detail` object, on some method only return `list` or `detail` you must check it again before you use the response**.
- If you just need the data (not planing to use this API), just import the Database Dump on `export` folder, extract `indonesia_regions_pos.tar.gz` and import to your database.
- If you want to retrieve data with mode **Dagri** please fill **Parent Id** (Provinde Id / City Id / Subdistrict Id) with valid data. **Parent Id for POS and Dagri are different**. You can get the city Id `(kode)` from `$region->getCityListByProvinceId('pos',$provinceId)->list`.
- please remeber if you want fetch any data you must use parent Id (province Id / City Id / Subdistrict Id) from **list** collection, **NOT** from detail collection **(If you use ID from detail it will work but you will get duplicate data)**.
- #### Retrieve All province data

    [](#retrieve-all-province-data)

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    use Dekiakbar\IndonesiaRegionsPhpClient\Region;
    $region = new Region();
    print_r( $region->getAllProvince('pos') );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 11
                        [nama_bps] => ACEH
                        [kode_pos] => 20000
                        [nama_pos] => ACEH
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 51
                        [nama_bps] => BALI
                        [kode_pos] => 80000
                        [nama_pos] => BALI
                    )
            )
        [list] => Array
            (
                [0] => stdClass Object
                    (
                        [kode] => 11
                        [nama] => ACEH
                    )

                [1] => stdClass Object
                    (
                        [kode] => 12
                        [nama] => SUMATERA UTARA
                    )
            )
    )
    ```
- #### Retrieve City List By Province Id

    [](#retrieve-city-list-by-province-id)

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    use Dekiakbar\IndonesiaRegionsPhpClient\Region;
    $region = new Region();

    // province Id from $region->getAllProvince('bps')
    $provinceId = 32;
    print_r(
        $region->getCityListByProvinceId('pos',$provinceId)
    );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 3204
                        [nama_bps] => BANDUNG
                        [kode_pos] => 40300
                        [nama_pos] => BANDUNG
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 3273
                        [nama_bps] => BANDUNG
                        [kode_pos] => 40100
                        [nama_pos] => KOTA BANDUNG
                    )
            )
        [list] => Array
            (
                [0] => stdClass Object
                    (
                        [kode] => 3201
                        [nama] => BOGOR
                    )

                [1] => stdClass Object
                    (
                        [kode] => 3202
                        [nama] => SUKABUMI
                    )
            )
    )
    ```
- #### Retrieve Subdistrict List By City Id

    [](#retrieve-subdistrict-list-by-city-id)

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    use Dekiakbar\IndonesiaRegionsPhpClient\Region;
    $region = new Region();

    // POS
    // city Id from $region->getCityListByProvinceId('pos',$provinceId)->list
    $cityId = 3273;
    print_r(
        $region->getSubdistrictListByCityId('pos',$cityId)
    );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 3273180
                        [nama_bps] => ANDIR
                        [kode_pos] => 40181
                        [nama_pos] => Andir
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 3273180
                        [nama_bps] => ANDIR
                        [kode_pos] => 40182
                        [nama_pos] => Andir
                    )
            )
        [list] => Array
            (
                [0] => stdClass Object
                    (
                        [kode] => 3273010
                        [nama] => BANDUNG KULON
                    )

                [1] => stdClass Object
                    (
                        [kode] => 3273020
                        [nama] => BABAKAN CIPARAY
                    )
            )
    )

    // Dagri
    // city Id from $region->getCityListByProvinceId('dagri',$provinceId)->list
    $cityId = '32.73';
    print_r(
        $region->getSubdistrictListByCityId('dagri',$cityId)
    );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 3273050
                        [nama_bps] => ASTANAANYAR
                        [kode_dagri] => 32.73.10
                        [nama_dagri] => ASTANA ANYAR
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 3273120
                        [nama_bps] => UJUNG BERUNG
                        [kode_dagri] => 32.73.26
                        [nama_dagri] => UJUNGBERUNG
                    )
            )
        [list] => Array
            (
                [0] => stdClass Object
                    (
                        [kode] => 32.73.01
                        [nama] => Sukasari
                    )

                [1] => stdClass Object
                    (
                        [kode] => 32.73.02
                        [nama] => Coblong
                    )
            )
    )
    ```
- #### Retrieve Village List By Subdistrict Id

    [](#retrieve-village-list-by-subdistrict-id)

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    use Dekiakbar\IndonesiaRegionsPhpClient\Region;
    $region = new Region();
    // POS
    // subdistrict Id from $region->getSubdistrictListByCityId('pos',$cityId)->list
    $subdistrictId = 3273010;
    print_r(
        $region->getVillageListBySubdistrictId('pos',$subdistrictId)
    );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 3273010005
                        [nama_bps] => CARINGIN
                        [kode_pos] => 40212
                        [nama_pos] => Caringin
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 3273010007
                        [nama_bps] => CIBUNTU
                        [kode_pos] => 40212
                        [nama_pos] => Cibuntu
                    )
            )
        [list] => Array
            (
                [0] => stdClass Object
                    (
                        [kode] => 3273010001
                        [nama] => GEMPOL SARI
                    )

                [1] => stdClass Object
                    (
                        [kode] => 3273010002
                        [nama] => CIGONDEWAH KALER
                    )
            )
    )

    // Dagri
    // subdistrict Id from $region->getSubdistrictListByCityId('dagri',$cityId)->list
    $subdistrictId = '32.73.10';
    print_r(
        $region->getVillageListBySubdistrictId('dagri',$subdistrictId)
    );

    // will return something like :
    stdClass Object
    (
        [detail] => Array
            (
                [0] => stdClass Object
                    (
                        [kode_bps] => 3273050001
                        [nama_bps] => KARASAK
                        [kode_dagri] => 32.73.10.1001
                        [nama_dagri] => KARASAK
                    )

                [1] => stdClass Object
                    (
                        [kode_bps] => 3273050002
                        [nama_bps] => PELINDUNG HEWAN
                        [kode_dagri] => 32.73.10.1006
                        [nama_dagri] => PELINDUNG HEWAN
                    )
            )
    )
    ```
- #### Retrieve ISO 3166-2 code for province

    [](#retrieve-iso-3166-2-code-for-province)

    > **Note : This method only for province**

    ```
    require_once __DIR__ . '/vendor/autoload.php';
    use Dekiakbar\IndonesiaRegionsPhpClient\Region;
    $region = new Region();

    // Province code get from $region->getAllProvince('bps')->list
    $provinceId = 32;
    print_r(
            $region->getIsoCode($provinceId)
    );

    // will return String, something like :
    ID-JB
    ```

---

License
-------

[](#license)

[![License](https://camo.githubusercontent.com/f8a7d692d8ec7d886cd1695eb181cbac8476a2e7036aed8614a7fe3c29bed538/68747470733a2f2f706f7365722e707567782e6f72672f64656b69616b6261722f696e646f6e657369612d726567696f6e732d7068702d636c69656e742f6c6963656e7365)](//packagist.org/packages/dekiakbar/indonesia-regions-php-client)

- **[MIT license](https://github.com/dekiakbar/indonesia-regions-php-client/blob/master/LICENSE)**
- Copyright 2020 © [Deki Akbar](https://github.com/dekiakbar).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~79 days

Total

4

Last Release

1877d ago

PHP version history (2 changes)1.0.0PHP ^7.2

1.2.1PHP ^7.2|^7.3|^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/ca73f1e344c31c29e2a54b0720d09af3398d0925de1431f185997642f3d4bd80?d=identicon)[dekiakbar](/maintainers/dekiakbar)

---

Top Contributors

[![dekiakbar](https://avatars.githubusercontent.com/u/21062206?v=4)](https://github.com/dekiakbar "dekiakbar (2 commits)")

---

Tags

apibpsindonesiaindonesia-regionsphpregionphpapiregionindonesiabps

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dekiakbar-indonesia-regions-php-client/health.svg)

```
[![Health](https://phpackages.com/badges/dekiakbar-indonesia-regions-php-client/health.svg)](https://phpackages.com/packages/dekiakbar-indonesia-regions-php-client)
```

###  Alternatives

[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[renoki-co/php-k8s

Control your Kubernetes clusters with this PHP-based Kubernetes client. It supports any form of authentication, the exec API, and it has an easy implementation for CRDs.

321669.7k2](/packages/renoki-co-php-k8s)[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162145.5k1](/packages/joisarjignesh-bigbluebutton)[obiefy/api-response

Simple Laravel package to return Json responses.

17324.6k](/packages/obiefy-api-response)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[dystcz/lunar-api

Dystore API layer for Lunar e-commerce package

411.1k3](/packages/dystcz-lunar-api)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
