Skip to main content

简体中文 | English

资源分享:对于想了解更多财经数据与量化投研的小伙伴,推荐一个专注于财经数据和量化研究的知识社区。 该社区提供相关文档和视频学习资源,汇集了各类财经数据源和量化投研工具的使用经验。 有兴趣深入学习的朋友可点此了解更多,也推荐大家关注微信公众号【数据科学实战】。

重磅推荐:AKQuant 是一款专为 量化投研 (Quantitative Research) 打造的高性能量化回测框架。它以 Rust 铸造极速撮合内核, 以 Python 链接数据与 AI 生态,旨在为量化投资者提供可靠高效的量化投研解决方案。参见AKQuant

工具推荐:期魔方是一款本地化期货量化分析工具,适合数据分析爱好者使用。无需复杂部署,支持数据分析和机器学习功能,研究功能免费开放。 如需了解更多信息可访问期魔方。

AKShare Logo

PyPI - Python Version PyPI PyPI Downloads Documentation Status Ruff akshare Checks Status Release Status MIT Licence

概览

AKShare 是基于 Python 的开源财经数据接口库,目标是让获取财经数据变得简单,需要 64 位的 Python 3.11.5 或更高版本。

Write less, get more!

  • 文档:中文文档
  • 供 AI 助手使用的 MCP 服务:AKTools 让 Claude、Cursor 等 MCP 客户端用自然语言获取 AKShare 的数据,见 AI 助手(MCP)
  • HTTP API:AKTools 还能把 AKShare 部署为 HTTP 服务,供其他编程语言调用

AI 助手(MCP)

AKShare 是一个 Python 库,本身不提供 MCP 服务。配套项目 AKTools 提供了 MCP 服务,并以 io.github.akfamily/aktools 登记在 MCP 官方注册表中。Claude Code、Claude Desktop、Cursor 等 AI 助手可以根据一句自然语言的提问查找并调用 AKShare 的全部接口,例如“贵州茅台 2024 年 10 月 8 日到 11 日的前复权日线行情”。

只需要安装 uv,不必另外安装其他软件:

claude mcp add aktools -- uvx --from aktools aktools-mcp

Claude Desktop、Cursor 等客户端的配置:

{
  "mcpServers": {
    "aktools": {
      "command": "uvx",
      "args": ["--from", "aktools", "aktools-mcp"]
    }
  }
}

Add AKTools MCP server to Cursor

AKTools 没有把约 950 个接口逐个登记为工具,而是提供 3 个通用工具,由 AI 助手依次调用:

工具 用途
search_interfaces 按关键词查找接口名
describe_interface 查看接口的参数、默认值与说明
get_data 调用接口,最多返回 max_rows 行(默认 100,最大 1000)

用 python -m aktools 启动的服务同时在 http://127.0.0.1:8080/mcp 以 Streamable HTTP 方式提供这 3 个工具。HTTP 方式、代理、访问令牌与局域网访问的设置见 MCP 使用指南。

安装

uv(推荐)

uv pip install akshare --upgrade

uv 的安装与虚拟环境的创建见 uv 环境配置。

pip

pip install akshare --upgrade

国内镜像

uv pip install akshare --upgrade --default-index https://pypi.tuna.tsinghua.edu.cn/simple
# 或者
pip install akshare --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple

使用

获取数据

代码:

import akshare as ak

stock_zh_a_hist_sina_df = ak.stock_zh_a_hist_sina(symbol="sz000001", period="daily", start_date="20170301", end_date="20231022", adjust="")
print(stock_zh_a_hist_sina_df)

输出:

            date   open   high  ...        amount  outstanding_share  turnover
0     2017-03-01   9.49   9.55  ...  3.301580e+08       1.691799e+10  0.002051
1     2017-03-02   9.51   9.54  ...  3.823959e+08       1.691799e+10  0.002386
2     2017-03-03   9.41   9.43  ...  3.219525e+08       1.691799e+10  0.002025
3     2017-03-06   9.40   9.46  ...  3.812123e+08       1.691799e+10  0.002391
4     2017-03-07   9.44   9.46  ...  2.777474e+08       1.691799e+10  0.001742
...          ...    ...    ...  ...           ...                ...       ...
1610  2023-10-16  11.00  11.03  ...  5.509887e+08       1.940555e+10  0.002585
1611  2023-10-17  11.01  11.05  ...  5.431709e+08       1.940555e+10  0.002543
1612  2023-10-18  10.99  11.02  ...  7.139799e+08       1.940555e+10  0.003359
1613  2023-10-19  10.91  10.92  ...  1.271915e+09       1.940555e+10  0.006127
1614  2023-10-20  10.55  10.67  ...  5.576186e+08       1.940555e+10  0.002711

