or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

tessl/pypi-akshare

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

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/akshare@1.17.x

To install, run

npx @tessl/cli install tessl/pypi-akshare@1.17.0

0

# AKShare Python Financial Data Library

1

2

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.

3

4

## Package Information

5

6

**Name:** akshare

7

**Language:** Python

8

**Installation:** `pip install akshare`

9

**Version:** 1.17.44

10

**Dependencies:** pandas, requests, beautifulsoup4, lxml

11

12

## Core Imports

13

14

```python { .api }

15

import akshare as ak

16

import pandas as pd

17

from typing import Optional

18

19

# AKShare provides 1,046+ functions across 37 categories

20

# All functions return pandas.DataFrame objects

21

```

22

23

## Basic Usage

24

25

### Real-time Market Data

26

```python { .api }

27

import akshare as ak

28

29

# Get real-time A-share market data

30

df: pd.DataFrame = ak.stock_zh_a_spot_em()

31

print(df.head())

32

# 序号 代码 名称 最新价 涨跌幅 涨跌额 成交量 成交额

33

# 0 1 000001 平安银行 10.50 1.45 0.15 1234567 12950123456

34

# 1 2 000002 万科A 8.92 -0.89 -0.08 987654 8800765432

35

36

# Get historical data for specific stock

37

hist_df: pd.DataFrame = ak.stock_zh_a_hist(

38

symbol="000001",

39

period="daily",

40

start_date="20240101",

41

end_date="20241201"

42

)

43

```

44

45

### Macroeconomic Data

46

```python { .api }

47

import akshare as ak

48

49

# Chinese Consumer Price Index

50

cpi_df: pd.DataFrame = ak.macro_china_cpi()

51

print(cpi_df.head())

52

# 日期 全国CPI 城市CPI 农村CPI

53

# 0 2024-11-01 102.3 102.1 102.8

54

# 1 2024-10-01 102.0 101.8 102.5

55

56

# US Non-farm Payrolls

57

nonfarm_df: pd.DataFrame = ak.macro_usa_non_farm()

58

59

# Chinese GDP Data

60

gdp_df: pd.DataFrame = ak.macro_china_gdp()

61

```

62

63

### Fund and ETF Data

64

```python { .api }

65

import akshare as ak

66

67

# Real-time ETF data

68

etf_df: pd.DataFrame = ak.fund_etf_spot_em()

69

70

# Open-end fund daily data

71

fund_df: pd.DataFrame = ak.fund_open_fund_daily_em(symbol="000001")

72

```

73

74

## Architecture

75

76

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

77

78

### Data Source Integration

79

- **East Money (东方财富)** - Functions suffixed with `_em`

80

- **Sina Finance (新浪财经)** - Functions suffixed with `_sina`

81

- **Tonghuashun (同花顺)** - Functions suffixed with `_ths`

82

- **JiSiLu (集思录)** - Functions suffixed with `_jsl`

83

- **CNInfo (巨潮资讯网)** - Functions suffixed with `_cninfo`

84

85

### Module Organization

86

```

87

akshare/

88

├── stock/ # Core stock market data

89

├── stock_feature/ # Advanced stock analysis

90

├── economic/ # Macroeconomic indicators

91

├── fund/ # Mutual funds and ETFs

92

├── bond/ # Bond market data

93

├── futures/ # Futures and derivatives

94

├── option/ # Options market data

95

├── index/ # Market indices

96

└── utils/ # Shared utilities

97

```

98

99

### Consistent API Design

100

- All functions return `pandas.DataFrame` objects

101

- Standardized parameter patterns (symbol, period, start_date, end_date)

102

- Consistent column naming and data typing

103

- No API keys required for most functions

104

105

## Capabilities

106

107

### [Stock Market Data](./stock-data.md)

108

**Core stock market data and advanced analysis features**

109

110

```python { .api }

111

# Real-time A-share quotes

112

df: pd.DataFrame = ak.stock_zh_a_spot_em()

113

114

# Historical stock data

115

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

116

117

# US stock real-time data

118

us_df: pd.DataFrame = ak.stock_us_spot()

119

120

# Hong Kong stock data

121

hk_df: pd.DataFrame = ak.stock_hk_spot()

122

123

# Stock Connect capital flows

124

hsgt_df: pd.DataFrame = ak.stock_hsgt_fund_flow_summary_em()

125

```

126

127

**Functions:** 325+ functions across STOCK (120) and STOCK_FEATURE (205) categories

128

**Coverage:** Chinese A-shares, Hong Kong stocks, US stocks, technical indicators, capital flows

129

130

### [Economic Indicators](./economic-data.md)

131

**Comprehensive macroeconomic data from multiple countries**

132

133

