Registry / data / tushare

tushare

JSON →
library1.4.29pypypi✓ verified 23d ago

Tushare (pypi-slug: tushare) is a Python utility designed for collecting, cleaning, and storing financial market data, primarily focusing on China stocks, futures, and funds. While the original 'Org' version of Tushare had its own data sources, it is now largely superseded by 'Tushare Pro,' a more robust and maintained data service. The `tushare` library acts as the Python SDK to access both the legacy 'Org' data (though deprecated) and the recommended 'Pro' data interfaces. This library is currently at version 1.4.29 and is in maintenance mode for its legacy features, with active development focused on its Pro API integration.

pip install tushare
INSTALL
IMPORT
SIG · TUSHARE
T
tushare
datapythonv1.4.29
Install
9.8s avg
Import
1405ms
Disk
185MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.4.29 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 1.436s · 184.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 9.8s · import 1.374s · 177MB
185MB installed
● package 185MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tushare
import tushare as ts

This quickstart demonstrates how to initialize Tushare with a Pro API token (recommended) and fetch historical daily stock data using the Tushare Pro interface. The `TUSHARE_PRO_TOKEN` should be obtained from tushare.pro after registration and set as an environment variable for security. The example fetches daily quotes for a specific stock within a date range.

import tushare as ts import os # Tushare Pro requires a token. Register at tushare.pro to get one. # It's recommended to set it as an environment variable. PRO_TOKEN = os.environ.get('TUSHARE_PRO_TOKEN', 'YOUR_TUSHARE_PRO_TOKEN') ts.set_token(PRO_TOKEN) # Initialize Pro API client pro = ts.pro_api() # Fetch stock daily quotes (example: Ping An Bank, TS_CODE: 000001.SZ) df = pro.daily(ts_code='000001.SZ', start_date='20230101', end_date='20230110') print(df.head()) # Example: Get real-time quotes (requires Pro, but might be via old interface or specific Pro interface) # Note: Real-time data access might have specific Pro API calls or rate limits. # For historical data, pro.daily is the recommended way in Tushare Pro. # For older tushare (non-Pro) historical data, which is deprecated: # try: # legacy_df = ts.get_hist_data('600848') # print("\nLegacy historical data (deprecated):") # print(legacy_df.head()) # except Exception as e: # print(f"\nCould not fetch legacy data (expected for deprecated service): {e}")
Debug
Known issues
breakingThe original 'Org' version of Tushare, which is directly used without `ts.pro_api()` and a token, is no longer maintained, and its data sources are deprecated. Reliability and availability of data from these legacy interfaces are not guaranteed. Users should migrate to Tushare Pro.
fix
Register for a Tushare Pro account at `tushare.pro`, obtain an API token, and use `ts.set_token()` followed by `ts.pro_api()` to access the Pro data interfaces.
affects: <=1.4.29
gotchaTushare Pro APIs require an API token for authentication. Failing to set the token will result in data access failures.
fix
Set your Tushare Pro token using `ts.set_token('YOUR_TOKEN')` before making any Pro API calls. It's best practice to load the token from an environment variable.
affects: All versions when using Pro API
gotchaSome Tushare API functions are sensitive to date format. Dates must be provided in 'YYYYMMDD' string format; otherwise, APIs may return empty data or errors.
fix
Always ensure date parameters are passed as strings in 'YYYYMMDD' format, e.g., '20230101'.
affects: All versions
gotchaFrequent data calls, especially with different parameters or without adherence to usage policies, can lead to rate limiting or temporary data call restrictions by the Tushare service.
fix
Consult Tushare Pro documentation for rate limits and best practices. Implement delays or caching mechanisms in your code to avoid excessive requests.
affects: All versions when interacting with Tushare service
gotchaThere have been reported incompatibilities with newer versions of the pandas library, specifically where Tushare might not adapt correctly to recent pandas updates.
fix
If encountering issues, try pinning your pandas version to an older, compatible release (e.g., `pandas<2.0.0`) or check the Tushare GitHub issues for specific compatibility updates or workarounds.
affects: Possibly 1.4.x with recent pandas releases (e.g., pandas 2.x)
Errors
Common errors & fixes
AttributeError: 'module' object has no attribute 'get_hist_data'
The `get_hist_data` function is part of Tushare's legacy API, which is deprecated, and users should transition to the Tushare Pro API.
fix
Initialize the Pro API client with your token and use the equivalent Pro API methods, such as `pro.daily()` for daily historical data: `import tushare as ts; ts.set_token('YOUR_PRO_TOKEN'); pro = ts.pro_api(); df = pro.daily(ts_code='000001.SZ', start_date='20180101', end_date='20181101')`.
tushare error, please set token.
Tushare Pro API requires an authentication token, which must be set using `ts.set_token()` before initializing the Pro API client to access data.
fix
Obtain your Tushare Pro token from the official website and set it in your script or environment variable: `import tushare as ts; ts.set_token('YOUR_PRO_TOKEN'); pro = ts.pro_api()`.
tushare.pro.client.TushareException: 抱歉,您最多只能获取2000条数据,每天只能获取50000条数据,单次请求量超过限制。
The API request exceeds the Tushare Pro API's single call limit (e.g., max 2000 rows per request) or the daily data quota for your account level.
fix
Refactor your code to fetch data in smaller batches using loops and pagination, or adjust the date range to reduce the single request volume to stay within the API limits.
ModuleNotFoundError: No module named 'tushare'
The `tushare` package is not installed in the Python environment being used, or the environment path is incorrect.
fix
Install the package using pip: `pip install tushare`.
Upgrade
Version history
1.4.29latest on PyPI · released Mar 25, 2026
Audit
Dependencies
pandasrequiredData is primarily returned as pandas DataFrames, requiring pandas for data manipulation.
Agent activity
56 hits · last 30 days
node
50
OpenAI (training)
1
Resources
tushare — pip install tushare · libregistry