Metadata-Version: 2.4
Name: py-wisharetec
Version: 0.1.1
Summary: Wisharetec SaaS 系统的 Python 客户端库，提供同步和异步接口调用能力。
Author-email: Guolei <174000902@qq.com>
License: MIT License
        
        Copyright (c) 2026 郭磊
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://gitee.com/guolei19850528/py_wisharetec
Project-URL: Repository, https://gitee.com/guolei19850528/py_wisharetec.git
Keywords: wisharetec,python,client,api,wisharetec saas,saas
Classifier: License :: OSI Approved :: MIT License
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27.0
Requires-Dist: pydantic>=2.0
Requires-Dist: jsonpath-ng>=1.5.3
Requires-Dist: jsonschema>=4.21.0
Requires-Dist: diskcache>=5.6.3
Requires-Dist: redis>=4.6.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: setuptools>=61.0; extra == "dev"
Requires-Dist: twine>=4.0; extra == "dev"
Dynamic: license-file

# py_wisharetec

Wisharetec SaaS 系统的 Python 客户端库，提供同步和异步接口调用能力。

## 功能特性

- 同步/异步 HTTP 客户端支持
- 登录认证与令牌管理
- 令牌缓存机制（支持 diskcache 和 Redis）
- 请求封装与响应处理
- JSON 数据校验与查询工具

## 安装

```bash
pip install py_wisharetec
```

## 快速开始

### 同步模式

```python
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())
```

### 异步模式

```python
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 客户端额外参数 |

### 缓存配置

```python
cache_config = {
    "instance": None,           # diskcache.Cache 或 redis.Redis 实例
    "key": "py_wisharetec_saas_{account}",  # 缓存键名
    "expire": 7100             # 过期时间（秒）
}
```

### 客户端配置

```python
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

## 示例

### 使用缓存

```python
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](https://gitee.com/guolei19850528/py_wisharetec)

## 许可证

MIT License