```python { .api }

134

# Chinese economic indicators

135

cpi_df: pd.DataFrame = ak.macro_china_cpi()

136

gdp_df: pd.DataFrame = ak.macro_china_gdp()

137

pmi_df: pd.DataFrame = ak.macro_china_pmi()

138

139

# US economic data

140

us_gdp_df: pd.DataFrame = ak.macro_usa_gdp()

141

unemployment_df: pd.DataFrame = ak.macro_usa_unemployment_rate()

142

143

# European economic indicators

144

euro_cpi_df: pd.DataFrame = ak.macro_euro_cpi()

145

```

146

147

**Functions:** 226 functions covering China, US, Europe, Japan, Australia, Canada, UK

148

**Coverage:** GDP, CPI, PMI, employment, trade, monetary policy indicators

149

150

### [Financial Instruments](./financial-instruments.md)

151

**Funds, bonds, futures, and options market data**

152

153

```python { .api }

154

# ETF and fund data

155

etf_df: pd.DataFrame = ak.fund_etf_spot_em()

156

fund_daily_df: pd.DataFrame = ak.fund_open_fund_daily_em(symbol="000001")

157

158

# Bond market data

159

bond_df: pd.DataFrame = ak.bond_zh_hs_daily()

160

convertible_df: pd.DataFrame = ak.bond_convert_list()

161

162

# Futures data

163

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

164

165

# Options data

166

option_df: pd.DataFrame = ak.option_finance_board()

167

```

168

169

**Functions:** 224 functions across FUND (79), BOND (41), FUTURES (62), OPTION (42) categories

170

**Coverage:** Mutual funds, ETFs, government bonds, corporate bonds, commodity futures, stock options

171

172

### [Market Indices](./market-indices.md)

173

**Market indices and composite indicators**

174

175

```python { .api }

176

# Chinese market indices

177

index_df: pd.DataFrame = ak.stock_zh_index_spot_em()

178

index_daily_df: pd.DataFrame = ak.stock_zh_index_daily(symbol="000001")

179

180

# Global market indices

181

global_df: pd.DataFrame = ak.index_investing_global()

182

183

# Commodity indices

184

commodity_df: pd.DataFrame = ak.index_cx_commodity()

185

186

# Volatility indices

187

vix_df: pd.DataFrame = ak.index_vix()

188

```

189

190

**Functions:** 95 functions covering domestic and international indices

191

**Coverage:** Stock indices, commodity indices, volatility indices, economic composite indicators

192

193

### [Fundamental Analysis](./fundamental-analysis.md)

194

**Financial statements and company fundamental data**

195

196

```python { .api }

197

# Financial analysis indicators

198

financial_df: pd.DataFrame = ak.stock_financial_analysis_indicator_em(symbol="000001")

199

200

# Income statement data

201

income_df: pd.DataFrame = ak.stock_financial_abstract(symbol="000001")

202

203

# Balance sheet indicators

204

balance_df: pd.DataFrame = ak.stock_balance_sheet_by_report_em(symbol="000001")

205

206

# Earnings forecasts

207

forecast_df: pd.DataFrame = ak.stock_profit_forecast()

208

209

# Analyst recommendations

210

recommend_df: pd.DataFrame = ak.stock_recommend()

211

```

212

213

**Functions:** 47 functions for comprehensive fundamental analysis

214

**Coverage:** Income statements, balance sheets, cash flows, financial ratios, analyst coverage

215

216

## Key Features

217

218

- **No API Keys Required** - Most functions work without authentication

219

- **Real-time Data Access** - Live market quotes and real-time indicators

220

- **Extensive Historical Data** - Years of historical data across all asset classes

221

- **Multiple Data Sources** - Redundant sources for reliability and coverage

222

- **Consistent Output Format** - All functions return pandas DataFrames

223

- **Chinese Market Focus** - Comprehensive coverage of Chinese financial markets

224

- **International Data** - US, European, and other major market data

225

- **Regular Updates** - Active development with frequent data source maintenance

226

- **Open Source** - MIT license with active community development

227

228

## Common Patterns

229

230

### Parameter Conventions

231

```python { .api }

232

# Symbol parameter for specific instruments

233

df = ak.stock_zh_a_hist(symbol="000001") # Individual stock

234

df = ak.fund_open_fund_daily_em(symbol="000001") # Specific fund

235

236

# Date range parameters

237

df = ak.stock_zh_a_hist(

238

symbol="000001",

239

start_date="20240101", # Format: YYYYMMDD

240

end_date="20241201"

241

)

242

243

# Period parameter for data frequency

244

df = ak.stock_zh_a_hist(symbol="000001", period="daily") # daily, weekly, monthly

245

```

246

247

### Return Data Format

248

```python { .api }

249

# All functions return pandas DataFrame

250

df: pd.DataFrame = ak.stock_zh_a_spot_em()

251

252

# Consistent data types

253

assert isinstance(df, pd.DataFrame)

254

assert df.shape[0] > 0 # Always returns data when available

255

```

256

257

### Error Handling

258

```python { .api }

259

try:

260

df = ak.stock_zh_a_hist(symbol="000001")

261

if df.empty:

262

print("No data available for this symbol")

263

except Exception as e:

264

print(f"Data retrieval error: {e}")

265

```

266

267

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