Skip to main content

AShareHub Python SDK

Official Python SDK for Chinese A-Share Market Data

PyPI version Python versions License: MIT

WebsiteDocumentationAPI ReferenceGet API Key


Overview

AShareHub provides institutional-grade Chinese A-Share market data through a simple, modern Python SDK. Access real-time and historical data for all listed Chinese A-shares.

Key Features:

  • Returns pd.DataFrame — same convention as Tushare
  • 38 data endpoints covering market, financial, real-time, news, and reference data
  • 10+ years of historical data
  • Secure API key authentication
  • Fast and reliable

Installation

pip install asharehub

Requirements: Python 3.10+, pandas


Quick Start

from asharehub import AShareHub

client = AShareHub(api_key="ash_your_key_here")

# Get daily market data — returns pd.DataFrame
df = client.market_daily(symbol="000001.SZ", start_date="2024-01-01", end_date="2024-12-31")
print(df[["trade_date", "open", "high", "low", "close", "vol"]])

client.close()

API Methods

All methods return pd.DataFrame. Empty results return an empty DataFrame (df.empty == True).

Market Data

df = client.market_daily(symbol="000001.SZ", start_date="2024-01-01")
df = client.fundamentals(symbol="000001.SZ", start_date="2024-01-01")
df = client.margin(symbol="000001.SZ", limit=100)
df = client.block_trade(symbol="000001.SZ", limit=100)
df = client.top_list(limit=100)
df = client.shareholders(symbol="000001.SZ", limit=100)
df = client.holder_trade(symbol="000001.SZ", limit=100)
df = client.concepts(limit=100)
df = client.concept_members(symbol="TS2", limit=100)
df = client.adj_factor(symbol="000001.SZ", limit=100)
df = client.technical_factors(symbol="000001.SZ", limit=100)
df = client.limit_list(limit_type="U", limit=100)

Capital Flows

df = client.moneyflow_hsgt(start_date="2024-01-01", limit=100)
df = client.moneyflow(symbol="000001.SZ", limit=100)
df = client.northbound_holdings(symbol="000001.SZ", limit=100)

Financials

df = client.financial_indicators(symbol="000001.SZ", limit=20)
df = client.income(symbol="000001.SZ", limit=20)
df = client.balance_sheet(symbol="000001.SZ", limit=20)
df = client.cash_flow(symbol="000001.SZ", limit=20)
df = client.forecast(symbol="000001.SZ", limit=50)
df = client.express(symbol="000001.SZ", limit=50)
df = client.dividend(symbol="000001.SZ", limit=50)

Indices

df = client.index_daily(symbol="000300.SH", start_date="2024-01-01")
df = client.index_weight(symbol="399300.SZ", limit=100)

Other

df = client.chip_distribution(symbol="000001.SZ", limit=100)
df = client.fx_daily(symbol="USDCNH.FXCM", limit=100)

Reference Data

df = client.stock_list(limit=100)
df = client.industry_list(limit=100)
df = client.trade_calendar(exchange="SSE", start_date="2024-01-01")

Common Parameters

All data methods accept:

Parameter Type Description
symbol str Stock/index code, e.g. 000001.SZ
start_date str Start date, YYYY-MM-DD
end_date str End date, YYYY-MM-DD
limit int Max rows per request
offset int Pagination offset

Common Index Codes

Code Name
000001.SH SSE Composite (上证综指)
000300.SH CSI 300 (沪深300)
399001.SZ SZSE Component (深证成指)
399006.SZ ChiNext (创业板指)
000016.SH SSE 50 (上证50)

Authentication

Get your free API key:

  1. Visit asharehub.com/console/register
  2. Create an account
  3. Generate your API key in the dashboard

Free tier includes 100 API calls per day.


Error Handling

from asharehub import AShareHub
import httpx

client = AShareHub(api_key="your_key")

try:
    df = client.market_daily(symbol="000001.SZ")
except httpx.HTTPStatusError as e:
    if e.response.status_code == 401:
        print("Invalid API key")
    elif e.response.status_code == 429:
        print("Rate limit exceeded")
    else:
        print(f"HTTP error: {e}")

Advanced Usage

Context Manager

with AShareHub(api_key="your_key") as client:
    df = client.market_daily(symbol="000001.SZ")
    # Client automatically closes when exiting context

Custom Base URL

client = AShareHub(
    api_key="your_key",
    base_url="https://custom.api.url",
    timeout=60.0
)

Rate Limits

Plan Price Daily Limit
Free $0 100 requests
Pro $49/month 10,000 requests
Business $99/month 50,000 requests

Support


License

MIT License - see the LICENSE file for details.


Built for the global investment community

asharehub.com

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asharehub-0.5.2.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asharehub-0.5.2-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file asharehub-0.5.2.tar.gz.

File metadata

  • Download URL: asharehub-0.5.2.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asharehub-0.5.2.tar.gz
Algorithm Hash digest
SHA256 d71ee1afb505e1e1637bab723bf3d445a90ab8139acd0e661c445dfdb80393fa
MD5 7215adb91d79c4ed4556c31953aac07b
BLAKE2b-256 349f1b75668106791cb091725dab756b30774bfb2e1904b7173e78318c1c6afd

See more details on using hashes here.

Provenance

The following attestation bundles were made for asharehub-0.5.2.tar.gz:

Publisher: publish-pypi.yml on ChuYiCui1/AshareHub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asharehub-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: asharehub-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for asharehub-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 35b1b369f48998e0a85e8476e6715365df984b3c3e2d7193578c026dd1d0e075
MD5 5f2a5d372ca26cf839ef9001ff75b6ef
BLAKE2b-256 7bcfaab00ecc43b0289949622b0cb8e5ed6c0fea27e3aa664395e385eaf276f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for asharehub-0.5.2-py3-none-any.whl:

Publisher: publish-pypi.yml on ChuYiCui1/AshareHub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page