baostock
A tool for obtaining historical data of China stock market
Decision gist · record as of 2026-08-14
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.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires login to BaoStock's data server; network connectivity to their service is necessary for data retrieval.
- Low install friction with a single runtime dependency (pandas).
- Active maintenance status with a recent release.
License · maintenance · safety
BSD License (permissive) — BSD License is permissive, allowing commercial and private use with minimal restrictions.
last release 2026-07-10 (35 days)
0 known vulnerabilities (OSV.dev, 2026-08-14) · 756,010 downloads/mo, #5,140 on PyPI
Alternatives
Verify before relying
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()- 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.
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 on it.
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
Before you install
Low install friction with a single runtime dependency (pandas). Active maintenance status with a recent release.
Requires login to BaoStock's data server; network connectivity to their service is necessary for data retrieval.
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()
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 packagepandas |
| 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 |
| Classifiers | Development Status :: 3 - AlphaEnvironment :: ConsoleLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.6Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries |
Evidence: baostock-0.9.3-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “china stock market data”
- baostockBaoStock retrieves historical China stock market data and returns it…
- tushareFetches historical and real-time Chinese stock market data and…
- vnaiVnAI provides a Python interface for accessing Vietnamese stock…
Give your agent the search over MCP, or paste the wish link into any chat.
More Libraries packages
urllib3 is an HTTP client library that provides thread-safe connection pooling, SSL/TLS verification, multipart file uploads, request retries, compression support, and proxy handling for Python applications.
Requests is a Python HTTP library that simplifies sending HTTP/1.1 requests with automatic handling of headers, authentication, cookies, and response parsing.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Provides parsing, arithmetic, and recurrence rule computation for dates and times, with timezone support and iCalendar RFC compliance.
Install it if you need to parse flexible date strings, compute relative dates, handle timezones, or work with recurrence rules—it's the de facto choice for these tasks.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
See also tickflow · tushare · yahooquery · efinance · mootdx · vnai · fear-and-greed · akshare · tdxpy · yfinance