--- id: baostock version: "0.9.3" license: BSD License license_treatment: permissive maintenance: active --- # baostock — A tool for obtaining historical data of China stock market License: permissive · Maintenance: active · Downloads: 756.0K/mo ## 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 above — 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 pip install baostock uv add baostock 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: unspecified - Install friction: low - Maintenance: active - Downloads: 756.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags china stock market data, historical stock price data, financial data retrieval, pandas dataframe stock data, quantitative trading data, chinese market analysis, stock market api, financial-data, china-markets, quantitative-analysis [View on SkillFed](https://skillfed.io/packages/baostock) · [View on PyPI](https://pypi.org/project/baostock/)