Metadata-Version: 2.1
Name: dxpos-openapi
Version: 0.0.1
Summary: DXPOS OpenAPI Python SDK
Author-email: DXPOS <support@dxpos.co>
License: MIT License
        
        Copyright (c) 2026 DXPOS
        
        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://openapi.dxpos.co
Project-URL: Documentation, https://openapi.dxpos.co
Keywords: dxpos,openapi,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
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: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8.16
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests==2.31.0
Requires-Dist: urllib3==1.26.20
Requires-Dist: certifi==2024.8.30
Requires-Dist: charset-normalizer==3.3.2
Requires-Dist: idna==3.7
Provides-Extra: dev
Requires-Dist: pytest==8.3.5; extra == "dev"
Requires-Dist: build==1.2.2; extra == "dev"
Requires-Dist: twine==5.1.1; extra == "dev"
Requires-Dist: setuptools==75.3.0; extra == "dev"
Requires-Dist: wheel==0.45.1; extra == "dev"

# dxpos-openapi

DXPOS OpenAPI 的 Python SDK。安装后：

```python
from dxpos_openapi import DxposClient
```

需要 Python 3.8.16 及以上。

## 安装

```bash
pip install dxpos-openapi
```

升级：

```bash
pip install -U dxpos-openapi
```

## 初始化

密钥和域名在构造 `DxposClient` 时传入，SDK 不读环境变量。`base_url` 默认生产域名。

```python
from dxpos_openapi import DxposClient

client = DxposClient(
    access_key="你的 Access Key",
    secret_key="你的 Secret Key",
    # base_url="https://openapi-test.dxpos.co",  # 测试环境
)
```

| 环境 | base_url |
|------|----------|
| 生产（默认） | `https://openapi.dxpos.co` |
| 测试 | `https://openapi-test.dxpos.co` |

五个方法会自动做 HMAC 签名，不用自己算。

## 返回值

每个方法都返回接口原样字典，业务失败也不抛异常：

```python
{
    "code": 0,
    "msg": "",
    "data": {},
    "request_id": "req_..."
}
```

`code == 0` 为成功，读 `data`。本地文件不存在、格式不支持、COS 上传失败、网络错误等会合成 `code == -1`。

## 方法

### 主题列表

```python
resp = client.list_themes()
theme_id = resp["data"]["items"][0]["theme_id"]
```

### 上传本地图片

内部会预创建文件并 PUT 到 COS。成功时返回预创建接口的原样 JSON，`data` 里有 `file_id`。

```python
resp = client.upload_file("/path/to/product.jpg")
file_id = resp["data"]["file_id"]
```

仅支持 `.jpg` / `.jpeg` / `.png` / `.webp`。

### 创建场景增强任务

`file_id`、`image_path`、`image_url` 必须三选一。

```python
# 已有公网 URL
resp = client.create_scene_enhancement(
    theme_id=theme_id,
    image_url="https://example.com/product.jpg",
)

# 已经 upload_file 拿到 file_id
resp = client.create_scene_enhancement(theme_id=theme_id, file_id=file_id)

# 本地路径：自动上传再建任务
resp = client.create_scene_enhancement(
    theme_id=theme_id,
    image_path="/path/to/product.jpg",
)

task_id = resp["data"]["task_id"]
```

### 查询任务

```python
resp = client.get_task(task_id)
# data.status: waiting / processing / done / failed / canceled
```

### 取消任务

仅排队中（`waiting`）可取消。

```python
resp = client.cancel_task(task_id)
```

## 维护者：发布到 PyPI

不需要把 token 写进仓库。本机配置 `~/.pypirc`，用 `__token__` 和 API token。

开发依赖：

```bash
pip install -e ".[dev]"
pytest
```

首次 `0.0.1`：

```bash
rm -rf dist build src/*.egg-info
python -m build
twine check dist/*
twine upload -r testpypi dist/*
# 干净环境验证：
# pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple dxpos-openapi==0.0.1
twine upload dist/*
git tag v0.0.1
git push origin main --tags
```

以后更新：同步改 `pyproject.toml` 的 `version` 和 `src/dxpos_openapi/__init__.py` 的 `__version__`，再走一遍 build / twine / tag。同一版本号不能覆盖重传。小改用 `0.0.x`，加方法或改入参用 `0.1.0`。
