Wisharetec SaaS 系统的 Python 客户端库,提供同步和异步接口调用能力。
Project description
py_wisharetec
Wisharetec SaaS 系统的 Python 客户端库,提供同步和异步接口调用能力。
功能特性
- 同步/异步 HTTP 客户端支持
- 登录认证与令牌管理
- 令牌缓存机制(支持 diskcache 和 Redis)
- 请求封装与响应处理
- JSON 数据校验与查询工具
安装
pip install py_wisharetec
快速开始
同步模式
from py_wisharetec.saas import Saas
# 初始化客户端
saas = Saas(
base_url="https://saas.wisharetec.com/",
account="your_account",
password="your_password"
)
# 登录并刷新令牌
saas.refresh_token()
# 发起请求
response = saas.request(
method="GET",
url="/api/your-endpoint"
)
print(response.json())
异步模式
import asyncio
from py_wisharetec.saas import Saas
async def main():
# 初始化客户端
saas = Saas(
base_url="https://saas.wisharetec.com/",
account="your_account",
password="your_password"
)
# 异步登录并刷新令牌
await saas.async_refresh_token()
# 发起异步请求
response = await saas.async_request(
method="GET",
url="/api/your-endpoint"
)
print(response.json())
asyncio.run(main())
配置选项
初始化参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| base_url | str | https://saas.wisharetec.com/ | SaaS 服务基础 URL |
| account | str | None | 账号 |
| password | str | None | 密码 |
| cache_config | dict | {} | 缓存配置 |
| client_kwargs | dict | {} | HTTP 客户端额外参数 |
缓存配置
cache_config = {
"instance": None, # diskcache.Cache 或 redis.Redis 实例
"key": "py_wisharetec_saas_{account}", # 缓存键名
"expire": 7100 # 过期时间(秒)
}
客户端配置
client_kwargs = {
"timeout": 60, # 请求超时时间
"verify": False, # 是否验证 SSL 证书
"headers": {
"client": "co-pc"
}
}
API 参考
Saas 类
同步方法
client()- 创建同步 HTTP 客户端login(**kwargs)- 登录系统refresh_token(**kwargs)- 刷新令牌request(**kwargs)- 发起请求query_space_manage_tree(**kwargs)- 查询空间管理树
异步方法
async_client()- 创建异步 HTTP 客户端async_login(**kwargs)- 异步登录系统async_refresh_token(**kwargs)- 异步刷新令牌async_request(**kwargs)- 发起异步请求async_query_space_manage_tree(**kwargs)- 异步查询空间管理树
工具函数
json_find_first(expression, data)- 使用 JSONPath 查找第一个匹配项json_is_valid(schema, data)- 校验 JSON 数据是否符合 Schema
示例
使用缓存
import diskcache
from py_wisharetec.saas import Saas
# 创建缓存实例
cache = diskcache.Cache("./cache")
# 初始化客户端(带缓存)
saas = Saas(
account="your_account",
password="your_password",
cache_config={
"instance": cache,
"expire": 7200
}
)
# 登录(自动使用缓存)
saas.refresh_token()
依赖
- httpx >= 0.27.0
- pydantic >= 2.0.0
- diskcache >= 5.0.0 (可选)
- redis >= 5.0.0 (可选)
- jsonpath-ng >= 1.6.0
- jsonschema >= 4.0.0
主页
https://gitee.com/guolei19850528/py_wisharetec
许可证
MIT License
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
py_wisharetec-0.1.0.tar.gz
(8.3 kB
view details)
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