{"id":4819,"library":"tushare","title":"Tushare - China Stock Data Utility","description":"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.","status":"maintenance","version":"1.4.29","language":"en","source_language":"en","source_url":"https://github.com/waditu/tushare","tags":["financial data","stocks","China","quantitative finance","pandas"],"install":[{"cmd":"pip install tushare","lang":"bash","label":"Install tushare"}],"dependencies":[{"reason":"Data is primarily returned as pandas DataFrames, requiring pandas for data manipulation.","package":"pandas","optional":false}],"imports":[{"symbol":"tushare","correct":"import tushare as ts"}],"quickstart":{"code":"import tushare as ts\nimport os\n\n# Tushare Pro requires a token. Register at tushare.pro to get one.\n# It's recommended to set it as an environment variable.\nPRO_TOKEN = os.environ.get('TUSHARE_PRO_TOKEN', 'YOUR_TUSHARE_PRO_TOKEN')\nts.set_token(PRO_TOKEN)\n\n# Initialize Pro API client\npro = ts.pro_api()\n\n# Fetch stock daily quotes (example: Ping An Bank, TS_CODE: 000001.SZ)\ndf = pro.daily(ts_code='000001.SZ', start_date='20230101', end_date='20230110')\n\nprint(df.head())\n# Example: Get real-time quotes (requires Pro, but might be via old interface or specific Pro interface)\n# Note: Real-time data access might have specific Pro API calls or rate limits.\n# For historical data, pro.daily is the recommended way in Tushare Pro.\n# For older tushare (non-Pro) historical data, which is deprecated:\n# try:\n#    legacy_df = ts.get_hist_data('600848')\n#    print(\"\\nLegacy historical data (deprecated):\")\n#    print(legacy_df.head())\n# except Exception as e:\n#    print(f\"\\nCould not fetch legacy data (expected for deprecated service): {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"breaking","affected_versions":"<=1.4.29"},{"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.","message":"Tushare Pro APIs require an API token for authentication. Failing to set the token will result in data access failures.","severity":"gotcha","affected_versions":"All versions when using Pro API"},{"fix":"Always ensure date parameters are passed as strings in 'YYYYMMDD' format, e.g., '20230101'.","message":"Some Tushare API functions are sensitive to date format. Dates must be provided in 'YYYYMMDD' string format; otherwise, APIs may return empty data or errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult Tushare Pro documentation for rate limits and best practices. Implement delays or caching mechanisms in your code to avoid excessive requests.","message":"Frequent 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.","severity":"gotcha","affected_versions":"All versions when interacting with Tushare service"},{"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.","message":"There have been reported incompatibilities with newer versions of the pandas library, specifically where Tushare might not adapt correctly to recent pandas updates.","severity":"gotcha","affected_versions":"Possibly 1.4.x with recent pandas releases (e.g., pandas 2.x)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}