[1615 rows x 9 columns]

搜索接口

AKShare 自带一份离线的接口登记,不必离开 Python、也不需要联网,就能按关键词查到接口。由大模型驱动的程序需要把一句描述对应到可调用的接口名时,这一功能尤其有用。

代码:

import akshare as ak

search_df = ak.search("可转债 实时行情", limit=5)
print(search_df)

# 单个接口的完整信息:参数、输出字段与调用示例
interface_info_dict = ak.interface_info("bond_cb_jsl")
print(interface_info_dict)

输出:

                     接口名    类目                                                       描述  有无文档   匹配分
0  bond_cb_realtime_sina  bond                                             新浪财经-沪深可转债数据  True  34.5
1            bond_cb_jsl  bond  集思录可转债实时数据,包含行情数据(涨跌幅,成交量和换手率等)及可转债基本信息(转股价,溢价率和到期收益率等)  True  28.5
2        bond_cb_info_em  bond                                    东方财富网-数据中心-新股数据-可转债详情  True  15.0
3        bond_cb_list_em  bond                                 东方财富网-数据中心-新股数据-可转债数据一览表  True  15.0
4       bond_cb_list_ths  bond                                             同花顺-数据中心-可转债  True  15.0

传入完整的接口名时,该接口总是排在第一位,可以用来确认一个记不太清的名称。搜索是关键词匹配而不是语义检索,能做什么、不能做什么见接口检索文档。

接口命名

接口名的结构是 <类目>_<市场或主体>_<主题>_<数据源>。以 stock_zh_a_hist_em 为例:类目 stock,市场 zh_a,主题 hist(历史行情),数据源 em(东方财富)。

  • 第一段是 ak.list_categories() 返回的 15 个类目之一:stock、index、fund、futures、option、bond、fx、macro、interest_rate、spot、energy、crypto、calendar、research、alternative
  • 最后一段通常是数据源,如 em、sina、ths、tx、cninfo、sse、szse,同一数据来自不同数据源时,接口名只有后缀不同
  • 行情接口中,名称里的 daily 表示只有日线;带 period 参数(daily、weekly、monthly)的接口叫 hist,如 stock_zh_a_hist_em 和 stock_zh_a_hist_sina

从 1.20.41 之前的版本升级

1.20.41 至 1.20.54 把所有接口统一到上面的命名规则:约 320 个接口改名(如 stock_zh_a_hist 改为 stock_zh_a_hist_em,stock_zh_index_daily 改为 index_zh_daily_sina),少数参数统一为 symbol、date、start_date、end_date,上游数据源已关闭的接口被移除。旧名称没有保留为别名,但调用时会提示去向:

import akshare as ak

ak.stock_zh_a_hist(symbol="000001")
# AttributeError: stock_zh_a_hist 已在 1.20.46 更名为 stock_zh_a_hist_em,请改用 ak.stock_zh_a_hist_em;…

ak.renamed_info("stock_zh_a_hist")
# {'name': 'stock_zh_a_hist', 'status': 'renamed', 'new_name': 'stock_zh_a_hist_em', 'version': '1.20.46', 'url': '…'}

用旧名称调用 ak.search 时,现在的名称也排在第一位。完整的新旧名称对照见更新日志末尾的接口更名一览表。

特点

  • 简单易用:一行代码获取数据
  • 便于扩展:容易与其他程序结合,定制自己的代码
  • 生态丰富:依托 Python 的数据科学生态

教程

  1. 项目概览
  2. 安装指导
  3. 接口检索
  4. AI 助手(MCP)
  5. 快速入门
  6. 数据字典
  7. 量化指标
  8. 常见问题
  9. 实盘交易

参与贡献

AKShare 仍在持续开发中,欢迎提交 issue 和 pull request:

  • 报告或修复问题
  • 提出需求或贡献新接口
  • 撰写或修订文档
  • 补充测试用例

提交 pull request 之前请先阅读贡献指南。

说明:本项目使用 Ruff 格式化代码

