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
Metadata
Release files for us-home-safety-score 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| us_home_safety_score-1.0.2.tar.gz | 11.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| us_home_safety_score-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.7 kB
Release files / us_home_safety_score-1.0.2.tar.gz
| Download URL | us_home_safety_score-1.0.2.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2d11a3928b03413873588d80ef4259edf67fd6a0eaa2f0a9cab640963d883850
|
|
BLAKE2b-256 checksum How to use checksums |
83478db54df6dcf2a7fda8a64dbefa7b076b2a858e4e1f7f7bcc4efc8f954a72
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / us_home_safety_score-1.0.2-py3-none-any.whl
| Download URL | us_home_safety_score-1.0.2-py3-none-any.whl |
|---|---|
| Size | 8.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52360add1a6dae744a030ef87e501d75c43ab6579d972881354277d33662eb52
|
|
BLAKE2b-256 checksum How to use checksums |
83d1881cb068df69332c6516553dac86b6f4f3411240ec7abe7460c10e51bd24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|