Skip to main content

LiteQuant Python client SDK

Project description

LiteQuant Python SDK

LiteQuant Python SDK 用于在本地下载和读取 LiteQuant 数据。SDK 会自动处理连接、同步、本地 Parquet 缓存和常见错误提示。

支持 Python 3.8 及以上版本。

Installation

pip install litequant

Quick Start

from litequant import LiteQuantClient

client = LiteQuantClient(
    api_token="your_api_token",
    save_path="./litequant_data",
)

client.UpdateAllCategory(update_method="incremental")
df = client.GetCategory("cn_stock_pivot#open")
print(df.tail())

client.close()

推荐使用上下文管理器自动关闭连接:

from litequant import LiteQuantClient

with LiteQuantClient(api_token="your_api_token", save_path="./litequant_data") as client:
    categories = client.ListCategories()
    df = client.GetCategory(categories[0])

默认 API 地址为 https://www.litequant.pro。如需连接测试环境,可以传入 api_url 或设置环境变量 LITEQUANT_API_URL

Error Handling

SDK 默认会在 Python 终端输出功能面错误提示,同时抛出类型化异常。错误信息不会展示后端细节。

from litequant import LiteQuantClient, LiteQuantError

try:
    with LiteQuantClient(api_token="your_api_token", save_path="./litequant_data") as client:
        df = client.GetCategory("cn_stock_pivot#open")
except LiteQuantError as exc:
    print(exc.code)
    print(exc.user_message)
    print(exc.retryable)

如果你希望完全自己处理错误提示,可以关闭终端输出:

client = LiteQuantClient(
    api_token="your_api_token",
    save_path="./litequant_data",
    display_errors=False,
)

常见公开错误码:

  • AUTH_INVALID:API 凭证无效或已过期
  • ACCOUNT_UNAVAILABLE:账号不可用
  • SUBSCRIPTION_UNAVAILABLE:套餐不可用或已过期
  • PERMISSION_DENIED:权限不足
  • CONNECTION_LIMIT:连接数已达上限
  • CONNECTION_INTERRUPTED:连接已中断,请重新连接
  • REQUEST_INVALID:请求参数无效
  • SERVICE_UNAVAILABLE:服务暂时不可用
  • DATA_UNAVAILABLE:数据暂时不可用
  • DATA_VERIFY_FAILED:数据校验失败

Data Cache

SDK 会把数据保存为本地 Parquet 缓存。再次读取同一数据类别时,会优先使用本地缓存;如果本地没有该数据类别,SDK 会自动同步。

当前 pivot 数据支持 monthlydaily 两种分区模式。后续可以在服务端元信息和客户端缓存层一起扩展更多分区模式。

Metadata Contract

数据服务会提供客户端可识别的类别列表、类别元信息和分区元信息。客户端会自动读取这些元信息并完成数据同步。

公开稳定字段包括:

  • partition_mode:pivot 分区模式,目前支持 monthlydaily
  • partition_keys:数据分区标识列表
  • hash:数据校验值
  • key_columns / dedupe_keys:unstack 数据去重键

普通用户通常不需要直接使用这些字段。

Project details


Download files

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

Source Distribution

litequant-3.0.2.tar.gz (25.5 kB view details)

Uploaded Source

Built Distribution

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

litequant-3.0.2-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

Details for the file litequant-3.0.2.tar.gz.

File metadata

  • Download URL: litequant-3.0.2.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for litequant-3.0.2.tar.gz
Algorithm Hash digest
SHA256 9c3c853cf8b518a2887e59b1b169f2dd41661a88c6a852ffb740a974453bce80
MD5 054f61e6293d3b0f34059a2a69f46460
BLAKE2b-256 90588c0f7e9dcd4de930b75fb62ad25bac753bbeab2f067975dbaa2be35846e8

See more details on using hashes here.

File details

Details for the file litequant-3.0.2-py3-none-any.whl.

File metadata

  • Download URL: litequant-3.0.2-py3-none-any.whl
  • Upload date:
  • Size: 25.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for litequant-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56442f09f169ff4d102d8cd67737087e1b5f91de2afbd8de75100342653b4d62
MD5 a7ee7e3a15f49d501800b9b6ef5b8c70
BLAKE2b-256 15ac4f01330cd0adc6fbf808b5c6f83e9a0709db8b085e77c94942e10d8879c8

See more details on using hashes here.

Supported by

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