fundapi — 基金数据 API 官方 Python SDK
净值 / 档案 / 季报持仓 / 基金经理 / 排行 / 公告 / 分红 / 交易规则 / 评级 / 组合穿透 —— 19 个端点,免费端点无需 Key。
中文 · English
pip install fundapi
这是什么
基金数据 API 的官方 Python SDK —— 19 个端点对应 19 个方法:鉴权、重试(含 429 自动退避)、错误映射、基金代码规范化、返回解析都由 SDK 处理,一行方法拿到结构化数据。
from fundapi import FundAPI
api = FundAPI(key="cf-你的Key") # 或用环境变量 FUND_KEY
print(api.fund_profile("110022")) # 基金档案
3 个端点无需 Key(装上就能调):fund_search · fund_profile · fund_screener_options。其余需要 Key(获取)。
30 秒上手
from fundapi import FundAPI
api = FundAPI() # 免费端点,不用 Key
# 按名字搜基金(不知道代码时先搜)
for f in api.fund_search("易方达消费行业", limit=3)["list"]:
print(f["code"], f["name"])
# 基金档案
print(api.fund_profile("110022"))
付费端点:
api = FundAPI(key="cf-你的Key")
print(api.fund_nav("110022", size=5)) # 历史净值
print(api.fund_rating("110022")) # 评级
方法一览(19 个,与 MCP 工具同名)
| 方法 | 端点 | 档位 |
|---|---|---|
fund_search(q, limit=20) |
搜索基金 | 免费 |
fund_profile(code) |
基金档案 | 免费 |
fund_screener_options() |
筛选项字典 | 免费 |
fund_nav(code, page=1, size=20, start="", end="") |
历史净值 | 专业版 |
fund_holdings(code, year="", quarter="") |
季报持仓 | 专业版 |
fund_managers(code) |
现任经理 | 专业版 |
fund_rank(ft="all", sort="1y", order="desc", page=1, size=50) |
全市场排行 | 专业版 |
fund_notices(code, page=1, size=20) |
基金公告 | 专业版 |
fund_estimate(code) |
当日估值 | 专业版 |
fund_dividends(code) |
历史分红 | 专业版 |
fund_trade_rule(code) |
交易规则 | 专业版 |
fund_rating(code, page=1, size=20) |
评级 | 专业版 |
fund_overlap(codes) |
多基金持仓重叠 | 机构版 |
fund_portfolio_xray(codes, weights) |
组合穿透到个股 | 机构版 |
fund_holding_changes(code, periods=4, top_n=10) |
持仓变动 | 机构版 |
fund_manager_history(code) |
基金经理历任 | 机构版 |
fund_portfolio_diagnose(codes, weights) |
组合诊断 | 机构版 |
fund_screener(...) |
条件筛选全市场 | 机构版 |
fund_compare(codes) |
多基金对比 | 机构版 |
返回结构
默认返回端点的 data 字段(结构因端点而异,见文档)。要完整信封(含 ok / tier / data 等):
api = FundAPI(raw=True)
错误处理
from fundapi import AuthError, RateLimitError, EmptyResultError, APIError
try:
api.fund_nav("110022")
except AuthError:
... # Key 无效 / 档位不足(去 https://fundapi.cn/pricing 升级)
except RateLimitError:
... # 超频,稍后再试
except EmptyResultError:
... # 当前无数据(不扣次数)
except APIError:
... # 其他错误,消息里带服务端原话
环境
- Python 3.9+
- 依赖:
requests
License
MIT
Metadata
Release files for fundapi 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fundapi-0.1.0.tar.gz | 12.4 kB | Without provenance | Details for fundapi-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fundapi-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for fundapi-0.1.0-py3-none-any.whl |
Total release size: 23.7 kB
Release files / fundapi-0.1.0.tar.gz
| Download URL | fundapi-0.1.0.tar.gz |
|---|---|
| Size | 12.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5a1082c82732628c934126be56054aadba57f12fb2be39e277ef9ad0d23ad428
|
|
BLAKE2b-256 checksum How to use checksums |
637a79ace8a25322287bbe5f51187065ce54f438c152164a9d16773d1cc81e70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / fundapi-0.1.0-py3-none-any.whl
| Download URL | fundapi-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6db961f5bfa6bb8e7a3a281fbedd61d85b490977e214c8c459126e16df1f783
|
|
BLAKE2b-256 checksum How to use checksums |
45f72ce61cb5ce53c349e88dcc4723ecd72eb4f390d0b9e2fcf7d556cee23d70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for fundapi 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.