First Lookup
A 5-minute end-to-end tour of the barangay package: browse views, look up records, traverse hierarchy, fuzzy search, validate addresses, export to pandas, and switch historical versions (Python + CLI).
A 5-minute end-to-end tour of what barangay can do. Assumes you have already installed the package.
Browse admin levels
Pre-built views give direct access to every PSGC administrative level.
from barangay import regions, provinces, municipalities, cities, barangays
print(regions) # <PSGC region database: 18 records>
print(provinces) # <PSGC province database: 82 records>
print(barangays) # <PSGC barangay database: 42010 records>barangay info stats| Model | Barangay Count |
|---|---|
| Basic (nested) | 42010 |
| Flat (list) | 42010 |
| Extended (recursive) | 42010 |
Look up a record
brgy = barangays.get(name="Tongmageng")
print(brgy.region) # Bangsamoro Autonomous Region In Muslim Mindanao (BARMM)
print(brgy.province) # Tawi-Tawi
print(brgy.psgc_id) # 1907005010barangay search TongmagengPandas export
from barangay import barangays
df = barangays.to_frame()
print(df.columns.tolist())
# ['name', 'type', 'psgc_id', 'parent_psgc_id', 'nicknames', 'extensions',
# 'region', 'province', 'highly_urbanized_city', 'independent_component_city',
# 'component_city', 'municipality', 'submunicipality',
# 'special_geographic_area', 'barangay']
print(df.shape) # (42010, 15)barangay export --model flat --format json --output data.jsonHierarchy traversal
brgy = barangays.get(name="Tongmageng")
print(brgy.parent) # <municipality: Sitangkai (1907005000)>
print(brgy.ancestors) # [municipality, province, region]
manila = cities.get(name="City of Manila")
for child in manila.children[:3]:
print(child) # <submunicipality: Tondo I/II ...>, <submunicipality: Binondo ...>, ...Address validation
from barangay import validate, validate_many
v = validate("Tongmageng, Sitangkai, Tawi-Tawi")
print(v.valid, v.matched_name, v.score) # True Tongmageng 100.0
results = validate_many(["Tongmageng, Sitangkai, Tawi-Tawi", "Nonexistent Place"])
for r in results:
print(f"{r.input!r} -> {'valid' if r.valid else 'invalid'}")barangay batch validate addresses.txtFuzzy search
from barangay import search_fuzzy
for r in search_fuzzy("Tongmageng"):
print(f"{r.name} ({r.psgc_id}) — score: {r.score}")barangay search "Tongmageng"Output:
| Region | Province | Municipality | Barangay | rphicmsgb | PSGC ID | Score |
|---|---|---|---|---|---|---|
| Bangsamoro Autonomous Region In Muslim Mindanao (BARMM) | Tawi-Tawi | Sitangkai | Tongmageng | rp000m00b | 1907005010 | 100.0 |
| Region V (Bicol Region) | Camarines Norte | Talisay | Itomang | rp000m00b | 0501611007 | 70.6 |
| Bangsamoro Autonomous Region In Muslim Mindanao (BARMM) | Basilan | Sumisip | Tongsengal | rp000m00b | 1900705025 | 70.0 |
| MIMAROPA Region | Palawan | Cuyo | Tenga-tenga | rp000m00b | 1705310017 | 70.0 |
| Region IX (Zamboanga Peninsula) | Sulu | Pangutaran | Tonggasang | rp000m00b | 0906608017 | 70.0 |
:::
The rphicmsgb column is a 9-character hierarchy indicator marking which levels resolve for each result (see the CLI reference). Blank levels are omitted from the table automatically.
import barangay
barangay.use_version("2025-07-08")
brgy = barangay.barangays.lookup("1907005010")
barangay.use_version(None) # back to latestbarangay info versionOutput:
Current version: 2026-04-13
Available dates: 2022-04-29, 2022-11-08, 2023-01-25, 2023-04-18, 2023-08-15, 2023-10-24, 2024-01-23, 2024-04-23, 2024-05-08, 2024-07-12, 2024-10-18, 2025-01-30, 2025-04-23, 2025-07-08, 2025-08-29, 2025-10-13, 2026-01-13, 2026-04-13