AKShare
AKShare is an elegant and simple financial data interface library for Python, built for human beings! It provides a comprehensive set of tools for acquiring fundamental, real-time, and historical market data for various financial products like stocks, futures, options, funds, foreign exchange, bonds, and cryptocurrencies. The library is actively developed with frequent releases, often multiple minor versions per day, to adapt to changes in data sources.
Warnings
- breaking Due to its web scraping nature, underlying data sources frequently change their website layouts, leading to API breakage or interface name changes. Users must frequently update the library.
- gotcha AKShare data is intended for academic research and reference purposes only. It is not designed for real-time, low-latency, or high-frequency trading due to potential delays and interruptions in data acquisition.
- gotcha Specific Python versions are required. While `requires_python` states `>=3.9`, the official documentation recommends Python `3.13.x` or higher for optimal compatibility and performance.
- gotcha Some interfaces might not support `start_date` and `end_date` parameters, returning all available data for a given symbol. Users need to manually filter dataframes for specific date ranges.
- gotcha Naming local Python script files as `akshare.py` will cause import conflicts with the installed `akshare` library.
- gotcha Network-related errors such as `ReadTimeout` or IP blocking can occur due to frequent data scraping from various sources. Using proxies or reducing request frequency might be necessary.
- gotcha Some functionalities, especially when running on Linux systems, may require an external JavaScript runtime environment (like `Node.js`) to be installed and available in the system path.
Install
-
pip install akshare --upgrade
Imports
- ak
import akshare as ak
Quickstart
import akshare as ak # Fetch historical A-share stock data for a specific symbol # Replace '000001' with your desired stock code stock_data = ak.stock_zh_a_hist(symbol="000001", period="daily", start_date="20230101", end_date='20231231', adjust="") print(stock_data.head())