Skip to main content

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+.

PyPI License: MIT 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

us_home_safety_score-1.0.1.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

us_home_safety_score-1.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file us_home_safety_score-1.0.1.tar.gz.

File metadata

  • Download URL: us_home_safety_score-1.0.1.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for us_home_safety_score-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cff83b128f89c0b5907478c8c43af46172a9409a5839e96f721af96ee79c851f
MD5 cb8557a9de6483b0de76b5af8d88990b
BLAKE2b-256 1bc6a597c8f6630f4cc49177839118d08ce9b3cf6af0e955b0528cdefb8166d6

See more details on using hashes here.

File details

Details for the file us_home_safety_score-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for us_home_safety_score-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 28830e5af06123cb4111a276dba30bebbe236c869b43867fca889037b33a6c59
MD5 80f98d179b84931ae164057baa30f42a
BLAKE2b-256 db98c518ed4ea9120a992671b06ce0ee4ad0cf6304643c197be36403e61956c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page