A modern, containerized platform for Philippine Standard Geographic Code (PSGC) data.
Note: This project is a complete overhaul of the legacy v1.0 scraping scripts. If you are looking for the old PHP/Python crawlers, please switch to the
v1-legacy-crawlerbranch.
The Open PH Geographic Data Platform provides a reliable, high-performance way to access Philippine geographic data (Regions, Provinces, Cities, Municipalities, Barangays).
Unlike the previous version which relied on fragile web scraping, v2.0.0+ uses a verified ingestion workflow where official PSGC Excel files are uploaded via a secure Admin Dashboard. This data is then served via:
- Public API: A high-speed, cached REST API (FastAPI + Redis) for real-time application usage.
- Static Dumps: Automatically generated
.sql,.json,.xml, and.csvfiles for offline use.
Live Demo: https://barangays.sanchez.ph
Built for performance and reliability on OCI Ampere (ARM64) infrastructure.
- Database: PostgreSQL 16 + PostGIS (Hierarchical integrity & geo-spatial readiness)
- Backend: Python FastAPI (Async, Auto-Documentation)
- Caching: Redis 7 (Rate limiting & response caching)
- Frontend: Next.js 14 (App Router), Tailwind CSS, Shadcn/UI
- Infrastructure: Docker Compose (Orchestration)
- β Live Public API: Query geographic data with sub-millisecond latency.
- β Verified Data Ingest: Admin interface to upload official PSGC Excel files, preventing "broken crawler" issues.
- β Auto-Generation: Instantly generates static SQL/JSON/CSV/XML dumps upon data update.
- β Rate Limiting: Built-in protection against abuse (via Redis).
- β
Interactive Docs: Full Swagger UI (
/docs) and Redoc (/redoc) support. - β Dockerized: One-command deployment for any server.
- Docker & Docker Compose
git clone https://github.com/tildemark/ph-geographic-database-generator-to-sql-json-csv.git
cd ph-geographic-database-generator-to-sql-json-csvCreate a .env file in the root directory:
# Database Credentials
POSTGRES_USER=admin
POSTGRES_PASSWORD=change_me_securely
POSTGRES_DB=ph_geo_db
# Security
ADMIN_SECRET=your_secret_upload_key
# Domain Configuration
NEXT_PUBLIC_API_URL=https://yourdomain.com/api
ALLOWED_ORIGINS=https://yourdomain.comdocker-compose up --build -d- Frontend: Accessible at
http://localhost:3000 - API: Accessible at
http://localhost:8000 - API Docs: Accessible at
http://localhost:8000/docs
If the backend fails with InvalidPasswordError:
- Stale Volumes: If you changed the password in
.envbut the DB still reports an old password, Docker might be reusing a "zombie" volume. - Resolution: Reset the database volume (Note: This deletes data).
docker compose down -v docker compose up -d
- Network Collisions: If your server runs multiple Docker stacks, a container named
dborredismight resolve to the wrong stack. - Resolution: Use unique hostnames in
docker-compose.yml. We have defaulted toph_geo_dbandph_geo_redisto prevent this.
- Major cities (Highly Urbanized Cities) are often administratively independent from provinces.
- Resolution: Re-upload the PSGC Excel file via the
/adminpanel. The ingestion script has updated logic to map these cities to their geographic provinces for easier navigation.
- Large Excel files might exceed the default Nginx upload limit.
- Resolution: Update your Nginx Proxy Manager / Nginx config:
client_max_body_size 50M; proxy_read_timeout 300s;
The API is free to use but rate-limited to ensure availability.
Base URL: https://barangays.sanchez.ph/api
| Method | Endpoint | Description |
|---|---|---|
GET |
/regions |
List all regions |
GET |
/regions/{code}/provinces |
Get all provinces in a region |
GET |
/provinces/{code}/cities |
Get all cities/municipalities in a province |
GET |
/cities/{code}/barangays |
Get all barangays in a city/municipality |
For full parameter details, visit the Swagger Documentation.
To update the dataset when PSA releases a new PSGC file:
- Download the latest PSGC Publication (Excel) from the PSA Website.
- Navigate to
/adminon your deployment. - Enter your
ADMIN_SECRET. - Upload the
.xlsxfile. - Wait: The system will sync the database and regenerate all static download files.
Contributions are welcome! Please ensure you use docker-compose for development to match the production environment.
This project is licensed under the MIT License - see the LICENSE file for details.