Validation (validate / validate_many)
Reference for validate() and validate_many(): validate Philippine address strings against the PSGC masterlist with fuzzy matching; ValidationResult properties.
Validate address strings against the PSGC masterlist using fuzzy matching. Use validate() for a single address and validate_many() for a batch.
from barangay import validate, validate_many
v = validate("Tongmageng, Sitangkai, Tawi-Tawi")
print(v.valid) # True
print(v.matched_name) # Tongmageng
print(v.matched_psgc_id) # 1907005010
print(v.score) # 100.0
results = validate_many([
"Tongmageng, Sitangkai, Tawi-Tawi",
"Brgy 291, City of Manila",
"Nonexistent Place",
])
for r in results:
print(f"{r.input!r} -> {'valid' if r.valid else 'invalid'}")
# 'Tongmageng, Sitangkai, Tawi-Tawi' -> valid
# 'Brgy 291, City of Manila' -> invalid
# 'Nonexistent Place' -> invalidvalidate() parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
address |
str |
— | Address string to validate |
threshold |
float |
95.0 |
Minimum score for a valid match |
as_of |
str \| None |
None |
Historical date |
Returns: ValidationResult
ValidationResult properties
| Property | Type | Description |
|---|---|---|
.input |
str |
Original input string |
.valid |
bool |
Whether a match was found above threshold |
.matched_name |
str \| None |
Name of the matched record |
.matched_psgc_id |
str \| None |
PSGC ID of the matched record |
.matched_record |
AdminDivRecord \| None |
Full matched record |
.score |
float \| None |
Confidence score |
validate_many() takes a list[str] of addresses and returns list[ValidationResult].
See also
- Search —
search_fuzzy() - Validate addresses how-to
- Address validation tutorial