skillfed

baostock

A tool for obtaining historical data of China stock market

baostock v0.9.3 756.0K downloads/30d#5,140 on PyPI
Permissive license BSD License Active released

What it is and what it does

BaoStock is a Python client for accessing China stock market historical data through a dedicated data server. It wraps market data queries into a simple API that returns results as pandas DataFrames, making it straightforward to load stock prices, trading volumes, and valuation metrics into analysis workflows. The package is designed for financial analysts, quantitative traders, and data scientists working with Chinese equities.

The typical workflow involves logging in, querying historical K-line (candlestick) data for specific stock codes and date ranges, iterating through result rows, and converting them into a DataFrame for further analysis or export. It handles authentication, result pagination, and format conversion automatically, reducing boilerplate code for common data retrieval tasks.

Use it for:

  • Fetch historical OHLC data for Chinese stocks to build backtesting datasets for quantitative trading strategies.
  • Retrieve valuation metrics (P/E, P/B, P/S ratios) for fundamental analysis of Chinese equities.
  • Export stock market data to CSV for use in machine learning models trained on market behavior.
  • Monitor trading status and volume changes for a portfolio of Chinese stocks over time.
  • Build financial dashboards that aggregate price and volume data from multiple Chinese stock codes.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

BaoStock retrieves historical China stock market data and returns it as pandas DataFrames, designed for financial analysis and machine learning workflows.

Yes, if you need free historical China stock market data. The package is actively maintained, has low install friction, and integrates cleanly with pandas workflows. The main constraint is dependence on BaoStock's external data server—verify uptime and rate limits for your use case before committing to production systems.

Install

baostock on PyPI

pip

pip install baostock

uv

uv add baostock

poetry

poetry add baostock

Installing baostock

Before you install

Low install friction with a single runtime dependency (pandas). Active maintenance status with a recent release.

License in practice

BSD License is permissive, allowing commercial and private use with minimal restrictions.

Quickstart

pip install baostock

import baostock as bs
import pandas as pd

lg = bs.login()
rs = bs.query_history_k_data_plus("sh.600000", "date,code,open,high,low,close", start_date='2025-06-01', end_date='2025-12-31')
data_list = []
while (rs.error_code == '0') & rs.next():
    data_list.append(rs.get_row_data())
result = pd.DataFrame(data_list, columns=rs.fields)
bs.logout()

Requires login to BaoStock's data server; network connectivity to their service is necessary for data retrieval.

Verify before relying

  • Stability and uptime guarantees for the BaoStock data server.
  • Rate limits or data volume restrictions on API calls.
  • Whether historical data extends beyond the example date range shown (2025-06-01 to 2025-12-31).
  • Support for real-time data or only historical OHLC data.

Package facts

License BSD License (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — pandas
Maintenance actively maintained — 35 days since the last release
First released
Downloads 756,010/month — #5,140 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: baostock-0.9.3-py3-none-any.whl

Development Status :: 3 - AlphaEnvironment :: ConsoleLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.6Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries

Tags

china stock market datahistorical stock price datafinancial data retrievalpandas dataframe stock dataquantitative trading datachinese market analysisstock market api
financial-datachina-marketsquantitative-analysis

More Libraries packages