声明

  1. AKShare 提供的数据仅供学术研究使用;
  2. AKShare 提供的数据仅供参考,不构成任何投资建议;
  3. 基于 AKShare 做研究的投资者应当注意数据风险;
  4. AKShare 将坚持提供开源的财经数据;
  5. 受不可控因素影响,AKShare 的部分数据接口可能被移除;
  6. 请遵守 AKShare 使用的开源协议;
  7. 为其他编程语言和 AI 助手提供 HTTP API 与 MCP 服务:AKTools。

展示徽章

在项目的 README.md 中使用徽章:

[![Data: akshare](https://img.shields.io/badge/Data%20Science-AKShare-green)](https://github.com/akfamily/akshare)

在 README.rst 中使用徽章:

.. image:: https://img.shields.io/badge/Data%20Science-AKShare-green
    :target: https://github.com/akfamily/akshare

显示效果:

Data: akshare

引用

在论文或出版物中引用本项目时,请使用下面的 bibtex:

@misc{akshare,
    author = {Albert King and Yaojie Zhang},
    title = {AKShare},
    year = {2022},
    publisher = {GitHub},
    journal = {GitHub repository},
    howpublished = {\url{https://github.com/akfamily/akshare}},
}

致谢

特别感谢 FuShare 项目提供的学习机会;

特别感谢 TuShare 项目提供的学习机会;

感谢 东方财富网站 提供的数据;

感谢 新浪财经网站 提供的数据;

感谢 金十数据网站 提供的数据;

感谢 生意社网站 提供的数据;

感谢 中国银行间市场交易商协会网站 提供的数据;

感谢 99期货网站 提供的数据;

感谢 中国外汇交易中心暨全国银行间同业拆借中心网站 提供的数据;

感谢 和讯财经网站 提供的数据;

感谢 DACHENG-XIU 网站 提供的数据;

感谢 上海证券交易所网站 提供的数据;

感谢 深圳证券交易所网站 提供的数据;

感谢 北京证券交易所网站 提供的数据;

感谢 中国金融期货交易所网站 提供的数据;

感谢 上海期货交易所网站 提供的数据;

感谢 大连商品交易所网站 提供的数据;

感谢 郑州商品交易所网站 提供的数据;

感谢 上海国际能源交易中心网站 提供的数据;

感谢 Timeanddate 网站 提供的数据;

感谢 河北省空气质量预报信息发布系统网站 提供的数据;

感谢 Economic Policy Uncertainty 网站 提供的数据;

感谢 申万指数网站 提供的数据;

感谢 真气网网站 提供的数据;

感谢 财富网站 提供的数据;

感谢 中国证券投资基金业协会网站 提供的数据;

感谢 Expatistan 网站 提供的数据;

感谢 北京市碳排放权电子交易平台网站 提供的数据;

感谢 国家金融与发展实验室网站 提供的数据;

感谢 义乌小商品指数网站 提供的数据;

感谢 百度迁徙网站 提供的数据;

感谢 思知网站 提供的数据;

感谢 新加坡交易所网站 提供的数据。

Metadata

Release files for akshare 1.20.65

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for akshare 1.20.65
File Size Uploaded Provenance Actions
akshare-1.20.65.tar.gz 987.1 kB With provenance Details for akshare-1.20.65.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for akshare 1.20.65
File Interpreter ABI Platform Actions
akshare-1.20.65-py3-none-any.whl Python 3 none any Details for akshare-1.20.65-py3-none-any.whl

Total release size: 2.1 MB

Release files / akshare-1.20.65.tar.gz

Download URL akshare-1.20.65.tar.gz
Size 987.1 kB
Tags Source
SHA-256 checksum
How to use checksums
14a877d4b36ca9afdea4663ff3c494616ed5fd57e239f39def47f72ec7728c91
BLAKE2b-256 checksum
How to use checksums
5522cc349d967c2430c30508baec614020a76737069345e218e2a72622a9063e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Release files / akshare-1.20.65-py3-none-any.whl

Download URL akshare-1.20.65-py3-none-any.whl
Size 1.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
53b734bc6cdb24eb10ca7b5d9b013b7a9d986439a771ef51891ff228a9952d64
BLAKE2b-256 checksum
How to use checksums
c2dfd41d6716bff96bb600f5ec69f7ddc545dc6148f48b1e855191da4514b576
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

Security for akshare 1.20.65

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for akshare-1.20.65.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 15, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

1.20.65 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page