CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-akshare

Comprehensive Python library for financial data acquisition providing access to Chinese and global market data.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

AKShare Python Financial Data Library

AKShare is a comprehensive Python library for financial data acquisition, providing access to over 1,000 functions across 37 categories covering Chinese and global financial markets. The library offers real-time and historical data for multiple asset classes including stocks, bonds, futures, options, funds, commodities, and macroeconomic indicators.

Package Information

Name: akshare
Language: Python
Installation: pip install akshare
Version: 1.17.44
Dependencies: pandas, requests, beautifulsoup4, lxml

Core Imports

import akshare as ak
import pandas as pd
from typing import Optional

# AKShare provides 1,046+ functions across 37 categories
# All functions return pandas.DataFrame objects

Basic Usage

Real-time Market Data

import akshare as ak

# Get real-time A-share market data
df: pd.DataFrame = ak.stock_zh_a_spot_em()
print(df.head())
#      序号    代码    名称   最新价  涨跌幅  涨跌额    成交量        成交额
# 0    1  000001  平安银行  10.50   1.45   0.15  1234567  12950123456
# 1    2  000002   万科A   8.92  -0.89  -0.08   987654   8800765432

# Get historical data for specific stock
hist_df: pd.DataFrame = ak.stock_zh_a_hist(
    symbol="000001", 
    period="daily", 
    start_date="20240101", 
    end_date="20241201"
)

Macroeconomic Data

import akshare as ak

# Chinese Consumer Price Index
cpi_df: pd.DataFrame = ak.macro_china_cpi()
print(cpi_df.head())
#         日期     全国CPI    城市CPI    农村CPI
# 0  2024-11-01    102.3     102.1     102.8
# 1  2024-10-01    102.0     101.8     102.5

# US Non-farm Payrolls
nonfarm_df: pd.DataFrame = ak.macro_usa_non_farm()

# Chinese GDP Data
gdp_df: pd.DataFrame = ak.macro_china_gdp()

Fund and ETF Data

import akshare as ak

# Real-time ETF data
etf_df: pd.DataFrame = ak.fund_etf_spot_em()

# Open-end fund daily data
fund_df: pd.DataFrame = ak.fund_open_fund_daily_em(symbol="000001")

Architecture

AKShare follows a modular architecture organized by data source and asset class:

Data Source Integration

  • East Money (东方财富) - Functions suffixed with _em
  • Sina Finance (新浪财经) - Functions suffixed with _sina
  • Tonghuashun (同花顺) - Functions suffixed with _ths
  • JiSiLu (集思录) - Functions suffixed with _jsl
  • CNInfo (巨潮资讯网) - Functions suffixed with _cninfo

Module Organization

akshare/
├── stock/           # Core stock market data
├── stock_feature/   # Advanced stock analysis
├── economic/        # Macroeconomic indicators  
├── fund/           # Mutual funds and ETFs
├── bond/           # Bond market data
├── futures/        # Futures and derivatives
├── option/         # Options market data
├── index/          # Market indices
└── utils/          # Shared utilities

Consistent API Design

  • All functions return pandas.DataFrame objects
  • Standardized parameter patterns (symbol, period, start_date, end_date)
  • Consistent column naming and data typing
  • No API keys required for most functions

Capabilities

Stock Market Data

Core stock market data and advanced analysis features

# Real-time A-share quotes
df: pd.DataFrame = ak.stock_zh_a_spot_em()

# Historical stock data  
hist_df: pd.DataFrame = ak.stock_zh_a_hist(symbol="000001", period="daily")

# US stock real-time data
us_df: pd.DataFrame = ak.stock_us_spot()

# Hong Kong stock data
hk_df: pd.DataFrame = ak.stock_hk_spot()

# Stock Connect capital flows
hsgt_df: pd.DataFrame = ak.stock_hsgt_fund_flow_summary_em()

Functions: 325+ functions across STOCK (120) and STOCK_FEATURE (205) categories
Coverage: Chinese A-shares, Hong Kong stocks, US stocks, technical indicators, capital flows

Economic Indicators

Comprehensive macroeconomic data from multiple countries

# Chinese economic indicators
cpi_df: pd.DataFrame = ak.macro_china_cpi()
gdp_df: pd.DataFrame = ak.macro_china_gdp()
pmi_df: pd.DataFrame = ak.macro_china_pmi()

