py_wisharetec_toolkit 3.0.2__py3-none-any.whl
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.
- py_wisharetec_toolkit/__init__.py +11 -0
- py_wisharetec_toolkit/py.typed +0 -0
- py_wisharetec_toolkit/shanshu/__init__.py +18 -0
- py_wisharetec_toolkit/shanshu/auth.py +143 -0
- py_wisharetec_toolkit/shanshu/client.py +2218 -0
- py_wisharetec_toolkit/shanshu/models.py +1276 -0
- py_wisharetec_toolkit-3.0.2.dist-info/METADATA +313 -0
- py_wisharetec_toolkit-3.0.2.dist-info/RECORD +10 -0
- py_wisharetec_toolkit-3.0.2.dist-info/WHEEL +5 -0
- py_wisharetec_toolkit-3.0.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: py_wisharetec_toolkit
|
|
3
|
+
Version: 3.0.2
|
|
4
|
+
Summary: 浙江慧享科技有限公司 - 善数・慧享云运营平台 Python 扩展包,提供接口调用封装
|
|
5
|
+
Author-email: guolei <174000902@qq.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://gitee.com/guolei19850528/py_wisharetec_toolkit
|
|
8
|
+
Keywords: wisharetec,wisharetec_toolkit,shanshu,saas.wisharetec.com,saas toolkit
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Intended Audience :: Developers
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
Requires-Dist: httpx>=0.24.0
|
|
23
|
+
Requires-Dist: pydantic>=2.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
27
|
+
Requires-Dist: black; extra == "dev"
|
|
28
|
+
Requires-Dist: ruff; extra == "dev"
|
|
29
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == "dev"
|
|
30
|
+
Provides-Extra: cache
|
|
31
|
+
Requires-Dist: diskcache>=5.0; extra == "cache"
|
|
32
|
+
Requires-Dist: redis>=5.0; extra == "cache"
|
|
33
|
+
|
|
34
|
+
# py_wisharetec_toolkit
|
|
35
|
+
|
|
36
|
+
浙江慧享科技有限公司 - 善数・慧享云运营平台 Python 扩展包。
|
|
37
|
+
|
|
38
|
+
本包封装了善数・慧享云运营平台 (https://saas.wisharetec.com/) 的各类 API 接口,提供同步客户端 `ShanshuClient` 和异步客户端 `AsyncShanshuClient`,供他人调用。
|
|
39
|
+
|
|
40
|
+
**作者**:guolei <174000902@qq.com>
|
|
41
|
+
**项目主页**:https://gitee.com/guolei19850528/py_wisharetec_toolkit
|
|
42
|
+
|
|
43
|
+
## 安装
|
|
44
|
+
|
|
45
|
+
### 推荐使用 uv 安装(推荐)
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv pip install py_wisharetec_toolkit
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
或从本地源码安装(开发模式):
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
uv pip install -e .
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
带缓存依赖安装(diskcache / redis):
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
uv pip install py_wisharetec_toolkit[cache]
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
或从本地源码安装(开发模式,带缓存依赖):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
uv pip install -e ".[cache]"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### 或者使用 pip 安装
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install py_wisharetec_toolkit
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
或从本地源码安装(开发模式):
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install -e .
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
带缓存依赖安装(diskcache / redis):
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install py_wisharetec_toolkit[cache]
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
或从本地源码安装(开发模式,带缓存依赖):
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pip install -e ".[cache]"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 配置
|
|
94
|
+
|
|
95
|
+
账号、密码等敏感信息统一通过环境变量(`.env` 文件)配置,请勿写入代码。
|
|
96
|
+
|
|
97
|
+
下文示例使用 `python-dotenv` 读取 `.env`,如未安装可执行:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install python-dotenv
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
在项目根目录创建 `.env` 文件并填写真实信息:
|
|
104
|
+
|
|
105
|
+
```dotenv
|
|
106
|
+
SHANSHU_BASE_URL=https://saas.wisharetec.com/
|
|
107
|
+
SHANSHU_ACCOUNT=your_account_here
|
|
108
|
+
SHANSHU_PASSWORD=your_password_here
|
|
109
|
+
|
|
110
|
+
# 空间树 ID(对应登录返回的 orgIds,可按需修改)
|
|
111
|
+
SHANSHU_SPACE_TREE_ID=73
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## 快速开始
|
|
115
|
+
|
|
116
|
+
### 同步客户端
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
import os
|
|
120
|
+
from pathlib import Path
|
|
121
|
+
|
|
122
|
+
from dotenv import load_dotenv
|
|
123
|
+
|
|
124
|
+
from py_wisharetec_toolkit.shanshu.auth import ShanshuDiskCacheTokenCache
|
|
125
|
+
from py_wisharetec_toolkit.shanshu.client import ShanshuClient
|
|
126
|
+
from py_wisharetec_toolkit.shanshu.models import ShanshuPageQueryParams
|
|
127
|
+
|
|
128
|
+
# 从本地 .env 文件读取账号和密码(不建议在代码中硬编码)
|
|
129
|
+
load_dotenv(dotenv_path=Path(__file__).parent / ".env")
|
|
130
|
+
|
|
131
|
+
base_url = os.environ.get(
|
|
132
|
+
"SHANSHU_BASE_URL", "https://saas.wisharetec.com/"
|
|
133
|
+
)
|
|
134
|
+
account = os.environ["SHANSHU_ACCOUNT"]
|
|
135
|
+
password = os.environ["SHANSHU_PASSWORD"]
|
|
136
|
+
space_tree_id = os.environ.get("SHANSHU_SPACE_TREE_ID", "73")
|
|
137
|
+
|
|
138
|
+
# 创建客户端(token 自动缓存到 diskcache)
|
|
139
|
+
token_cache = ShanshuDiskCacheTokenCache(cache_dir=".runtime/cache/diskcache")
|
|
140
|
+
client = ShanshuClient(
|
|
141
|
+
base_url=base_url,
|
|
142
|
+
account=account,
|
|
143
|
+
password=password,
|
|
144
|
+
token_cache=token_cache,
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
# 登录
|
|
148
|
+
client.login(account, password)
|
|
149
|
+
|
|
150
|
+
# 查询园区档案
|
|
151
|
+
params = ShanshuPageQueryParams(
|
|
152
|
+
conditions={
|
|
153
|
+
"fields": [
|
|
154
|
+
{"map": {}, "method": 1, "name": "spaceTreeId", "value": space_tree_id},
|
|
155
|
+
{"map": {}, "method": 1, "name": "flag", "value": 0},
|
|
156
|
+
]
|
|
157
|
+
},
|
|
158
|
+
page_num=1,
|
|
159
|
+
page_size=20,
|
|
160
|
+
)
|
|
161
|
+
resp = client.query_community_with_paginator(params=params)
|
|
162
|
+
print(resp.ok, resp.total, len(resp.records or []))
|
|
163
|
+
|
|
164
|
+
client.close()
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 异步客户端
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
import asyncio
|
|
171
|
+
import os
|
|
172
|
+
from pathlib import Path
|
|
173
|
+
|
|
174
|
+
from dotenv import load_dotenv
|
|
175
|
+
|
|
176
|
+
from py_wisharetec_toolkit.shanshu.auth import ShanshuDiskCacheTokenCache
|
|
177
|
+
from py_wisharetec_toolkit.shanshu.client import AsyncShanshuClient
|
|
178
|
+
from py_wisharetec_toolkit.shanshu.models import ShanshuPageQueryParams
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
async def main() -> None:
|
|
182
|
+
# 从本地 .env 文件读取账号和密码
|
|
183
|
+
load_dotenv(dotenv_path=Path(__file__).parent / ".env")
|
|
184
|
+
|
|
185
|
+
base_url = os.environ.get(
|
|
186
|
+
"SHANSHU_BASE_URL", "https://saas.wisharetec.com/"
|
|
187
|
+
)
|
|
188
|
+
account = os.environ["SHANSHU_ACCOUNT"]
|
|
189
|
+
password = os.environ["SHANSHU_PASSWORD"]
|
|
190
|
+
space_tree_id = os.environ.get("SHANSHU_SPACE_TREE_ID", "73")
|
|
191
|
+
|
|
192
|
+
token_cache = ShanshuDiskCacheTokenCache(cache_dir=".runtime/cache/diskcache")
|
|
193
|
+
client = AsyncShanshuClient(
|
|
194
|
+
base_url=base_url,
|
|
195
|
+
account=account,
|
|
196
|
+
password=password,
|
|
197
|
+
token_cache=token_cache,
|
|
198
|
+
)
|
|
199
|
+
try:
|
|
200
|
+
await client.async_login(account, password)
|
|
201
|
+
|
|
202
|
+
params = ShanshuPageQueryParams(
|
|
203
|
+
conditions={
|
|
204
|
+
"fields": [
|
|
205
|
+
{"map": {}, "method": 1, "name": "spaceTreeId", "value": space_tree_id},
|
|
206
|
+
{"map": {}, "method": 1, "name": "flag", "value": 0},
|
|
207
|
+
]
|
|
208
|
+
},
|
|
209
|
+
page_num=1,
|
|
210
|
+
page_size=20,
|
|
211
|
+
)
|
|
212
|
+
resp = await client.async_query_community_with_paginator(params=params)
|
|
213
|
+
print(resp.ok, resp.total, len(resp.records or []))
|
|
214
|
+
finally:
|
|
215
|
+
await client.async_close()
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
asyncio.run(main())
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## 已实现的接口
|
|
222
|
+
|
|
223
|
+
| 接口 | 方法 | 路径 | 返回模型 |
|
|
224
|
+
|------|------|------|----------|
|
|
225
|
+
| 登录 | `login` / `async_login` | `/api/user/loginInteractive` | `ShanshuLoginResponse` |
|
|
226
|
+
| 园区档案 | `query_community_with_paginator` / `async_query_community_with_paginator` | `/api/space/community/v2/frontPage` | `ShanshuCommunityPageResponse` |
|
|
227
|
+
| 房产档案 | `query_property_with_paginator` / `async_query_property_with_paginator` | `/api/space/property/propertyPage` | `ShanshuPropertyPageResponse` |
|
|
228
|
+
| 车场档案 | `query_yard_archive_with_paginator` / `async_query_yard_archive_with_paginator` | `/api/space/space/yardArchivePage` | `ShanshuYardArchivePageResponse` |
|
|
229
|
+
| 楼幢档案 | `query_building_with_paginator` / `async_query_building_with_paginator` | `/api/space/property/getSpaceBuildingPage` | `ShanshuBuildingPageResponse` |
|
|
230
|
+
| 住户档案 | `query_resident_with_paginator` / `async_query_resident_with_paginator` | `/api/user/residentInfo/getResidentPage` | `ShanshuResidentPageResponse` |
|
|
231
|
+
| 业主档案 | `query_archive_with_paginator` / `async_query_archive_with_paginator` | `/api/space/archive/examine/page` | `ShanshuArchivePageResponse` |
|
|
232
|
+
| 车辆档案 | `query_car_manage_with_paginator` / `async_query_car_manage_with_paginator` | `/api/space/carManage/pageCarManage` | `ShanshuCarManagePageResponse` |
|
|
233
|
+
| 车位档案 | `query_parking_with_paginator` / `async_query_parking_with_paginator` | `/api/space/parking/parkingPage` | `ShanshuParkingPageResponse` |
|
|
234
|
+
| 工单档案 | `query_work_order_with_paginator` / `async_query_work_order_with_paginator` | `/api/woreport/task/query/page` | `ShanshuWorkOrderPageResponse` |
|
|
235
|
+
| 商城订单 | `query_mall_order_with_paginator` / `async_query_mall_order_with_paginator` | `/api/retailmall/order/pageFront` | `ShanshuMallOrderPageResponse` |
|
|
236
|
+
| 服务订单 | `query_service_order_with_paginator` / `async_query_service_order_with_paginator` | `/api/houseserve/order/pageFront` | `ShanshuServiceOrderPageResponse` |
|
|
237
|
+
| 审批数据 | `query_approval_with_paginator` / `async_query_approval_with_paginator` | `/api/bpm/process/approval` | `ShanshuApprovalPageResponse` |
|
|
238
|
+
| 审批详情 | `query_approval_detail` / `async_query_approval_detail` | `/api/bpm/process/progress/{instance_id}/node_433279443693` | `ShanshuApprovalDetailRecord` |
|
|
239
|
+
| 业主详情 | `query_owner_detail` / `async_query_owner_detail` | `/api/space/archive/archive/detailSensitive` | `ShanshuOwnerDetailRecord` |
|
|
240
|
+
|
|
241
|
+
所有分页接口均使用 `ShanshuPageQueryParams` 模型封装查询参数,包含 `conditions`、`count`、`last`、`order_by`、`page_num`、`page_size` 字段。
|
|
242
|
+
|
|
243
|
+
### 接口注意事项
|
|
244
|
+
|
|
245
|
+
- 园区、房产、楼幢、车场、业主、车辆、车位、审批等接口的 `conditions` 需携带 `spaceTreeId` 与 `flag`。
|
|
246
|
+
- 住户档案接口需传入空条件:`conditions={}`。
|
|
247
|
+
- 工单档案接口要求 `conditions` 中额外携带 `appCode=WORK_ORDER`。
|
|
248
|
+
- 审批详情需先通过审批列表接口获取 `procInstId`,节点 ID 固定为 `node_433279443693`;业主详情需先获取 `userId` / `communityId` / `spaceId`,再调用详情接口。
|
|
249
|
+
|
|
250
|
+
## 运行测试
|
|
251
|
+
|
|
252
|
+
测试用例位于 `tests/shanshu/`,基于 pytest + pytest-asyncio,统一从 `tests/shanshu/.env` 读取配置,公共夹具定义在 `tests/shanshu/conftest.py`。
|
|
253
|
+
|
|
254
|
+
1. 复制模板并填写真实账号(也可以直接导出 `SHANSHU_*` 环境变量):
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
cp tests/shanshu/.env.example tests/shanshu/.env
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
2. 安装测试依赖并运行:
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
uv pip install -e ".[dev,cache]"
|
|
264
|
+
pytest tests/shanshu -q
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
未配置 `SHANSHU_ACCOUNT` / `SHANSHU_PASSWORD` 时,测试会自动跳过。
|
|
268
|
+
|
|
269
|
+
## Token 缓存
|
|
270
|
+
|
|
271
|
+
客户端支持三种 Token 缓存后端:
|
|
272
|
+
|
|
273
|
+
- `ShanshuMemoryTokenCache`:进程内内存缓存(默认,无需额外依赖)
|
|
274
|
+
- `ShanshuDiskCacheTokenCache`:基于 diskcache 的持久化缓存(需安装 `[cache]` 依赖)
|
|
275
|
+
- `ShanshuRedisTokenCache`:基于 redis 的缓存(需安装 `[cache]` 依赖)
|
|
276
|
+
|
|
277
|
+
缓存 key 格式:`py_wisharetec_toolkit:shanshu:authorization_token:{account}`,便于缓存不同用户的登录 token。
|
|
278
|
+
|
|
279
|
+
## 目录结构
|
|
280
|
+
|
|
281
|
+
```text
|
|
282
|
+
src/py_wisharetec_toolkit/
|
|
283
|
+
├── __init__.py # 顶层包
|
|
284
|
+
├── py.typed # PEP 561 类型标记
|
|
285
|
+
└── shanshu/ # 子包,供他人调用
|
|
286
|
+
├── __init__.py
|
|
287
|
+
├── client.py # 同步客户端 ShanshuClient 与异步客户端 AsyncShanshuClient
|
|
288
|
+
├── auth.py # Token 缓存与认证
|
|
289
|
+
└── models.py # pydantic 响应模型
|
|
290
|
+
|
|
291
|
+
tests/
|
|
292
|
+
└── shanshu/
|
|
293
|
+
├── conftest.py # 公共夹具(客户端、登录、查询条件)
|
|
294
|
+
├── .env.example # 测试配置模板
|
|
295
|
+
└── test_*.py # 各接口的同步 / 异步测试用例
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## 参数说明
|
|
299
|
+
|
|
300
|
+
所有分页查询接口均使用 `ShanshuPageQueryParams` 模型:
|
|
301
|
+
|
|
302
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
303
|
+
|------|------|--------|------|
|
|
304
|
+
| conditions | dict\|None | None | 查询条件 |
|
|
305
|
+
| count | bool | True | 是否返回总记录数 |
|
|
306
|
+
| last | bool | True | 是否返回 last 标志 |
|
|
307
|
+
| order_by | list\|None | None | 排序字段列表 |
|
|
308
|
+
| page_num | int | 1 | 页码 |
|
|
309
|
+
| page_size | int | 20 | 每页大小 |
|
|
310
|
+
|
|
311
|
+
## 许可证
|
|
312
|
+
|
|
313
|
+
MIT License
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
py_wisharetec_toolkit/__init__.py,sha256=KZTnCWxwgeIOSSIkhMXuSDqjv6icBa9QNBLMLak-ddE,232
|
|
2
|
+
py_wisharetec_toolkit/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
py_wisharetec_toolkit/shanshu/__init__.py,sha256=MK2dLTx6glmmrFegdElx5wIEn5e-maMjPpzzhXBzs18,525
|
|
4
|
+
py_wisharetec_toolkit/shanshu/auth.py,sha256=x8z8SJaOZPQJGNtwePtqiH-gbImJcuRr3DZxM9wUzs4,4042
|
|
5
|
+
py_wisharetec_toolkit/shanshu/client.py,sha256=reWq4FrJFWt8PBdAjmFUYoo5JMpTpPYz01y0QhLofFs,77423
|
|
6
|
+
py_wisharetec_toolkit/shanshu/models.py,sha256=HJ67zxhcH6wwB70ipf7cnoqouXv6goub0dR6bhG26-4,39620
|
|
7
|
+
py_wisharetec_toolkit-3.0.2.dist-info/METADATA,sha256=emhrdobiW1_QuvNkzYgSELxOhAVjP8LUVoslrPFZ6JM,11418
|
|
8
|
+
py_wisharetec_toolkit-3.0.2.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
9
|
+
py_wisharetec_toolkit-3.0.2.dist-info/top_level.txt,sha256=UwXO5AvfOi0dIDQrcGqnMPKS-Qfxa2tXX9Im7NvQ05E,22
|
|
10
|
+
py_wisharetec_toolkit-3.0.2.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
py_wisharetec_toolkit
|