You need ZIP-code crime context in your app this week. By the end of this guide you’ll query the Crime Data By ZipCode API on Zyla API Hub, parse the response in Python, and wire it into your workflow or AI agent with minimal overhead.
What you’ll build and why this API
The Crime Data By ZipCode API returns a compact, developer-friendly JSON with an Overall Crime Grade plus graded breakdowns for violent, property, and other crimes for a given U.S. ZIP code. It also includes nearby ZIP comparisons and similar-population comparisons so you can put a location into context quickly.
Typical uses include:
- Enriching real estate listings with local crime grades.
- Pre-qualifying service coverage or pricing by area risk bands.
- Adding ZIP-level risk context to insurance, logistics, or marketplace workflows.
- Showing users quick comparisons to nearby areas inside a map UI.
This guide focuses on the single path available on the listing: Get Crime Rates by ZIP. We’ll call it directly, parse the JSON, and discuss safe handling patterns.
Getting started on Zyla API Hub
Zyla API Hub is a marketplace of production-ready APIs with a single account, API key, and subscription model across listings. To begin:
- Open the Crime Data By ZipCode API page: Crime Data By ZipCode API.
- Click Subscribe or Start Free Trial when available. This listing uses a subscription + quota model (not pay-per-call). First API: 7-day trial or 50 requests. No Free Plan. Check the API page for current access options and pricing.
- After subscribing, get your API key from your Zyla dashboard.
If you don’t have an account yet, create one here: Register. Explore more APIs any time on zylalabs.com.
API overview: paths, method, and parameters
The Crime Data By ZipCode API provides one path on this listing.
- Path: Get Crime Rates by ZIP
- Method: GET
- URL: https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip
- Query parameter:
- zip (number, required): ZIP code to analyze. Example: 01370
- Auth: Authorization: Bearer YOUR_API_KEY
Response: a JSON object with high-level grades and detailed breakdowns. Field names are returned as human-readable labels (for example, “Overall Crime Grade”, “Violent Crime Rates”, “Theft”), and numeric values are encoded as strings in the sample response. Do not assume units or normalization; use the fields as provided. If you need to transform them for display, treat them as strings or convert cautiously.
Make your first request
Below is the official cURL you can copy and run immediately after replacing YOUR_API_KEY.
cURL
curl -s -X GET "https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip?zip=01370" \
-H "Authorization: Bearer YOUR_API_KEY"
Python (requests)
import os
import requests
API_KEY = os.getenv("ZYLALABS_API_KEY", "YOUR_API_KEY")
url = "https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip"
params = {"zip": "01370"}
headers = {"Authorization": f"Bearer {API_KEY}"}
resp = requests.get(url, params=params, headers=headers, timeout=20)
resp.raise_for_status()
data = resp.json()
# Extract high-value fields for your UI or workflow
overall = data.get("Overall", {})
zipcode = overall.get("Zipcode")
overall_grade = overall.get("Overall Crime Grade")
violent_grade = overall.get("Violent Crime Grade")
property_grade = overall.get("Property Crime Grade")
other_grade = overall.get("Other Crime Grade")
print(f"ZIP: {zipcode}")
print(f"Overall Grade: {overall_grade}")
print(f"Violent: {violent_grade} | Property: {property_grade} | Other: {other_grade}")
# Example: pull totals from the 'Crime BreakDown' list, if present
breakdown = data.get("Crime BreakDown", [])
totals = {}
for section in breakdown:
# Each section is shaped like:
# { "Violent Crime Rates": {...}, "0": {"Total Violent Crime": "...", "Total Violent Crime Score": "(...)" } }
for key, value in section.items():
if key == "0" and isinstance(value, dict):
for k, v in value.items():
if "Total" in k:
totals[k] = v
print("Totals:", totals)
# Optional: get a couple of nearby ZIP comparisons for quick display
nearby = data.get("Crime Rates Nearby", [])
for entry in nearby[:3]:
nz = entry.get("Nearby Zip")
ogr = entry.get("Overall Crime Grade")
print(f"Nearby {nz}: Overall {ogr}")
Official sample response
JSON
{"Overall":{"Zipcode":"01370","Overall Crime Grade":"B","Violent Crime Grade":"C-","Property Crime Grade":"B","Other Crime Grade":"B"},"Crime BreakDown":[{"Violent Crime Rates":{"Assault":"2.759","Robbery":"0.4627","Rape":"0.5506","Murder":"0.0218"},"0":{"Total Violent Crime":"3.795","Total Violent Crime Score":"(C-)"}},{"Property Crime Rates":{"Theft":"8.498","Vehicle Theft":"0.6988","Burglary":"1.563","Arson":"0.0619"},"0":{"Total Property Crime":"10.82","Total Property Crime Score":"(B)"}},{"Other Crime Rates":{"Kidnapping":"0.1303","Drug Crimes":"1.553","Vandalism":"3.749","Identity Theft":"0.4203","Animal Cruelty":"0.0490"},"0":{"Total \"Other\" Rate":"5.902","Total \"Other\" Score":"(B)"}}],"Crime Rates Nearby":[{"Nearby Zip":"01338, MA","Overall Crime Grade":"B-","Violent Crime Grade":"D","Property Crime Grade":"B-"},{"Nearby Zip":"01340, MA","Overall Crime Grade":"A-","Violent Crime Grade":"A-","Property Crime Grade":"B"},{"Nearby Zip":"01341, MA","Overall Crime Grade":"A","Violent Crime Grade":"C-","Property Crime Grade":"A"},{"Nearby Zip":"01301, MA","Overall Crime Grade":"C+","Violent Crime Grade":"C-","Property Crime Grade":"C"},{"Nearby Zip":"01330, MA","Overall Crime…
Key takeaways from the sample:
- Overall: Includes “Zipcode”, “Overall Crime Grade”, and per-category grades for Violent, Property, and Other.
- Crime BreakDown: An array of sections. Each section contains a set of specific crime rates (e.g., “Theft”, “Burglary”, “Assault”) and a nested object labeled “0” holding totals and a category score like “Total Property Crime Score”. Treat keys literally as they appear.
- Crime Rates Nearby: A list of nearby ZIPs with their overall and category grades, useful for at-a-glance comparisons.
- Similar Population Crime Rates: Similar comparisons for areas with comparable population characteristics, returned as another list of grade triplets.
Implementation notes that save time
- Authentication: Always send Authorization: Bearer YOUR_API_KEY in the header. Do not pass keys in query params.
- Parameter type: zip is required and numeric per documentation. If you’re capturing user input, validate and strip non-numeric characters before sending.
- Field names: The API returns human-readable keys with spaces (e.g., “Property Crime Grade”). If you map these to internal identifiers, create a stable translation layer in code.
- Numeric values: Crime rate values in the example are strings (e.g., "8.498"). Convert carefully if you need numeric operations. When displaying, keep formatting consistent with your UI standards.
- Caching: If your use case tolerates slight staleness, cache by ZIP for a reasonable TTL to reduce calls. Determine your TTL based on how often you refresh your data sources; the API documentation doesn’t specify an update cadence.
- Error handling: Check HTTP status codes and handle non-200s. For 4xx, verify the zip parameter and auth header. For 5xx, apply a short exponential backoff.
- Internationalization: Keys include U.S.-centric terms and MA/FL/AR abbreviations in examples. If your app is international, label clearly as U.S. ZIP data.
End-to-end Python integration sketch
Here’s a small utility you can drop into your service layer to fetch and normalize the primary grades and a few breakdown totals for any provided ZIP code string. Adapt to your framework (FastAPI, Flask, Django) as needed.
Python (utility function)
from typing import Any, Dict, Optional, Tuple
import requests
class CrimeApiClient:
def __init__(self, api_key: str, timeout: int = 15):
self.api_key = api_key
self.timeout = timeout
self.base_url = "https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip"
def get_zip_crime(self, zip_code: str) -> Dict[str, Any]:
headers = {"Authorization": f"Bearer {self.api_key}"}
params = {"zip": str(zip_code)}
r = requests.get(self.base_url, headers=headers, params=params, timeout=self.timeout)
r.raise_for_status()
return r.json()
def extract_grades(payload: Dict[str, Any]) -> Dict[str, Optional[str]]:
o = payload.get("Overall", {})
return {
"zipcode": o.get("Zipcode"),
"overall_grade": o.get("Overall Crime Grade"),
"violent_grade": o.get("Violent Crime Grade"),
"property_grade": o.get("Property Crime Grade"),
"other_grade": o.get("Other Crime Grade"),
}
def extract_totals(payload: Dict[str, Any]) -> Dict[str, str]:
totals = {}
for section in payload.get("Crime BreakDown", []):
zero = section.get("0")
if isinstance(zero, dict):
for k, v in zero.items():
if k.startswith("Total "):
totals[k] = v
return totals
# Example usage:
# client = CrimeApiClient(api_key="YOUR_API_KEY")
# data = client.get_zip_crime("01370")
# grades = extract_grades(data)
# totals = extract_totals(data)
# print(grades, totals)
Practical use cases you can ship this week
- Property search: For each listing ZIP, display an “Overall Crime Grade” badge and a hover tooltip with Violent/Property/Other grades plus two “Crime Rates Nearby” entries.
- Risk banding: Map grades to internal tiers (e.g., A–B = low risk, C = medium, D–F = high). Use this to gate offers or require additional verification.
- Service routing: For logistics or on-site services, flag ZIPs with weaker grades for extra scheduling buffers or staffing policies.
- Lead qualification: Before allocating sales resources, enrich the lead’s ZIP to tailor messaging and prioritize outreach.
Calling the API from an AI agent via MCP
Every API on Zyla API Hub can be called from MCP-compatible clients (Claude Code, Cursor, Windsurf, and others) through the MCP endpoint at:
The endpoint is compatible with MCP tooling; provide your Zyla API key and instruct the agent to perform an HTTP GET to the Crime Data By ZipCode API path using the same Authorization header shown above. In prompts or tool configuration, specify:
- Method: GET
- URL: https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip?zip=01370 (or your user-supplied ZIP)
- Headers: Authorization: Bearer YOUR_API_KEY
Have the agent extract “Overall Crime Grade” and a few “Crime Rates Nearby” for quick comparisons. Keep a consistent representation of the returned labels with spaces.
Link checklist and where to go next
- API listing: Crime Data By ZipCode API
- Create your account: Register
- MCP docs and endpoint: MCP
- Main hub: zylalabs.com
FAQ
Does the API require an Authorization header?
Yes. Send Authorization: Bearer YOUR_API_KEY on every request.
What parameters are required?
The Get Crime Rates by ZIP path requires the zip parameter (numeric). Example: zip=01370.
What’s the endpoint URL I should call from my service?
Use GET https://zylalabs.com/api/824/crime-data-by-zipcode-api/583/get-crime-rates-by-zip with the zip query parameter and the Authorization header.
How are the grades represented?
Grades are strings like “A”, “B”, “C-”, etc., for Overall and per-category. Rates in the sample are strings as well. Use the fields as returned and convert to numbers only if you need to compute.
Is there a free plan?
This listing uses a subscription + quota model. First API: 7-day trial or 50 requests. No Free Plan. Check the API page for current access options and pricing.
Ready to integrate? Create your Zyla account, get your API key, and ship your ZIP crime lookup in under an hour: Register. Explore more production-ready APIs anytime on zylalabs.com.
Official API response
{"Overall":{"Zipcode":"01370","Overall Crime Grade":"B","Violent Crime Grade":"C-","Property Crime Grade":"B","Other Crime Grade":"B"},"Crime BreakDown":[{"Violent Crime Rates":{"Assault":"2.759","Robbery":"0.4627","Rape":"0.5506","Murder":"0.0218"},"0":{"Total Violent Crime":"3.795","Total Violent Crime Score":"(C-)"}},{"Property Crime Rates":{"Theft":"8.498","Vehicle Theft":"0.6988","Burglary":"1.563","Arson":"0.0619"},"0":{"Total Property Crime":"10.82","Total Property Crime Score":"(B)"}},{"Other Crime Rates":{"Kidnapping":"0.1303","Drug Crimes":"1.553","Vandalism":"3.749","Identity Theft":"0.4203","Animal Cruelty":"0.0490"},"0":{"Total \"Other\" Rate":"5.902","Total \"Other\" Score":"(B)"}}],"Crime Rates Nearby":[{"Nearby Zip":"01338, MA","Overall Crime Grade":"B-","Violent Crime Grade":"D","Property Crime Grade":"B-"},{"Nearby Zip":"01340, MA","Overall Crime Grade":"A-","Violent Crime Grade":"A-","Property Crime Grade":"B"},{"Nearby Zip":"01341, MA","Overall Crime Grade":"A","Violent Crime Grade":"C-","Property Crime Grade":"A"},{"Nearby Zip":"01301, MA","Overall Crime Grade":"C+","Violent Crime Grade":"C-","Property Crime Grade":"C"},{"Nearby Zip":"01330, MA","Overall Crime Grade":"A","Violent Crime Grade":"A-","Property Crime Grade":"A"},{"Nearby Zip":"01346, MA","Overall Crime Grade":"A","Violent Crime Grade":"C","Property Crime Grade":"A"},{"Nearby Zip":"01339, MA","Overall Crime Grade":"A-","Violent Crime Grade":"C","Property Crime Grade":"A"},{"Nearby Zip":"01342, MA","Overall Crime Grade":"A","Violent Crime Grade":"B+","Property Crime Grade":"A+"},{"Nearby Zip":"01376, MA","Overall Crime Grade":"B-","Violent Crime Grade":"C+","Property Crime Grade":"B-"},{"Nearby Zip":"01337, MA","Overall Crime Grade":"A","Violent Crime Grade":"B-","Property Crime Grade":"A"}],"Similar Population Crime Rates":[{"Similar Zip":"34217, FL","Overall Crime Grade":"A-","Violent Crime Grade":"C+","Property Crime Grade":"C+"},{"Similar Zip":"72046, AR","Overall Crime Grade":"F","Violent Crime Grade":"D-","Property Crime Grade":"D-"},{"Similar Zip":"52778, IA","Overall Crime Grade":"B","Violent Crime Grade":"A-","Property Crime Grade":"A-"},{"Similar Zip":"54126, WI","Overall Crime Grade":"A","Violent Crime Grade":"A+","Property Crime Grade":"A+"},{"Similar Zip":"02715, MA","Overall Crime Grade":"A+","Violent Crime Grade":"A-","Property Crime Grade":"A-"},{"Similar Zip":"67025, KS","Overall Crime Grade":"B-","Violent Crime Grade":"B+","Property Crime Grade":"B+"},{"Sim…
Official API response
{"Overall":{"Zipcode":"01370","Overall Crime Grade":"B","Violent Crime Grade":"C-","Property Crime Grade":"B","Other Crime Grade":"B"},"Crime BreakDown":[{"Violent Crime Rates":{"Assault":"2.759","Robbery":"0.4627","Rape":"0.5506","Murder":"0.0218"},"0":{"Total Violent Crime":"3.795","Total Violent Crime Score":"(C-)"}},{"Property Crime Rates":{"Theft":"8.498","Vehicle Theft":"0.6988","Burglary":"1.563","Arson":"0.0619"},"0":{"Total Property Crime":"10.82","Total Property Crime Score":"(B)"}},{"Other Crime Rates":{"Kidnapping":"0.1303","Drug Crimes":"1.553","Vandalism":"3.749","Identity Theft":"0.4203","Animal Cruelty":"0.0490"},"0":{"Total \"Other\" Rate":"5.902","Total \"Other\" Score":"(B)"}}],"Crime Rates Nearby":[{"Nearby Zip":"01338, MA","Overall Crime Grade":"B-","Violent Crime Grade":"D","Property Crime Grade":"B-"},{"Nearby Zip":"01340, MA","Overall Crime Grade":"A-","Violent Crime Grade":"A-","Property Crime Grade":"B"},{"Nearby Zip":"01341, MA","Overall Crime Grade":"A","Violent Crime Grade":"C-","Property Crime Grade":"A"},{"Nearby Zip":"01301, MA","Overall Crime Grade":"C+","Violent Crime Grade":"C-","Property Crime Grade":"C"},{"Nearby Zip":"01330, MA","Overall Crime Grade":"A","Violent Crime Grade":"A-","Property Crime Grade":"A"},{"Nearby Zip":"01346, MA","Overall Crime Grade":"A","Violent Crime Grade":"C","Property Crime Grade":"A"},{"Nearby Zip":"01339, MA","Overall Crime Grade":"A-","Violent Crime Grade":"C","Property Crime Grade":"A"},{"Nearby Zip":"01342, MA","Overall Crime Grade":"A","Violent Crime Grade":"B+","Property Crime Grade":"A+"},{"Nearby Zip":"01376, MA","Overall Crime Grade":"B-","Violent Crime Grade":"C+","Property Crime Grade":"B-"},{"Nearby Zip":"01337, MA","Overall Crime Grade":"A","Violent Crime Grade":"B-","Property Crime Grade":"A"}],"Similar Population Crime Rates":[{"Similar Zip":"34217, FL","Overall Crime Grade":"A-","Violent Crime Grade":"C+","Property Crime Grade":"C+"},{"Similar Zip":"72046, AR","Overall Crime Grade":"F","Violent Crime Grade":"D-","Property Crime Grade":"D-"},{"Similar Zip":"52778, IA","Overall Crime Grade":"B","Violent Crime Grade":"A-","Property Crime Grade":"A-"},{"Similar Zip":"54126, WI","Overall Crime Grade":"A","Violent Crime Grade":"A+","Property Crime Grade":"A+"},{"Similar Zip":"02715, MA","Overall Crime Grade":"A+","Violent Crime Grade":"A-","Property Crime Grade":"A-"},{"Similar Zip":"67025, KS","Overall Crime Grade":"B-","Violent Crime Grade":"B+","Property Crime Grade":"B+"},{"Sim…