ecapi-sdk (Python)
ECAPI 的 Python SDK,面向当前重构后的 REST/OpenAPI 契约。当前门面由 openapi.json 生成并覆盖全部 160 个接口,并随包提供 py.typed 与 client.pyi,方便 IDE 显示参数、必填字段和 docstring。
安装
pip install ecapi-sdk
仓库内更新 SDK 文档和类型提示:
python3 sdk/generate_sdk_api_reference.py
python3 -m py_compile sdk/python/ecapi-sdk/src/ecapi_sdk/client.py
快速开始
from ecapi_sdk import ECAPIClient, ECAPIError, is_ecapi_error
client = ECAPIClient(
base_url="https://api.easecation.net",
auth={"type": "apiKey", "apiKey": "ec_xxx"},
)
try:
me = client.user.get_me()
player = client.player.get_info({"displayName": "Steve"})
wallet = client.player.get_wallet("player-ecid")
except ECAPIError as error:
print(error.status, error.code, error.request_id, str(error))
raise
认证方式
client.set_api_key("ec_xxx")
client.set_bearer_token("iam-jwt-token")
client.set_app_session_token("app-session-token")
client.clear_auth()
也可以在单次请求中传入 auth=... 覆盖默认认证;传 auth=None 表示本次不发送认证。
认证来自 IAM callback、短期 token 或其它动态来源时,可以使用 auth_provider,SDK 会在每次请求前调用它:
client = ECAPIClient(
auth_provider=lambda: {"type": "apiKey", "apiKey": get_current_api_key()},
)
如果 auth_provider 返回 awaitable,且当前没有正在运行的 event loop,同步客户端会用 asyncio.run() 等待它;在已有 event loop 中请使用同步 provider 或在业务层先解析认证。
类型提示与文档
client.py与client.pyi均从 OpenAPI 生成,query/body 会生成TypedDict,字段必填性来自 OpenAPI。API_REFERENCE.md会列出方法、接口说明、权限、HTTP 方法、路径、必填参数和可选参数。ECAPIError会提取服务端错误 envelope 中的code、request_id、details、field和用户友好的message。- 从3.7.14起不自动跟随HTTP重定向,错误保留3xx状态;请直接配置最终API地址,不自动重试。图片等二进制接口的JSON错误同样保留上述字段,成功响应仍返回原字节。
常用调用
client.system.get_health()
client.system.get_liveness()
client.system.get_readiness()
client.player.search_ecid({"search": "Steve"})
client.player.cutoff_leaderboard.get_leaderboard({"game": "bedwar"})
client.server.leaderboard.get_top({
"game": "labour",
"scoreType": "ONLINE",
"deadlineType": "WEEK",
})
client.player.leaderboard.get_rank("player-ecid", {
"game": "labour",
"scoreType": "ONLINE",
"deadlineType": "MONTH",
})
client.punish.create({
"type": "WARNING",
"ecid": "player-ecid",
"source": "console",
"reason": "测试警告",
})
未封装或临时接口可使用统一入口:
client.request("GET", "/players/info", query={"displayName": "Steve"})
契约说明
本 SDK 不提供旧路径兼容别名,所有方法都调用新的 REST/OpenAPI 路径。OpenAPI 是路径、参数和权限说明的唯一事实源,完整方法请查看 API_REFERENCE.md。
Metadata
Release files for ecapi-sdk 3.7.17
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ecapi_sdk-3.7.17.tar.gz | 36.8 kB | Without provenance | Details for ecapi_sdk-3.7.17.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ecapi_sdk-3.7.17-py3-none-any.whl | Python 3 | none | any | Details for ecapi_sdk-3.7.17-py3-none-any.whl |
Total release size: 71.9 kB
Release files / ecapi_sdk-3.7.17.tar.gz
| Download URL | ecapi_sdk-3.7.17.tar.gz |
|---|---|
| Size | 36.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0301ec09aa8103213de714ab3eb790a6efe0e5803118580c09b90f88a124717d
|
|
BLAKE2b-256 checksum How to use checksums |
12b5b5f162b5d474175b01e908741da27494e82a6f2dabd33728ac9304a039ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / ecapi_sdk-3.7.17-py3-none-any.whl
| Download URL | ecapi_sdk-3.7.17-py3-none-any.whl |
|---|---|
| Size | 35.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fe84c341514d4f1a72e2c5e100957c0c8710787273010618c6ca9c82ea1c113
|
|
BLAKE2b-256 checksum How to use checksums |
4a0765b21f09d64d4128a251ebb9448797c479d99fd68ebfd6a5641aeabe23b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for ecapi-sdk 3.7.17
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.