Compute residential Home Safety Scores (0-100, A-F) from federal data: EPA water violations, lead/copper levels, EPA radon zones, and FEMA flood claims. Python port of the npm package.
Project description
us-home-safety-score
Compute residential Home Safety Scores (0-100, A-F) from U.S. federal data. Zero dependencies. Pure Python 3.9+.
This is the Python port of the us-home-safety-score npm package. Both implementations produce identical scores for the same inputs (verified bit-for-bit across a 640-case grid, including rounding edge cases).
The Home Safety Score is a composite index that evaluates environmental risk for any U.S. ZIP code across four dimensions:
- Water quality — EPA SDWIS violation history
- Lead exposure — EPA Lead and Copper Rule sampling
- Radon risk — EPA county-level radon zones
- Flood risk — FEMA NFIP historical claims
Higher score = safer. It is the same algorithm used on ZipCheckup.com to score tens of thousands of ZIP codes.
Install
pip install us-home-safety-score
Quick Start
from us_home_safety_score import compute_safety_score
result = compute_safety_score({
"totalViolations": 3,
"healthViolations": 1,
"leadLevel": 0.008, # mg/L (90th percentile)
"radonZone": 2, # EPA zone: 1=High, 2=Moderate, 3=Low
"floodClaims": 25, # FEMA NFIP historical claims
})
print(result)
# {
# 'score': 67,
# 'grade': 'C',
# 'components': {
# 'water': {'score': 21, 'maxPoints': 25, 'weight': 0.25},
# 'lead': {'score': 18, 'maxPoints': 25, 'weight': 0.25},
# 'radon': {'score': 13, 'maxPoints': 25, 'weight': 0.25},
# 'flood': {'score': 15, 'maxPoints': 25, 'weight': 0.25},
# },
# 'componentCount': 4,
# }
Field names use camelCase (
totalViolations,leadLevel,floodClaims, …) to stay 1:1 with the npm package's input contract.
Scoring
| Component | Weight | Max Points | Source |
|---|---|---|---|
| Water quality | 25% (or 33%) | 25 (or 33) | EPA SDWIS violations, past 5 years |
| Lead/copper | 25% (or 33%) | 25 (or 33) | EPA Lead and Copper Rule, 90th-percentile |
| Radon | 25% (or 33%) | 25 (or 33) | EPA county radon zones |
| Flood | 25% | 25 | FEMA NFIP claims count |
When FEMA flood data is unavailable, the score falls back to a 3-component mode (each component worth 33 points instead of 25). Missing lead or radon data uses a neutral assumption (2/3 of max points) rather than penalizing or rewarding the location.
Grade thresholds: A ≥ 85, B ≥ 70, C ≥ 55, D ≥ 40, F < 40.
Full methodology: https://zipcheckup.com/about/home-safety-score/
API
| Function | Returns |
|---|---|
compute_safety_score(data) |
{score, grade, components, componentCount} |
compute_lead_risk(data) |
{risk, probability, exceedsActionLevel, description} |
compute_flood_risk(data) |
{risk, estimatedAnnualCost, claims, description} |
compute_compliance_risk(data) |
{risk, score, unresolved, description} |
compute_energy_burden(data) |
{burden, risk, description} |
score_to_grade(score) |
'A' … 'F' |
from us_home_safety_score import compute_lead_risk
compute_lead_risk({"leadLevel": 0.020})
# {'risk': 'high', 'probability': 0.85, 'exceedsActionLevel': True,
# 'description': 'Lead level exceeds the EPA action level (15 ppb). ...'}
Data sources
- EPA SDWIS — Safe Drinking Water Information System (violations, Lead and Copper Rule sampling)
- EPA Radon Zones — county-level radon potential map
- FEMA NFIP — National Flood Insurance Program claims
This package contains only the scoring logic — you supply the federal data inputs. Pre-joined per-ZIP data is available via the us-water-quality-data package and the ZipCheckup API.
License
MIT © ZipCheckup
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file us_home_safety_score-1.0.0.tar.gz.
File metadata
- Download URL: us_home_safety_score-1.0.0.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36aab535978a26500795d03f1ef484abc9200142d05d4d6a2cd1f5e9e9f7e439
|
|
| MD5 |
b89abe838855c5ac5f7b4873fd80fdcf
|
|
| BLAKE2b-256 |
63295a7475ee4140ff3ed5c501167abbd104e51cd54a04ced0b02426776aa338
|
File details
Details for the file us_home_safety_score-1.0.0-py3-none-any.whl.
File metadata
- Download URL: us_home_safety_score-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
334e42abd4338ce914f5f446e905ee2b046ad2b4817404d0831fedeb9df9586a
|
|
| MD5 |
e4c7f200cf2f465da758d06e5ec7bf88
|
|
| BLAKE2b-256 |
37032fd5cb0733ecc85f55d4524d003de3551fed53ebb0b5c0d175764a64ff9f
|