alterlab-datacommons — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited alterlab-datacommons (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Provides comprehensive access to the Data Commons Python API v2 for querying statistical observations, exploring the knowledge graph, and resolving entity identifiers. Data Commons aggregates data from census bureaus, health organizations, environmental agencies, and other authoritative sources into a unified knowledge graph.
Verified against datacommons-client 2.1.6 (current as of 2026-09; Python ≥ 3.10). This is the V2 client (package datacommons_client), not the legacy datacommons (V1) package — the two have different APIs; do not mix them. Keyword names matter: the place-hierarchy helpers take place_dcids, fetch_entity_names takes entity_dcids, and fetch_property_values takes properties — passing node_dcids to them raises TypeError.
| Scenario | Use Instead |
|---|---|
| A specific FRED economic series (GDP, CPI, interest rates) with vintage/revision data | alterlab-fred |
| U.S. Treasury fiscal data (debt, spending, revenue) | alterlab-usfiscaldata |
| NCI Imaging Data Commons (CT/MR/pathology images) — a different "Data Commons" | alterlab-imaging-data-commons |
| Spatial joins, buffers, or mapping of geometries | alterlab-geopandas |
Install the Data Commons V2 client with Pandas support (extra is lowercase pandas):
uv pip install "datacommons-client[pandas]"For basic usage without Pandas:
uv pip install datacommons-clientThe Data Commons API consists of three main endpoints, each detailed in dedicated reference files:
Query time-series statistical data for entities. See references/observation.md for comprehensive documentation.
Primary use cases:
Common patterns:
from datacommons_client import DataCommonsClient
client = DataCommonsClient()
# Get latest population data
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06"], # California
date="latest"
)
# Get time series
response = client.observation.fetch(
variable_dcids=["UnemploymentRate_Person"],
entity_dcids=["country/USA"],
date="all"
)
# Query by hierarchy
response = client.observation.fetch(
variable_dcids=["Median_Income_Household"],
entity_expression="geoId/06<-containedInPlace+{typeOf:County}",
date="2020"
)Explore entity relationships and properties within the knowledge graph. See references/node.md for comprehensive documentation.
Primary use cases:
Common patterns:
# Discover properties
labels = client.node.fetch_property_labels(
node_dcids=["geoId/06"],
out=True
)
# Navigate hierarchy (dict: DCID -> list of {"dcid", "name", "types"})
children = client.node.fetch_place_children(
place_dcids="country/USA",
children_type="State",
)
# Get entity names (dict: DCID -> Name(value=..., language=...))
names = client.node.fetch_entity_names(
entity_dcids=["geoId/06", "geoId/48"]
)Translate entity names, coordinates, or external IDs into Data Commons IDs (DCIDs). See references/resolve.md for comprehensive documentation.
Primary use cases:
Common patterns:
# Resolve by name
response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"],
entity_type="State"
)
# Resolve by coordinates (returns a ResolveResponse, not a bare DCID)
coord_response = client.resolve.fetch_dcid_by_coordinates(
latitude="37.7749",
longitude="-122.4194"
)
# Resolve Wikidata IDs
response = client.resolve.fetch_dcids_by_wikidata_id(
wikidata_ids=["Q30", "Q99"]
)Most Data Commons queries follow this pattern:
resolve_response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"], entity_type="State"
)
# to_dict() -> {"entities": [{"node": "California", "candidates": [{"dcid": ...}]}, ...]}
dcids = [e["candidates"][0]["dcid"]
for e in resolve_response.to_dict()["entities"]
if e.get("candidates")]
# or: resolve_response.to_flat_dict() -> {"California": "geoId/06", ...}
# (a list of DCIDs when the name is ambiguous) variables = client.observation.fetch_available_statistical_variables(
entity_dcids=dcids
) response = client.observation.fetch(
variable_dcids=["Count_Person", "UnemploymentRate_Person"],
entity_dcids=dcids,
date="latest"
) # As dictionary
data = response.to_dict()
# As flat records (date, entity, variable, value + facet metadata).
# to_observation_records() returns a pydantic model — dump it before
# building a DataFrame, or the columns come out as 0..N.
records = response.to_observation_records().model_dump()
df = pd.DataFrame(records)To skip the manual conversion, the client also exposes a dedicated DataFrame accessor that runs the same query and returns a tidy DataFrame directly:
df = client.observations_dataframe(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all",
)Statistical variables use specific naming patterns in Data Commons:
Common variable patterns:
Count_Person - Total populationCount_Person_Female - Female populationUnemploymentRate_Person - Unemployment rateMedian_Income_Household - Median household incomeCount_Death - Death countMedian_Age_Person - Median ageDiscovery methods:
# Check what variables are available for an entity
available = client.observation.fetch_available_statistical_variables(
entity_dcids=["geoId/06"]
)
# Or explore via the web interface
# https://datacommons.org/tools/statvarThe idiomatic path is the client's observations_dataframe() accessor, which mirrors observation.fetch() arguments but returns a tidy DataFrame in one call (requires the pandas extra):
df = client.observations_dataframe(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all",
)
# Columns: date, entity, variable, value (plus facet/provenance columns)
# Reshape for analysis
pivot = df.pivot_table(
values='value',
index='date',
columns='entity'
)For every entity of a type under a parent place, pass entity_dcids="all" with entity_type and parent_entity:
df = client.observations_dataframe(
variable_dcids=["Median_Income_Household"],
date="latest",
entity_dcids="all",
entity_type="County",
parent_entity="geoId/06",
)If you already have a response object, flatten it with to_observation_records() (singular "observation"; there is no to_observations_as_records) and dump it:
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all",
)
df = pd.DataFrame(response.to_observation_records().model_dump())For datacommons.org (default):
HTTP 401 UNAUTHENTICATED); name resolution currently answers without one
export DC_API_KEY="your_key"client = DataCommonsClient(api_key="your_key")For custom Data Commons instances:
client = DataCommonsClient(url="https://custom.datacommons.org")Comprehensive documentation for each endpoint is available in the references/ directory:
fetch_available_statistical_variables() to see what's queryablefilter_facet_domains to ensure data from the same sourcereferences/ directoryscripts/query_datacommons.py — runnable helper for the Data Commons REST v2 API (needs a free key in DC_API_KEY):
python scripts/query_datacommons.py resolve "California" --type State
python scripts/query_datacommons.py observe Count_Person geoId/06 --date latest~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.