Python SDK for Gangtise OpenAPI
Project description
gangtise-openapi
Gangtise OpenAPI 的 Python SDK。与 npm CLI gangtise-openapi-cli v0.20.0 功能对齐,覆盖 84 个上游接口,并提供本地鉴权状态辅助工具。
更新日志
最近 5 个版本(完整记录见 CHANGELOG.md):
0.1.10 - 2026-06-27
- 新增证券级数据指标(EDE)域
gangtise.indicator.*(同步+异步,对齐 CLI v0.19.0):search按关键词搜指标码、cross_section取多指标×多证券单日截面、time_series取多指标×单证券(或单指标×多证券)时序;自动把values矩阵摊平成宽表(每行一证券/一日期,指标名作列)、剥离内层双层信封(内层失败码抛ApiError);indicator_param={"qte_close":{"adjustmentType":"2"}}设置前复权等单指标参数。 - 新增美股接口(对齐 CLI v0.20.0):
insight.announcement_us_list/announcement_us_download(镜像港股公告,file_type1=原文PDF 2=Markdown);fundamental.income_statement_us/balance_sheet_us/cash_flow_us。 - 新增
ai.stock_summary_list(个股看点,每证券精炼研究摘要;security必填,空值抛ValidationError防全市场积分误耗)与reference.chiefs_search(按姓名/机构/团队搜首席 ID)。 ai.hot_topic的with_related_securities/with_close_reading改为按布尔下发,传False真正发送false(此前省略字段、服务端走默认);announcement_hk_download新增file_type(1=原文 2=Markdown);缺失凭证报错改为指明缺哪个变量并提示export/gangtise.configure(...)。- 分页改为 fail-soft:扇出分页某页遇不可重试错误(限频/无权限)时保留已取页并发出
UserWarning,不再整体抛错;raw 结果带partial/failedPages(raw=True可见;默认 DataFrame 路径丢这些键、以 warning 为准),与 K 线分片容错一致(同步+异步);ai.knowledge_batch传空query改为抛ValidationError。
0.1.9 - 2026-06-17
- 新增产业公众号资讯接口(对齐 CLI v0.18.0):
insight.official_account_list按关键词/公众号/证券/文章类型(枚举)/行业分页检索,支持search_type(1=标题 2=全文)与rank_type(1=综合 2=时间倒序);insight.official_account_download按article_id下载文章为 txt(默认file_type=1)或 HTML(file_type=2)。同步+异步双实现,下载走 title 缓存解析文件名。
0.1.8 - 2026-06-16
- 服务端把 token 挤掉(他处登录)导致本会话失效时,自动重新登录并重试一次(错误码
0000001008加入 auth 重试集合,_call与下载、同步与异步四条路径全覆盖),不再需要手动重新登录;补充对应中文错误提示。对齐 CLI v0.17.2。
0.1.7 - 2026-06-16
- 修复并发下载临时文件竞态:两个解析到同一目标文件名的下载(同一 id 下载两次、标题相同、或显式相同
output)此前共用<目标>.part,字节交错且互删对方临时文件(表现为DownloadError: No such file);改为每次下载用唯一后缀.part-<uuid>。 - 异步下载不再因
mkdir/replace/unlink等元数据 syscall 阻塞事件循环(改走anyio.to_thread)。 - 内部清理:
reference.securities_search、alternative.edb_search改用共享_extract_rows;测试从 413 增至 431(并发下载回归、财报列式矩阵转置、异步 body 映射、异步轮询重试)。
0.1.6 - 2026-06-15
- 对齐 TS CLI v0.16.0/v0.17.0:新增 5 个
reference接口(constant/concept/sector),下线 6 个本地 lookup 表;4 个日程列表(路演/调研/策略会/论坛)各自精简为服务端实际支持的筛选项,传入不支持的参数现在抛TypeError而非静默返回空表;announcement_list删除服务端始终忽略的announcement_type参数。 - 修复
ai.knowledge_batch传空列表时向服务端发送"resourceTypes":[](TS 会省略该字段,可能导致 API 报错)。 - 修复
is_all_market(["all", "000001.SZ"])误触发全市场分片(TS 只对恰好["all"]分片)。 - 对齐
410110/410111错误提示文案(提及*-check命令与"终态"描述)。
安装
pip install gangtise-openapi
需要 Python 3.10+。
配置
export GANGTISE_ACCESS_KEY=ak_xxx
export GANGTISE_SECRET_KEY=sk_xxx
(也可在创建 GangtiseClient 时直接传入 access_key= 和 secret_key=;直接构造的 client 需配合域封装类调用接口:from gangtise_openapi.domains import Quote; Quote(client).day_kline(...)。)令牌缓存文件位于 ~/.config/gangtise/token.json,与 npm CLI 共用同一份。
快速开始
from gangtise_openapi import gangtise
# 表格类接口返回 pandas DataFrame
df = gangtise.quote.day_kline(
security="000001.SH",
start_date="2026-01-01",
end_date="2026-01-31",
)
# 传 raw=True 获取底层 dict/list
result = gangtise.insight.opinion_list(industry=1, size=20, raw=True)
# 异步
import asyncio
async def main():
df = await gangtise.async_.quote.day_kline(security="000001.SH")
asyncio.run(main())
示例
每个公开的 SDK 方法都配有可独立运行、便于客户自测的脚本。
uv run python sample/sync/quote_day_kline.py
uv run python sample/async/quote_day_kline.py
返回 DataFrame 的示例会直接打印 DataFrame;文本或 dict/list 响应会以标准 Markdown 文件写入 sample_outputs/;下载类示例会把真实文件写入 sample_downloads/,并尽量保留服务端提供或原始的文件名与扩展名。
运行说明见 sample/README.md,完整的方法参数文档见 sample/API_PARAMETERS.md。
接口
SDK 覆盖 10 个领域下的 84 个上游接口:
gangtise.auth.*— 登录、状态gangtise.lookup.*— 本地查表(券商机构、会议机构)gangtise.reference.*— 证券搜索(GTS 代码)、常量分类与常量值(行业/城市/公告分类/区域)、题材 ID 搜索、板块 ID 搜索与成分股gangtise.insight.*— 观点、研报、公告、日程gangtise.quote.*— K 线、实时行情gangtise.fundamental.*— 财务报表、估值、股东、盈利预测gangtise.ai.*— AI 生成的洞察(一页通、同业对比、业绩点评等)gangtise.vault.*— 个人云盘、会议记录、股票池、微信gangtise.alternative.*— 经济指标(EDB)、题材(概念)指数画像与成分股gangtise.indicator.*— 证券级数据指标(EDE):搜索指标码、截面、时序
Python 封装接受与 CLI 参数相同的入参,只是用 snake_case 代替 --kebab-case。例如 CLI 的 --start-date 对应 Python 的 start_date。
许可证
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gangtise_openapi-0.1.11.tar.gz.
File metadata
- Download URL: gangtise_openapi-0.1.11.tar.gz
- Upload date:
- Size: 67.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85abf168c123a7490fa512d735266f85ca4e5446bf9e32922fc29a6fd63db476
|
|
| MD5 |
71c32983ec2855d862091bf40571c5c6
|
|
| BLAKE2b-256 |
3a8e1f67ada92b1ffe43bfd247ede053e6910f3e9f69a21d72c5645169a34688
|
Provenance
The following attestation bundles were made for gangtise_openapi-0.1.11.tar.gz:
Publisher:
release.yml on gangtiser/gangtise-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gangtise_openapi-0.1.11.tar.gz -
Subject digest:
85abf168c123a7490fa512d735266f85ca4e5446bf9e32922fc29a6fd63db476 - Sigstore transparency entry: 2010023851
- Sigstore integration time:
-
Permalink:
gangtiser/gangtise-python@c50ed2aae4a9862a6cca2dd02710cfdaabb96307 -
Branch / Tag:
refs/tags/v0.1.11 - Owner: https://github.com/gangtiser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c50ed2aae4a9862a6cca2dd02710cfdaabb96307 -
Trigger Event:
push
-
Statement type:
File details
Details for the file gangtise_openapi-0.1.11-py3-none-any.whl.
File metadata
- Download URL: gangtise_openapi-0.1.11-py3-none-any.whl
- Upload date:
- Size: 74.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d712a6bc3ab358aecb1892396bd9535ed857f7d220baadf343655f52c75e8bdc
|
|
| MD5 |
c2eb75e0fc6ebba57185c1989008585a
|
|
| BLAKE2b-256 |
4ca5d92388fbee824f0fdd51cf6c7748d08de9f63649ef9e618435933b482751
|
Provenance
The following attestation bundles were made for gangtise_openapi-0.1.11-py3-none-any.whl:
Publisher:
release.yml on gangtiser/gangtise-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
gangtise_openapi-0.1.11-py3-none-any.whl -
Subject digest:
d712a6bc3ab358aecb1892396bd9535ed857f7d220baadf343655f52c75e8bdc - Sigstore transparency entry: 2010023942
- Sigstore integration time:
-
Permalink:
gangtiser/gangtise-python@c50ed2aae4a9862a6cca2dd02710cfdaabb96307 -
Branch / Tag:
refs/tags/v0.1.11 - Owner: https://github.com/gangtiser
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c50ed2aae4a9862a6cca2dd02710cfdaabb96307 -
Trigger Event:
push
-
Statement type: