ecapi-sdk 0.1.3__tar.gz → 3.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ecapi_sdk-3.1.1/PKG-INFO +114 -0
- ecapi_sdk-3.1.1/README.md +96 -0
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/pyproject.toml +1 -2
- ecapi_sdk-3.1.1/src/ecapi_sdk/__init__.py +3 -0
- ecapi_sdk-3.1.1/src/ecapi_sdk/client.py +1055 -0
- ecapi_sdk-3.1.1/src/ecapi_sdk/client.pyi +1142 -0
- ecapi_sdk-3.1.1/src/ecapi_sdk.egg-info/PKG-INFO +114 -0
- ecapi_sdk-0.1.3/PKG-INFO +0 -150
- ecapi_sdk-0.1.3/README.md +0 -132
- ecapi_sdk-0.1.3/src/ecapi_sdk/__init__.py +0 -4
- ecapi_sdk-0.1.3/src/ecapi_sdk/client.py +0 -925
- ecapi_sdk-0.1.3/src/ecapi_sdk/client.pyi +0 -831
- ecapi_sdk-0.1.3/src/ecapi_sdk.egg-info/PKG-INFO +0 -150
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/setup.cfg +0 -0
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/src/ecapi_sdk/py.typed +0 -0
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/src/ecapi_sdk.egg-info/SOURCES.txt +0 -0
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/src/ecapi_sdk.egg-info/dependency_links.txt +0 -0
- {ecapi_sdk-0.1.3 → ecapi_sdk-3.1.1}/src/ecapi_sdk.egg-info/top_level.txt +0 -0
ecapi_sdk-3.1.1/PKG-INFO
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ecapi-sdk
|
|
3
|
+
Version: 3.1.1
|
|
4
|
+
Summary: ECAPI SDK for Python
|
|
5
|
+
Author: EaseCation
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/easecation/easecation-api/tree/main/sdk/python/ecapi-sdk
|
|
8
|
+
Project-URL: Documentation, https://github.com/easecation/easecation-api/tree/main/sdk/python/ecapi-sdk#readme
|
|
9
|
+
Project-URL: Source, https://github.com/easecation/easecation-api
|
|
10
|
+
Project-URL: Issues, https://github.com/easecation/easecation-api/issues
|
|
11
|
+
Keywords: ecapi,easecation,sdk,python
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Requires-Python: >=3.9
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# ecapi-sdk (Python)
|
|
20
|
+
|
|
21
|
+
ECAPI 的 Python SDK,面向当前重构后的 REST/OpenAPI 契约。当前门面由 `openapi.json` 生成并覆盖全部 160 个接口,并随包提供 `py.typed` 与 `client.pyi`,方便 IDE 显示参数、必填字段和 docstring。
|
|
22
|
+
|
|
23
|
+
## 安装
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install ecapi-sdk
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
仓库内更新 SDK 文档和类型提示:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
python3 sdk/generate_sdk_api_reference.py
|
|
33
|
+
python3 -m py_compile sdk/python/ecapi-sdk/src/ecapi_sdk/client.py
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## 快速开始
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from ecapi_sdk import ECAPIClient, ECAPIError, is_ecapi_error
|
|
40
|
+
|
|
41
|
+
client = ECAPIClient(
|
|
42
|
+
base_url="https://api.easecation.net",
|
|
43
|
+
auth={"type": "apiKey", "apiKey": "ec_xxx"},
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
me = client.user.get_me()
|
|
48
|
+
player = client.player.get_info({"displayName": "Steve"})
|
|
49
|
+
wallet = client.player.get_wallet("player-ecid")
|
|
50
|
+
except ECAPIError as error:
|
|
51
|
+
print(error.status, error.code, error.request_id, str(error))
|
|
52
|
+
raise
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## 认证方式
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
client.set_api_key("ec_xxx")
|
|
59
|
+
client.set_bearer_token("legacy-or-jwt-token")
|
|
60
|
+
client.set_app_session_token("app-session-token")
|
|
61
|
+
client.clear_auth()
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
也可以在单次请求中传入 `auth=...` 覆盖默认认证;传 `auth=None` 表示本次不发送认证。
|
|
65
|
+
|
|
66
|
+
认证来自 IAM callback、短期 token 或其它动态来源时,可以使用 `auth_provider`,SDK 会在每次请求前调用它:
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
client = ECAPIClient(
|
|
70
|
+
auth_provider=lambda: {"type": "apiKey", "apiKey": get_current_api_key()},
|
|
71
|
+
)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
如果 `auth_provider` 返回 awaitable,且当前没有正在运行的 event loop,同步客户端会用 `asyncio.run()` 等待它;在已有 event loop 中请使用同步 provider 或在业务层先解析认证。
|
|
75
|
+
|
|
76
|
+
## 类型提示与文档
|
|
77
|
+
|
|
78
|
+
- `client.py` 与 `client.pyi` 均从 OpenAPI 生成,query/body 会生成 `TypedDict`,字段必填性来自 OpenAPI。
|
|
79
|
+
- `API_REFERENCE.md` 会列出方法、接口说明、权限、HTTP 方法、路径、必填参数和可选参数。
|
|
80
|
+
- `ECAPIError` 会提取服务端错误 envelope 中的 `code`、`request_id`、`details`、`field` 和用户友好的 `message`。
|
|
81
|
+
|
|
82
|
+
## 常用调用
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
client.system.get_health()
|
|
86
|
+
client.system.get_liveness()
|
|
87
|
+
client.system.get_readiness()
|
|
88
|
+
|
|
89
|
+
client.player.search_ecid({"search": "Steve"})
|
|
90
|
+
client.player.cutoff_leaderboard.get_leaderboard({"game": "bedwar"})
|
|
91
|
+
client.punish.create({
|
|
92
|
+
"type": "WARNING",
|
|
93
|
+
"ecid": "player-ecid",
|
|
94
|
+
"source": "console",
|
|
95
|
+
"reason": "测试警告",
|
|
96
|
+
})
|
|
97
|
+
client.punish.set_parkour_punishment({
|
|
98
|
+
"ecid": "player-ecid",
|
|
99
|
+
"map": "parkour_01",
|
|
100
|
+
"start": 1717200000,
|
|
101
|
+
"end": 1717286400,
|
|
102
|
+
"usetime": 12345,
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
未封装或临时接口可使用统一入口:
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
client.request("GET", "/players/info", query={"displayName": "Steve"})
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 契约说明
|
|
113
|
+
|
|
114
|
+
本 SDK 不提供旧路径兼容别名,所有方法都调用新的 REST/OpenAPI 路径。OpenAPI 是路径、参数和权限说明的唯一事实源,完整方法请查看 `API_REFERENCE.md`。
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# ecapi-sdk (Python)
|
|
2
|
+
|
|
3
|
+
ECAPI 的 Python SDK,面向当前重构后的 REST/OpenAPI 契约。当前门面由 `openapi.json` 生成并覆盖全部 160 个接口,并随包提供 `py.typed` 与 `client.pyi`,方便 IDE 显示参数、必填字段和 docstring。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install ecapi-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
仓库内更新 SDK 文档和类型提示:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
python3 sdk/generate_sdk_api_reference.py
|
|
15
|
+
python3 -m py_compile sdk/python/ecapi-sdk/src/ecapi_sdk/client.py
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 快速开始
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from ecapi_sdk import ECAPIClient, ECAPIError, is_ecapi_error
|
|
22
|
+
|
|
23
|
+
client = ECAPIClient(
|
|
24
|
+
base_url="https://api.easecation.net",
|
|
25
|
+
auth={"type": "apiKey", "apiKey": "ec_xxx"},
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
me = client.user.get_me()
|
|
30
|
+
player = client.player.get_info({"displayName": "Steve"})
|
|
31
|
+
wallet = client.player.get_wallet("player-ecid")
|
|
32
|
+
except ECAPIError as error:
|
|
33
|
+
print(error.status, error.code, error.request_id, str(error))
|
|
34
|
+
raise
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## 认证方式
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
client.set_api_key("ec_xxx")
|
|
41
|
+
client.set_bearer_token("legacy-or-jwt-token")
|
|
42
|
+
client.set_app_session_token("app-session-token")
|
|
43
|
+
client.clear_auth()
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
也可以在单次请求中传入 `auth=...` 覆盖默认认证;传 `auth=None` 表示本次不发送认证。
|
|
47
|
+
|
|
48
|
+
认证来自 IAM callback、短期 token 或其它动态来源时,可以使用 `auth_provider`,SDK 会在每次请求前调用它:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
client = ECAPIClient(
|
|
52
|
+
auth_provider=lambda: {"type": "apiKey", "apiKey": get_current_api_key()},
|
|
53
|
+
)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
如果 `auth_provider` 返回 awaitable,且当前没有正在运行的 event loop,同步客户端会用 `asyncio.run()` 等待它;在已有 event loop 中请使用同步 provider 或在业务层先解析认证。
|
|
57
|
+
|
|
58
|
+
## 类型提示与文档
|
|
59
|
+
|
|
60
|
+
- `client.py` 与 `client.pyi` 均从 OpenAPI 生成,query/body 会生成 `TypedDict`,字段必填性来自 OpenAPI。
|
|
61
|
+
- `API_REFERENCE.md` 会列出方法、接口说明、权限、HTTP 方法、路径、必填参数和可选参数。
|
|
62
|
+
- `ECAPIError` 会提取服务端错误 envelope 中的 `code`、`request_id`、`details`、`field` 和用户友好的 `message`。
|
|
63
|
+
|
|
64
|
+
## 常用调用
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
client.system.get_health()
|
|
68
|
+
client.system.get_liveness()
|
|
69
|
+
client.system.get_readiness()
|
|
70
|
+
|
|
71
|
+
client.player.search_ecid({"search": "Steve"})
|
|
72
|
+
client.player.cutoff_leaderboard.get_leaderboard({"game": "bedwar"})
|
|
73
|
+
client.punish.create({
|
|
74
|
+
"type": "WARNING",
|
|
75
|
+
"ecid": "player-ecid",
|
|
76
|
+
"source": "console",
|
|
77
|
+
"reason": "测试警告",
|
|
78
|
+
})
|
|
79
|
+
client.punish.set_parkour_punishment({
|
|
80
|
+
"ecid": "player-ecid",
|
|
81
|
+
"map": "parkour_01",
|
|
82
|
+
"start": 1717200000,
|
|
83
|
+
"end": 1717286400,
|
|
84
|
+
"usetime": 12345,
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
未封装或临时接口可使用统一入口:
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
client.request("GET", "/players/info", query={"displayName": "Steve"})
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## 契约说明
|
|
95
|
+
|
|
96
|
+
本 SDK 不提供旧路径兼容别名,所有方法都调用新的 REST/OpenAPI 路径。OpenAPI 是路径、参数和权限说明的唯一事实源,完整方法请查看 `API_REFERENCE.md`。
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ecapi-sdk"
|
|
7
|
-
version = "
|
|
7
|
+
version = "3.1.1"
|
|
8
8
|
description = "ECAPI SDK for Python"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -34,4 +34,3 @@ where = ["src"]
|
|
|
34
34
|
|
|
35
35
|
[tool.setuptools.package-data]
|
|
36
36
|
ecapi_sdk = ["py.typed", "*.pyi"]
|
|
37
|
-
|