Skip to main content

tokease

词易算力指数平台的 Python SDK。不发请求也能查看每个接口的输入参数和输出字段;配置 API Key 后可以查询 index_basicindex_dailyindex_latestindex_quotetrade_calendar。返回范围由 Key 的权限决定。

安装

发布到 PyPI 之后:

pip install tokease

在仓库里开发:

pip install -e python/tokease

查看接口参数

import tokease

tokease.list_datasets()
tokease.list_datasets("query")
tokease.builtin_indices()
tokease.dataset_params("index_daily")
tokease.dataset_fields("index_daily")
tokease.describe("index_quote")

dataset_params 返回的名称与 POST /api/v1/query 的参数白名单一致。未知参数会在本地直接拒绝,不会发给服务端。

查询数据

import tokease

client = tokease.Client(api_key="tokease_xxxxxxxxxxxx_xxxxxxxx")
daily = client.index_daily(
    index_code="Server_Index",
    start_date="20260801",
    end_date="20260831",
    fields=["trade_date", "index_code", "index_value", "change_rate"],
)

index_basicindex_dailyindex_latestindex_quotetrade_calendar 直接返回 pandas.DataFrame。日期列是 datetime64,点位、价格和涨跌是数值。

API Key 也可以通过环境变量 TOKEASE_API_KEY 传入。服务地址是 pyproject.toml 里的 Homepage,当前为 https://whale.tokease.cn

默认会按 has_more 自动翻页。只要单页时传入 paginate=Falserequest_id 写在 DataFrame.attrs["request_id"]

Key 无效或权限不足时抛出 TokeaseAPIError。省略 index_code 时,服务端只返回该 Key 有权查看的指数。

发布到 PyPI

版本号始终等于仓库根目录 package.jsonversion,不要在 Python 包里另写一份。PyPI 上每个版本只能上传一次。

发布使用 PyPI API Token,不使用 GitHub 受信发布。在 PyPI 账号设置里创建令牌,范围选 Entire account,再写入本仓库的 Actions secret PYPI_API_TOKEN。之后推送与系统版本一致的标签即可发布。本地 .githooks/pre-push 会先核对,版本不一致时标签推不上去:

git tag v1.13.1
git push origin v1.13.1

也可以在 GitHub Actions 里手动运行 Publish tokease,选择 pypitestpypi。TestPyPI 需要在 test.pypi.org 另建一个 API Token,并换成对应的 secret。

Release files for tokease 1.14.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tokease 1.14.1
File Size Uploaded
tokease-1.14.1.tar.gz 15.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tokease 1.14.1
File Interpreter ABI Platform
tokease-1.14.1-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / tokease-1.14.1.tar.gz

Download URL tokease-1.14.1.tar.gz
Size 15.9 kB
Tags Source
SHA-256 checksum
How to use checksums
30c27ee390eb4ac1e7a9120dae385e3e6eac82527a8124bc53bcb335a2ab4ce9
BLAKE2b-256 checksum
How to use checksums
e836308b2d326bac53d355294f865cc52a6c8048b34135e8abc1bf81f727eead
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / tokease-1.14.1-py3-none-any.whl

Download URL tokease-1.14.1-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5a55837400a2c4beb56f2cc0412fbfec0188329b9fdd816e0f719531b0835f84
BLAKE2b-256 checksum
How to use checksums
b7b60fbf6206a20398bf2e4b4f252cdeaa1ebe2101bc7c234e4e62b5be71c2c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.14.2

2 release files

This release

1.14.1 This release

2 release files

1.14.0

2 release files

1.13.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page