datacommons-client by davila7/claude-code-templates
npx skills add https://github.com/davila7/claude-code-templates --skill datacommons-client提供对 Data Commons Python API v2 的全面访问,用于查询统计观测数据、探索知识图谱以及解析实体标识符。Data Commons 将来自人口普查局、卫生组织、环保机构和其他权威来源的数据聚合到一个统一的知识图谱中。
安装支持 Pandas 的 Data Commons Python 客户端:
uv pip install "datacommons-client[Pandas]"
对于不使用 Pandas 的基本用法:
uv pip install datacommons-client
Data Commons API 包含三个主要端点,每个端点都在专门的参考文件中有详细说明:
查询实体的时间序列统计数据。请参阅 references/observation.md 获取完整文档。
主要用例:
常见模式:
from datacommons_client import DataCommonsClient
client = DataCommonsClient()
# 获取最新人口数据
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06"], # 加利福尼亚州
date="latest"
)
# 获取时间序列
response = client.observation.fetch(
variable_dcids=["UnemploymentRate_Person"],
entity_dcids=["country/USA"],
date="all"
)
# 按层次结构查询
response = client.observation.fetch(
variable_dcids=["MedianIncome_Household"],
entity_expression="geoId/06<-containedInPlace+{typeOf:County}",
date="2020"
)
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
探索知识图谱内的实体关系和属性。请参阅 references/node.md 获取完整文档。
主要用例:
常见模式:
# 发现属性
labels = client.node.fetch_property_labels(
node_dcids=["geoId/06"],
out=True
)
# 导航层次结构
children = client.node.fetch_place_children(
node_dcids=["country/USA"]
)
# 获取实体名称
names = client.node.fetch_entity_names(
node_dcids=["geoId/06", "geoId/48"]
)
将实体名称、坐标或外部 ID 转换为 Data Commons ID (DCID)。请参阅 references/resolve.md 获取完整文档。
主要用例:
常见模式:
# 按名称解析
response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"],
entity_type="State"
)
# 按坐标解析
dcid = client.resolve.fetch_dcid_by_coordinates(
latitude=37.7749,
longitude=-122.4194
)
# 解析 Wikidata ID
response = client.resolve.fetch_dcids_by_wikidata_id(
wikidata_ids=["Q30", "Q99"]
)
大多数 Data Commons 查询遵循以下模式:
解析实体(如果从名称开始):
resolve_response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"]
)
dcids = [r["candidates"][0]["dcid"]
for r in resolve_response.to_dict().values()
if r["candidates"]]
发现可用变量(可选):
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"
)
处理结果:
# 作为字典
data = response.to_dict()
# 作为 Pandas DataFrame
df = response.to_observations_as_records()
统计变量在 Data Commons 中使用特定的命名模式:
常见变量模式:
Count_Person - 总人口Count_Person_Female - 女性人口UnemploymentRate_Person - 失业率Median_Income_Household - 家庭收入中位数Count_Death - 死亡人数Median_Age_Person - 年龄中位数发现方法:
# 检查实体有哪些可用变量
available = client.observation.fetch_available_statistical_variables(
entity_dcids=["geoId/06"]
)
# 或通过网页界面探索
# https://datacommons.org/tools/statvar
所有观测响应都与 Pandas 集成:
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all"
)
# 转换为 DataFrame
df = response.to_observations_as_records()
# 列:date, entity, variable, value
# 重塑以进行分析
pivot = df.pivot_table(
values='value',
index='date',
columns='entity'
)
对于 datacommons.org(默认):
export DC_API_KEY="your_key"client = DataCommonsClient(api_key="your_key")对于自定义 Data Commons 实例:
client = DataCommonsClient(url="https://custom.datacommons.org")每个端点的完整文档可在 references/ 目录中找到:
references/observation.md:完整的观测 API 文档,包含所有方法、参数、响应格式和常见用例references/node.md:用于图谱探索、属性查询和层次结构导航的完整节点 API 文档references/resolve.md:用于实体识别和 DCID 解析的完整解析 API 文档references/getting_started.md:包含端到端示例和常见模式的快速入门指南fetch_available_statistical_variables() 查看可查询的内容filter_facet_domains 确保数据来自同一来源references/ 目录中都有详尽的文档每周安装次数
138
仓库
GitHub 星标数
23.5K
首次出现
2026 年 1 月 21 日
安全审计
安装于
claude-code121
opencode114
cursor110
gemini-cli108
antigravity101
codex97
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.
Install the Data Commons Python client with Pandas support:
uv pip install "datacommons-client[Pandas]"
For basic usage without Pandas:
uv pip install datacommons-client
The 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=["MedianIncome_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
children = client.node.fetch_place_children(
node_dcids=["country/USA"]
)
# Get entity names
names = client.node.fetch_entity_names(
node_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
dcid = 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 entities (if starting with names):
resolve_response = client.resolve.fetch_dcids_by_name(
names=["California", "Texas"]
)
dcids = [r["candidates"][0]["dcid"]
for r in resolve_response.to_dict().values()
if r["candidates"]]
Discover available variables (optional):
variables = client.observation.fetch_available_statistical_variables(
entity_dcids=dcids
)
Query statistical data :
response = client.observation.fetch(
variable_dcids=["Count_Person", "UnemploymentRate_Person"],
entity_dcids=dcids,
date="latest"
)
Process results :
# As dictionary
data = response.to_dict()
# As Pandas DataFrame
df = response.to_observations_as_records()
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/statvar
All observation responses integrate with Pandas:
response = client.observation.fetch(
variable_dcids=["Count_Person"],
entity_dcids=["geoId/06", "geoId/48"],
date="all"
)
# Convert to DataFrame
df = response.to_observations_as_records()
# Columns: date, entity, variable, value
# Reshape for analysis
pivot = df.pivot_table(
values='value',
index='date',
columns='entity'
)
For datacommons.org (default):
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:
references/observation.md : Complete Observation API documentation with all methods, parameters, response formats, and common use casesreferences/node.md : Complete Node API documentation for graph exploration, property queries, and hierarchy navigationreferences/resolve.md : Complete Resolve API documentation for entity identification and DCID resolutionreferences/getting_started.md : Quickstart guide with end-to-end examples and common patternsfetch_available_statistical_variables() to see what's queryablefilter_facet_domains to ensure data from the same sourcereferences/ directoryWeekly Installs
138
Repository
GitHub Stars
23.5K
First Seen
Jan 21, 2026
Security Audits
Gen Agent Trust HubWarnSocketPassSnykFail
Installed on
claude-code121
opencode114
cursor110
gemini-cli108
antigravity101
codex97
DOCX文件创建、编辑与分析完整指南 - 使用docx-js、Pandoc和Python脚本
51,800 周安装