http-mcp-client-server 0.1.0__tar.gz
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.
- http_mcp_client_server-0.1.0/LICENSE +21 -0
- http_mcp_client_server-0.1.0/MANIFEST.in +3 -0
- http_mcp_client_server-0.1.0/PKG-INFO +272 -0
- http_mcp_client_server-0.1.0/PUBLISH.md +235 -0
- http_mcp_client_server-0.1.0/README.md +240 -0
- http_mcp_client_server-0.1.0/pyproject.toml +61 -0
- http_mcp_client_server-0.1.0/src/http_mcp_client/__init__.py +4 -0
- http_mcp_client_server-0.1.0/src/http_mcp_client/server.py +356 -0
- http_mcp_client_server-0.1.0/tests/__init__.py +1 -0
- http_mcp_client_server-0.1.0/tests/test_import.py +17 -0
- http_mcp_client_server-0.1.0/tests/test_server.py +339 -0
- http_mcp_client_server-0.1.0/uv.lock +920 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 http-mcp-client-server
|
|
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.
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: http-mcp-client-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: HTTP MCP Client-Server for video enhancement API
|
|
5
|
+
Project-URL: Homepage, https://github.com/yourusername/http-mcp-client-server
|
|
6
|
+
Project-URL: Repository, https://github.com/yourusername/http-mcp-client-server
|
|
7
|
+
Project-URL: Issues, https://github.com/yourusername/http-mcp-client-server/issues
|
|
8
|
+
Author-email: Your Name <your.email@example.com>
|
|
9
|
+
License: MIT
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: client,enhancement,fastapi,http,mcp,server,video
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Multimedia :: Video
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Requires-Dist: httpx>=0.27.0
|
|
23
|
+
Requires-Dist: mcp>=1.0.0
|
|
24
|
+
Requires-Dist: pydantic>=2.0.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: build>=1.0.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff>=0.6.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: twine>=5.0.0; extra == 'dev'
|
|
31
|
+
Description-Content-Type: text/markdown
|
|
32
|
+
|
|
33
|
+
# http-mcp-client-server (Python)
|
|
34
|
+
|
|
35
|
+
[](https://pypi.org/project/http-mcp-client-server/)
|
|
36
|
+
[](https://www.python.org/downloads/)
|
|
37
|
+
[](https://opensource.org/licenses/MIT)
|
|
38
|
+
|
|
39
|
+
基于 MCP 协议的视频增强服务,作为 MCP Client-Server 与 FastAPI HTTP Server 交互。
|
|
40
|
+
|
|
41
|
+
## 功能
|
|
42
|
+
|
|
43
|
+
提供以下 MCP Tools:
|
|
44
|
+
- `create_task` - 创建视频增强任务(支持 URL 或本地文件上传)
|
|
45
|
+
- `get_task_status` - 查询任务状态
|
|
46
|
+
- `enhance_video_sync` - 同步增强视频(阻塞等待)
|
|
47
|
+
|
|
48
|
+
## 安装
|
|
49
|
+
|
|
50
|
+
### 从 PyPI 安装(推荐)
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 使用 pip 安装
|
|
54
|
+
pip install http-mcp-client-server
|
|
55
|
+
|
|
56
|
+
# 或使用 uv 安装
|
|
57
|
+
uv pip install http-mcp-client-server
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 从源码安装
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/yourusername/http-mcp-client-server.git
|
|
64
|
+
cd python_client
|
|
65
|
+
|
|
66
|
+
# 使用 uv 安装(推荐)
|
|
67
|
+
uv pip install -e ".[dev]"
|
|
68
|
+
|
|
69
|
+
# 或使用 pip 安装
|
|
70
|
+
pip install -e ".[dev]"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 使用方法
|
|
74
|
+
|
|
75
|
+
### 1. 命令行启动
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# 直接运行(安装后)
|
|
79
|
+
http-mcp-client-server --base-url http://localhost:8000 --api-key your-api-key
|
|
80
|
+
|
|
81
|
+
# 或使用环境变量
|
|
82
|
+
export HTTP_API_BASE_URL=http://localhost:8000
|
|
83
|
+
export HTTP_API_KEY=your-api-key
|
|
84
|
+
http-mcp-client-server
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 2. 在 Claude Desktop 中配置
|
|
88
|
+
|
|
89
|
+
编辑 Claude Desktop 配置文件:
|
|
90
|
+
|
|
91
|
+
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
92
|
+
|
|
93
|
+
**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"mcpServers": {
|
|
98
|
+
"video-enhancement": {
|
|
99
|
+
"command": "http-mcp-client-server",
|
|
100
|
+
"args": [
|
|
101
|
+
"--base-url",
|
|
102
|
+
"http://localhost:8000",
|
|
103
|
+
"--api-key",
|
|
104
|
+
"your-api-key"
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 3. 使用 uv run 运行(开发模式)
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
uv run http-mcp-client-server --base-url http://localhost:8000 --api-key your-api-key
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 提供的 Tools
|
|
118
|
+
|
|
119
|
+
### create_task
|
|
120
|
+
|
|
121
|
+
创建视频增强任务(异步)。
|
|
122
|
+
|
|
123
|
+
**参数:**
|
|
124
|
+
- `video_source` (string, required): 视频 URL 或本地文件路径
|
|
125
|
+
- `type` (string, optional): 上传类型,默认 "url"
|
|
126
|
+
- 可选值: `"url"` - 网络视频URL, `"local"` - 本地文件路径
|
|
127
|
+
- `resolution` (string, optional): 目标分辨率,默认 720p
|
|
128
|
+
- 可选值: 480p, 540p, 720p, 1080p, 2k
|
|
129
|
+
|
|
130
|
+
**使用示例:**
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
# URL 方式
|
|
134
|
+
{
|
|
135
|
+
"video_source": "https://example.com/video.mp4",
|
|
136
|
+
"type": "url",
|
|
137
|
+
"resolution": "1080p"
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
# 本地文件方式
|
|
141
|
+
{
|
|
142
|
+
"video_source": "/path/to/local/video.mp4",
|
|
143
|
+
"type": "local",
|
|
144
|
+
"resolution": "1080p"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**返回值:**
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"success": true,
|
|
152
|
+
"task_id": "xxx",
|
|
153
|
+
"status": "wait"
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### get_task_status
|
|
158
|
+
|
|
159
|
+
查询任务状态。
|
|
160
|
+
|
|
161
|
+
**参数:**
|
|
162
|
+
- `task_id` (string, required): 任务ID
|
|
163
|
+
|
|
164
|
+
**使用示例:**
|
|
165
|
+
```python
|
|
166
|
+
{
|
|
167
|
+
"task_id": "task-123-abc"
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
**返回值:**
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"success": true,
|
|
175
|
+
"task_id": "xxx",
|
|
176
|
+
"status": "completed",
|
|
177
|
+
"progress": 100,
|
|
178
|
+
"video_url": "https://...",
|
|
179
|
+
"error_message": null,
|
|
180
|
+
"created_at": "2024-01-01T00:00:00Z",
|
|
181
|
+
"updated_at": "2024-01-01T00:01:00Z"
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### enhance_video_sync
|
|
186
|
+
|
|
187
|
+
同步增强视频(阻塞等待完成)。
|
|
188
|
+
|
|
189
|
+
**参数:**
|
|
190
|
+
- `video_source` (string, required): 视频 URL 或本地文件路径
|
|
191
|
+
- `type` (string, optional): 上传类型,默认 "url"
|
|
192
|
+
- 可选值: `"url"` - 网络视频URL, `"local"` - 本地文件路径
|
|
193
|
+
- `resolution` (string, optional): 目标分辨率,默认 720p
|
|
194
|
+
- `poll_interval` (number, optional): 轮询间隔(秒),默认 5
|
|
195
|
+
- `timeout` (number, optional): 超时时间(秒),默认 600
|
|
196
|
+
|
|
197
|
+
**使用示例:**
|
|
198
|
+
```python
|
|
199
|
+
{
|
|
200
|
+
"video_source": "https://example.com/video.mp4",
|
|
201
|
+
"type": "url",
|
|
202
|
+
"resolution": "1080p",
|
|
203
|
+
"poll_interval": 5,
|
|
204
|
+
"timeout": 600
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**返回值:**
|
|
209
|
+
```json
|
|
210
|
+
{
|
|
211
|
+
"success": true,
|
|
212
|
+
"task_id": "xxx",
|
|
213
|
+
"status": "completed",
|
|
214
|
+
"progress": 100,
|
|
215
|
+
"video_url": "https://..."
|
|
216
|
+
}
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
## 文件上传说明
|
|
220
|
+
|
|
221
|
+
当 `type` 设置为 `"local"` 时,MCP Server 会:
|
|
222
|
+
1. 读取本地文件
|
|
223
|
+
2. 将文件转为 base64 编码
|
|
224
|
+
3. 上传到视频增强服务
|
|
225
|
+
|
|
226
|
+
**限制:**
|
|
227
|
+
- 最大文件大小:100MB
|
|
228
|
+
|
|
229
|
+
## 环境变量
|
|
230
|
+
|
|
231
|
+
| 变量名 | 说明 | 默认值 |
|
|
232
|
+
|--------|------|--------|
|
|
233
|
+
| `HTTP_API_BASE_URL` | FastAPI HTTP Server 地址 | `http://localhost:8000` |
|
|
234
|
+
| `HTTP_API_KEY` | API 认证密钥 | 无 |
|
|
235
|
+
|
|
236
|
+
## 开发
|
|
237
|
+
|
|
238
|
+
```bash
|
|
239
|
+
# 克隆仓库
|
|
240
|
+
git clone https://github.com/yourusername/http-mcp-client-server.git
|
|
241
|
+
cd python_client
|
|
242
|
+
|
|
243
|
+
# 安装开发依赖
|
|
244
|
+
uv pip install -e ".[dev]"
|
|
245
|
+
|
|
246
|
+
# 运行测试
|
|
247
|
+
pytest
|
|
248
|
+
|
|
249
|
+
# 代码格式化
|
|
250
|
+
ruff format .
|
|
251
|
+
ruff check --fix .
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
## 发布到 PyPI
|
|
255
|
+
|
|
256
|
+
```bash
|
|
257
|
+
# 安装构建工具
|
|
258
|
+
uv pip install build twine
|
|
259
|
+
|
|
260
|
+
# 构建分发包
|
|
261
|
+
python -m build
|
|
262
|
+
|
|
263
|
+
# 上传到 PyPI(测试)
|
|
264
|
+
python -m twine upload --repository testpypi dist/*
|
|
265
|
+
|
|
266
|
+
# 上传到 PyPI(正式)
|
|
267
|
+
python -m twine upload dist/*
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
## License
|
|
271
|
+
|
|
272
|
+
MIT License - 详见 [LICENSE](LICENSE) 文件
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
# 发布到 PyPI 指南
|
|
2
|
+
|
|
3
|
+
## 前置准备
|
|
4
|
+
|
|
5
|
+
1. **注册 PyPI 账号**
|
|
6
|
+
- 访问 https://pypi.org/account/register/
|
|
7
|
+
- 注册并验证邮箱
|
|
8
|
+
- 开启双因素认证 (2FA)
|
|
9
|
+
- 创建 API Token(在 Account Settings → API tokens)
|
|
10
|
+
|
|
11
|
+
2. **准备 API Token**
|
|
12
|
+
|
|
13
|
+
在 PyPI 账号设置中创建 API Token,发布时需要用到。
|
|
14
|
+
|
|
15
|
+
每次上传时会提示输入:
|
|
16
|
+
- Username: `__token__`
|
|
17
|
+
- Password: 你的 API Token (格式: `pypi-xxxxxxxxxxxx`)
|
|
18
|
+
|
|
19
|
+
## 发布步骤
|
|
20
|
+
|
|
21
|
+
### 1. 确保代码准备就绪
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
# 运行测试
|
|
25
|
+
pytest
|
|
26
|
+
|
|
27
|
+
# 代码格式化
|
|
28
|
+
ruff format .
|
|
29
|
+
ruff check --fix .
|
|
30
|
+
|
|
31
|
+
# 验证包可以正常构建
|
|
32
|
+
python -m build
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 2. 更新版本号
|
|
36
|
+
|
|
37
|
+
修改以下文件中的版本号:
|
|
38
|
+
- `pyproject.toml` - `version = "x.x.x"`
|
|
39
|
+
- `src/http_mcp_client/__init__.py` - `__version__ = "x.x.x"`
|
|
40
|
+
|
|
41
|
+
### 3. 构建分发包
|
|
42
|
+
|
|
43
|
+
**PowerShell:**
|
|
44
|
+
```powershell
|
|
45
|
+
# 清理旧的构建文件
|
|
46
|
+
Remove-Item -Recurse -Force dist/, build/ -ErrorAction SilentlyContinue
|
|
47
|
+
Remove-Item *.egg-info -Recurse -Force -ErrorAction SilentlyContinue
|
|
48
|
+
|
|
49
|
+
# 构建 wheel 和 sdist
|
|
50
|
+
python -m build
|
|
51
|
+
|
|
52
|
+
# 检查构建结果
|
|
53
|
+
Get-ChildItem dist/
|
|
54
|
+
# 应该包含:
|
|
55
|
+
# - http_mcp_client_server-X.X.X-py3-none-any.whl
|
|
56
|
+
# - http-mcp-client-server-X.X.X.tar.gz
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**CMD / macOS / Linux:**
|
|
60
|
+
```bash
|
|
61
|
+
# 清理旧的构建文件
|
|
62
|
+
rm -rf dist/ build/ *.egg-info
|
|
63
|
+
|
|
64
|
+
# 构建 wheel 和 sdist
|
|
65
|
+
python -m build
|
|
66
|
+
|
|
67
|
+
# 检查构建结果
|
|
68
|
+
ls -la dist/
|
|
69
|
+
# 应该包含:
|
|
70
|
+
# - http_mcp_client_server-X.X.X-py3-none-any.whl
|
|
71
|
+
# - http-mcp-client-server-X.X.X.tar.gz
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 4. 验证包
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# 使用 twine 检查
|
|
78
|
+
python -m twine check dist/*
|
|
79
|
+
|
|
80
|
+
# 测试安装
|
|
81
|
+
pip install dist/http_mcp_client_server-X.X.X-py3-none-any.whl
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 5. 上传到 TestPyPI(可选但推荐)
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
# 运行上传命令,会提示输入用户名和密码
|
|
88
|
+
python -m twine upload --repository testpypi dist/*
|
|
89
|
+
|
|
90
|
+
# 交互式输入:
|
|
91
|
+
# Username: __token__
|
|
92
|
+
# Password: pypi-xxxxx (你的 TestPyPI API Token)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
测试安装:
|
|
96
|
+
```bash
|
|
97
|
+
pip install --index-url https://test.pypi.org/simple/ http-mcp-client-server
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 6. 上传到正式 PyPI
|
|
101
|
+
|
|
102
|
+
#### 方式一:交互式输入(推荐,安全)
|
|
103
|
+
|
|
104
|
+
**PowerShell:**
|
|
105
|
+
```powershell
|
|
106
|
+
cd python_client
|
|
107
|
+
python -m twine upload dist/*
|
|
108
|
+
# 然后按提示输入:
|
|
109
|
+
# Username: __token__
|
|
110
|
+
# Password: pypi-AgEIcHlwaS5vcmcCJD...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**CMD:**
|
|
114
|
+
```cmd
|
|
115
|
+
cd python_client
|
|
116
|
+
python -m twine upload dist/*
|
|
117
|
+
REM 然后按提示输入用户名和密码
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
**macOS/Linux:**
|
|
121
|
+
```bash
|
|
122
|
+
cd python_client
|
|
123
|
+
python -m twine upload dist/*
|
|
124
|
+
# 然后按提示输入用户名和密码
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
#### 方式二:环境变量方式(不保存到文件)
|
|
128
|
+
|
|
129
|
+
**PowerShell:**
|
|
130
|
+
```powershell
|
|
131
|
+
# 设置环境变量(仅当前会话有效)
|
|
132
|
+
$env:TWINE_USERNAME = "__token__"
|
|
133
|
+
$env:TWINE_PASSWORD = "pypi-AgEIcHlwaS5vcmcCJD..."
|
|
134
|
+
|
|
135
|
+
# 执行上传(不需要输入用户名密码)
|
|
136
|
+
python -m twine upload dist/*
|
|
137
|
+
|
|
138
|
+
# 上传完成后清除环境变量(可选,关闭窗口自动清除)
|
|
139
|
+
Remove-Item Env:\TWINE_USERNAME
|
|
140
|
+
Remove-Item Env:\TWINE_PASSWORD
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**CMD:**
|
|
144
|
+
```cmd
|
|
145
|
+
set TWINE_USERNAME=__token__
|
|
146
|
+
set TWINE_PASSWORD=pypi-xxxxx
|
|
147
|
+
python -m twine upload dist/*
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
**macOS/Linux:**
|
|
151
|
+
```bash
|
|
152
|
+
export TWINE_USERNAME=__token__
|
|
153
|
+
export TWINE_PASSWORD=pypi-xxxxx
|
|
154
|
+
python -m twine upload dist/*
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 7. 验证发布
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# 等待几分钟让 PyPI 索引更新
|
|
161
|
+
pip install http-mcp-client-server
|
|
162
|
+
|
|
163
|
+
# 验证安装
|
|
164
|
+
http-mcp-client-server --help
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### 8. 创建 Git 标签(可选)
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
git tag v0.1.0
|
|
171
|
+
git push origin v0.1.0
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## 故障排除
|
|
175
|
+
|
|
176
|
+
### 上传失败:文件已存在
|
|
177
|
+
|
|
178
|
+
PyPI 不允许重复上传相同版本。需要:
|
|
179
|
+
1. 更新版本号
|
|
180
|
+
2. 重新构建
|
|
181
|
+
3. 重新上传
|
|
182
|
+
|
|
183
|
+
### 构建失败
|
|
184
|
+
|
|
185
|
+
确保安装了 build 工具:
|
|
186
|
+
```bash
|
|
187
|
+
uv pip install build
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### 验证失败
|
|
191
|
+
|
|
192
|
+
运行 `twine check` 查看具体错误:
|
|
193
|
+
```bash
|
|
194
|
+
python -m twine check dist/*
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
常见问题:
|
|
198
|
+
- README.md 格式错误
|
|
199
|
+
- 缺少必需的元数据
|
|
200
|
+
- 版本号格式不正确
|
|
201
|
+
|
|
202
|
+
## 自动化发布(GitHub Actions)
|
|
203
|
+
|
|
204
|
+
可以创建 `.github/workflows/publish.yml` 实现自动发布:
|
|
205
|
+
|
|
206
|
+
```yaml
|
|
207
|
+
name: Publish to PyPI
|
|
208
|
+
|
|
209
|
+
on:
|
|
210
|
+
release:
|
|
211
|
+
types: [created]
|
|
212
|
+
|
|
213
|
+
jobs:
|
|
214
|
+
deploy:
|
|
215
|
+
runs-on: ubuntu-latest
|
|
216
|
+
steps:
|
|
217
|
+
- uses: actions/checkout@v4
|
|
218
|
+
- name: Set up Python
|
|
219
|
+
uses: actions/setup-python@v5
|
|
220
|
+
with:
|
|
221
|
+
python-version: '3.12'
|
|
222
|
+
- name: Install dependencies
|
|
223
|
+
run: |
|
|
224
|
+
python -m pip install --upgrade pip
|
|
225
|
+
pip install build twine
|
|
226
|
+
- name: Build and publish
|
|
227
|
+
env:
|
|
228
|
+
TWINE_USERNAME: __token__
|
|
229
|
+
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
|
|
230
|
+
run: |
|
|
231
|
+
python -m build
|
|
232
|
+
twine upload dist/*
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
然后在 GitHub 仓库设置中添加 `PYPI_API_TOKEN` secret。
|