跳到主要内容
Socrata 提供了城市开放数据的 API。 对于像 旧金山犯罪数据 这样的数据集,请查看右上角的 API 选项卡。 这为您提供了 数据集标识符 使用数据集标识符可以获取给定城市 ID (data.sfgov.org) 的特定表格 - 例如,旧金山 311 数据vw6y-z8j6 例如,旧金山警方数据tmnf-yvry
pip install -qU  sodapy
from langchain_community.document_loaders import OpenCityDataLoader
dataset = "vw6y-z8j6"  # 311 data
dataset = "tmnf-yvry"  # crime data
loader = OpenCityDataLoader(city_id="data.sfgov.org", dataset_id=dataset, limit=2000)
docs = loader.load()
WARNING:root:Requests made without an app_token will be subject to strict throttling limits.
eval(docs[0].page_content)
{'pdid': '4133422003074',
 'incidntnum': '041334220',
 'incident_code': '03074',
 'category': 'ROBBERY',
 'descript': 'ROBBERY, BODILY FORCE',
 'dayofweek': 'Monday',
 'date': '2004-11-22T00:00:00.000',
 'time': '17:50',
 'pddistrict': 'INGLESIDE',
 'resolution': 'NONE',
 'address': 'GENEVA AV / SANTOS ST',
 'x': '-122.420084075249',
 'y': '37.7083109744362',
 'location': {'type': 'Point',
  'coordinates': [-122.420084075249, 37.7083109744362]},
 ':@computed_region_26cr_cadq': '9',
 ':@computed_region_rxqg_mtj9': '8',
 ':@computed_region_bh8s_q3mv': '309'}

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.