phgeograpy (PH Geography)
phgeograpy is a python package that lists regions, provinces, and cities/municipalities in the Philippines.
Take a break from machine learning and chatbots. I created this project to explore and experience building a python package. This is my first python package. Yey! I'll also use this project to expore unit testing.
I'm working on a web app that needs location input broken down into regions, provinces, and cities/municipalities so I created this package to make it reusable and open source. Technically it's just a list, you can use it to create dropdown inputs or model choices in Django.
Regions
Regions are represented by phgeograpy.Region
class.
Sample usage:
import phgeograpy
regions = phgeograpy.regions()
print(regions[0].slug)
print(regions[0].name)
print(regions[0].description)
region = phgeograpy.regions('ncr')
Provinces
Provinces are represented by phgeograpy.Province
class.
Sample usage:
import phgeograpy
provinces = phgeograpy.provinces()
print(provinces[0].slug)
print(provinces[0].name)
region = provinces[0].region
region1_provinces = phgeograpy.provinces(region_slug='region1')
region1 = phgeograpy.regions('region1')
region1_provinces = region1.provinces()
Municipalities
Municipalities are represented by phgeograpy.Municipality
class. Cities are also included.
Sample Usage:
import phgeograpy
municipalities = phgeograpy.municipalities()
print(municipalities[0].slug)
print(municipalities[0].name)
print(municipalities[0].is_city)
print(municipalities[0].is_capital)
print(municipalities[0].is_huc)
province = municipalities[0].province
municipalities = province.municipalities()
Raw data
To get raw data, just set raw
parameter to True
.
Sample usage:
raw_regions = phgeograpy.regions(raw=True)
Note that all data below the area of your query will be included in the raw output (e.g. raw regions will include data for provinces and municipalities, raw provinces will include data for municipalities).