# US economic data
us_gdp_df: pd.DataFrame = ak.macro_usa_gdp()
unemployment_df: pd.DataFrame = ak.macro_usa_unemployment_rate()

# European economic indicators
euro_cpi_df: pd.DataFrame = ak.macro_euro_cpi()

Functions: 226 functions covering China, US, Europe, Japan, Australia, Canada, UK
Coverage: GDP, CPI, PMI, employment, trade, monetary policy indicators

Financial Instruments

Funds, bonds, futures, and options market data

# ETF and fund data
etf_df: pd.DataFrame = ak.fund_etf_spot_em()
fund_daily_df: pd.DataFrame = ak.fund_open_fund_daily_em(symbol="000001")

# Bond market data
bond_df: pd.DataFrame = ak.bond_zh_hs_daily()
convertible_df: pd.DataFrame = ak.bond_convert_list()

# Futures data
futures_df: pd.DataFrame = ak.futures_zh_daily_sina(symbol="RB0000")

# Options data
option_df: pd.DataFrame = ak.option_finance_board()

Functions: 224 functions across FUND (79), BOND (41), FUTURES (62), OPTION (42) categories
Coverage: Mutual funds, ETFs, government bonds, corporate bonds, commodity futures, stock options

Market Indices

Market indices and composite indicators

# Chinese market indices
index_df: pd.DataFrame = ak.stock_zh_index_spot_em()
index_daily_df: pd.DataFrame = ak.stock_zh_index_daily(symbol="000001")

# Global market indices  
global_df: pd.DataFrame = ak.index_investing_global()

# Commodity indices
commodity_df: pd.DataFrame = ak.index_cx_commodity()

# Volatility indices
vix_df: pd.DataFrame = ak.index_vix()

Functions: 95 functions covering domestic and international indices
Coverage: Stock indices, commodity indices, volatility indices, economic composite indicators

Fundamental Analysis

Financial statements and company fundamental data

# Financial analysis indicators
financial_df: pd.DataFrame = ak.stock_financial_analysis_indicator_em(symbol="000001")

# Income statement data
income_df: pd.DataFrame = ak.stock_financial_abstract(symbol="000001")

# Balance sheet indicators
balance_df: pd.DataFrame = ak.stock_balance_sheet_by_report_em(symbol="000001")

# Earnings forecasts
forecast_df: pd.DataFrame = ak.stock_profit_forecast()

# Analyst recommendations  
recommend_df: pd.DataFrame = ak.stock_recommend()

Functions: 47 functions for comprehensive fundamental analysis
Coverage: Income statements, balance sheets, cash flows, financial ratios, analyst coverage

Key Features

  • No API Keys Required - Most functions work without authentication
  • Real-time Data Access - Live market quotes and real-time indicators
  • Extensive Historical Data - Years of historical data across all asset classes
  • Multiple Data Sources - Redundant sources for reliability and coverage
  • Consistent Output Format - All functions return pandas DataFrames
  • Chinese Market Focus - Comprehensive coverage of Chinese financial markets
  • International Data - US, European, and other major market data
  • Regular Updates - Active development with frequent data source maintenance
  • Open Source - MIT license with active community development

Common Patterns

Parameter Conventions

# Symbol parameter for specific instruments
df = ak.stock_zh_a_hist(symbol="000001")  # Individual stock
df = ak.fund_open_fund_daily_em(symbol="000001")  # Specific fund

# Date range parameters  
df = ak.stock_zh_a_hist(
    symbol="000001",
    start_date="20240101",  # Format: YYYYMMDD
    end_date="20241201"
)

# Period parameter for data frequency
df = ak.stock_zh_a_hist(symbol="000001", period="daily")  # daily, weekly, monthly

Return Data Format

# All functions return pandas DataFrame
df: pd.DataFrame = ak.stock_zh_a_spot_em()

# Consistent data types
assert isinstance(df, pd.DataFrame)
assert df.shape[0] > 0  # Always returns data when available

Error Handling

try:
    df = ak.stock_zh_a_hist(symbol="000001")
    if df.empty:
        print("No data available for this symbol")
except Exception as e:
    print(f"Data retrieval error: {e}")

AKShare provides comprehensive, reliable access to financial data essential for quantitative analysis, research, and application development in the Chinese and global markets.

Install with Tessl CLI

npx tessl i tessl/pypi-akshare
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/akshare@1.17.x
Publish Source
CLI
Badge
tessl/pypi-akshare badge