wechatpay-python 0.0.1__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.
wechat_py/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """Foundation for WeChat API integrations."""
2
+
3
+ from .client import WeChatClient
4
+ from .exceptions import WeChatAPIError, WeChatError, WeChatTransportError
5
+
6
+ __all__ = ["WeChatClient", "WeChatError", "WeChatAPIError", "WeChatTransportError"]
wechat_py/client.py ADDED
@@ -0,0 +1,58 @@
1
+ """A small synchronous HTTP client for WeChat APIs."""
2
+
3
+ from typing import Any, Dict, Optional
4
+
5
+ import httpx
6
+
7
+ from .exceptions import WeChatAPIError, WeChatTransportError
8
+
9
+
10
+ class WeChatClient:
11
+ """Send requests to WeChat APIs.
12
+
13
+ An injected HTTP client remains owned by its caller. Otherwise this instance
14
+ owns and closes its HTTP client.
15
+ """
16
+
17
+ def __init__(
18
+ self,
19
+ *,
20
+ base_url: str = "https://api.weixin.qq.com/",
21
+ timeout: float = 10.0,
22
+ http_client: Optional[httpx.Client] = None,
23
+ ) -> None:
24
+ self._owns_client = http_client is None
25
+ self._client = (
26
+ http_client
27
+ if http_client is not None
28
+ else httpx.Client(base_url=base_url, timeout=timeout)
29
+ )
30
+
31
+ def request(self, method: str, path: str, **kwargs: Any) -> Dict[str, Any]:
32
+ """Request a JSON object and raise an exception for HTTP or API errors."""
33
+ try:
34
+ response = self._client.request(method, path, **kwargs)
35
+ response.raise_for_status()
36
+ data = response.json()
37
+ except (httpx.HTTPError, ValueError) as exc:
38
+ raise WeChatTransportError(
39
+ "WeChat request failed or returned invalid JSON"
40
+ ) from exc
41
+
42
+ if not isinstance(data, dict):
43
+ raise WeChatTransportError("WeChat response must be a JSON object")
44
+ code = data.get("errcode", 0)
45
+ if code != 0:
46
+ raise WeChatAPIError(code, str(data.get("errmsg", "")))
47
+ return data
48
+
49
+ def close(self) -> None:
50
+ """Close the HTTP client if it was created by this instance."""
51
+ if self._owns_client:
52
+ self._client.close()
53
+
54
+ def __enter__(self) -> "WeChatClient":
55
+ return self
56
+
57
+ def __exit__(self, *args: Any) -> None:
58
+ self.close()
@@ -0,0 +1,18 @@
1
+ """Exceptions raised by the SDK."""
2
+
3
+
4
+ class WeChatError(Exception):
5
+ """Base class for SDK errors."""
6
+
7
+
8
+ class WeChatTransportError(WeChatError):
9
+ """The HTTP request failed or the response was not a JSON object."""
10
+
11
+
12
+ class WeChatAPIError(WeChatError):
13
+ """WeChat returned a nonzero error code."""
14
+
15
+ def __init__(self, code: int, message: str) -> None:
16
+ self.code = code
17
+ self.message = message
18
+ super().__init__(f"WeChat API error {code}: {message}")
@@ -0,0 +1,91 @@
1
+ Metadata-Version: 2.4
2
+ Name: wechatpay-python
3
+ Version: 0.0.1
4
+ Summary: A Python SDK foundation for WeChat APIs
5
+ Project-URL: Homepage, https://github.com/tiyee/wechat-py
6
+ Project-URL: Repository, https://github.com/tiyee/wechat-py
7
+ Project-URL: Issues, https://github.com/tiyee/wechat-py/issues
8
+ Author: TiyeeJiang
9
+ License: MIT License
10
+
11
+ Copyright (c) 2026 TiyeeJiang
12
+
13
+ Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ of this software and associated documentation files (the "Software"), to deal
15
+ in the Software without restriction, including without limitation the rights
16
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
+ copies of the Software, and to permit persons to whom the Software is
18
+ furnished to do so, subject to the following conditions:
19
+
20
+ The above copyright notice and this permission notice shall be included in all
21
+ copies or substantial portions of the Software.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29
+ SOFTWARE.
30
+ License-File: LICENSE
31
+ Keywords: api,sdk,wechat,weixin
32
+ Classifier: Development Status :: 2 - Pre-Alpha
33
+ Classifier: Intended Audience :: Developers
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Programming Language :: Python :: 3.9
36
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
37
+ Requires-Python: >=3.9
38
+ Requires-Dist: httpx<1,>=0.27
39
+ Description-Content-Type: text/markdown
40
+
41
+ # wechat-py
42
+
43
+ 微信 API 的 Python SDK 基础框架,使用 uv 管理依赖,支持 Python 3.9 及以上版本。
44
+
45
+ ## 安装
46
+
47
+ 发布到 PyPI 后,可以使用以下命令安装:
48
+
49
+ ```bash
50
+ uv add wechatpay-python
51
+ # 或 pip install wechatpay-python
52
+ ```
53
+
54
+ ## 开发
55
+
56
+ ```bash
57
+ uv sync --group dev
58
+ uv run pytest
59
+ uv run ruff check .
60
+ uv build
61
+ ```
62
+
63
+ ## 使用
64
+
65
+ ```python
66
+ from wechat_py import WeChatAPIError, WeChatClient
67
+
68
+ try:
69
+ with WeChatClient() as client:
70
+ result = client.request(
71
+ "GET", "/some/api", params={"access_token": "YOUR_ACCESS_TOKEN"}
72
+ )
73
+ print(result)
74
+ except WeChatAPIError as exc:
75
+ print(exc.code, exc.message)
76
+ ```
77
+
78
+ 示例中的路径是占位符,使用时请替换为实际接口。当前框架提供同步 JSON 请求、HTTP 和微信 API 错误处理;业务接口、access token 获取和刷新尚未实现。调用方负责凭证管理,避免将密钥提交到仓库。网络或 HTTP 错误以及非 JSON 对象响应会抛出 `WeChatTransportError`。
79
+
80
+ 可通过 `http_client` 注入已配置的 `httpx.Client`;注入的客户端由调用方负责关闭。默认客户端可通过 `base_url` 和 `timeout` 配置,并由 `WeChatClient` 关闭。
81
+
82
+ ## 发布到 PyPI
83
+
84
+ 构建并发布当前版本:
85
+
86
+ ```bash
87
+ uv build
88
+ uv publish dist/wechatpay_python-0.0.1.tar.gz dist/wechatpay_python-0.0.1-py3-none-any.whl
89
+ ```
90
+
91
+ 发布前需具备 PyPI 项目发布权限,并按 uv 提示提供 PyPI API token。请勿将 token 写入项目文件或提交到仓库。
@@ -0,0 +1,7 @@
1
+ wechat_py/__init__.py,sha256=k_7jtn1r5xPZKDxGXVJOab9F0_9Uvl866pP93AY4fYA,239
2
+ wechat_py/client.py,sha256=BuoT2CgH3gy9Qxk_KU2X_Gv1G-QR3CxzpO-MKSf9qaU,1829
3
+ wechat_py/exceptions.py,sha256=d-kH6llERjIq9Ts-VRJPs4b3VI0hwDs6H3k4Cmsihtc,484
4
+ wechatpay_python-0.0.1.dist-info/METADATA,sha256=aoHpM2hdXkKnNxyJDyXNEuj5G4vc2vo4Iih6M3dHq4M,3472
5
+ wechatpay_python-0.0.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
6
+ wechatpay_python-0.0.1.dist-info/licenses/LICENSE,sha256=ZrKzYat2vy2EQzTVpYheUM-WOPSyYJ20P6RFOGgaltI,1067
7
+ wechatpay_python-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.27.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 TiyeeJiang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.