xiaoshiai-hub 0.1.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.
- xiaoshiai_hub/__init__.py +83 -0
- xiaoshiai_hub/client.py +360 -0
- xiaoshiai_hub/download.py +598 -0
- xiaoshiai_hub/encryption.py +777 -0
- xiaoshiai_hub/exceptions.py +37 -0
- xiaoshiai_hub/types.py +109 -0
- xiaoshiai_hub/upload.py +875 -0
- xiaoshiai_hub-0.1.1.dist-info/METADATA +560 -0
- xiaoshiai_hub-0.1.1.dist-info/RECORD +12 -0
- xiaoshiai_hub-0.1.1.dist-info/WHEEL +5 -0
- xiaoshiai_hub-0.1.1.dist-info/licenses/LICENSE +56 -0
- xiaoshiai_hub-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xiaoshiai-hub
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Python SDK for XiaoShi AI Hub - Upload, download, and manage AI models and datasets with encryption support
|
|
5
|
+
Home-page: https://github.com/poxiaoyun/moha-sdk
|
|
6
|
+
Author: XiaoShi AI
|
|
7
|
+
Author-email: XiaoShi AI <support@xiaoshiai.cn>
|
|
8
|
+
Maintainer: XiaoShi AI Team
|
|
9
|
+
Maintainer-email: XiaoShi AI Team <support@xiaoshiai.cn>
|
|
10
|
+
License: Apache-2.0
|
|
11
|
+
Project-URL: Homepage, https://github.com/poxiaoyun/moha-sdk
|
|
12
|
+
Project-URL: Repository, https://github.com/poxiaoyun/moha-sdk
|
|
13
|
+
Project-URL: Issues, https://github.com/poxiaoyun/moha-sdk/issues
|
|
14
|
+
Keywords: xiaoshi,ai-hub,machine-learning,deep-learning,model-hub,dataset,encryption,sdk,api-client
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Intended Audience :: Science/Research
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
21
|
+
Classifier: Operating System :: OS Independent
|
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
28
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
29
|
+
Requires-Python: >=3.7
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
License-File: LICENSE
|
|
32
|
+
Requires-Dist: requests>=2.20.0
|
|
33
|
+
Requires-Dist: tqdm>=4.62.0
|
|
34
|
+
Provides-Extra: upload
|
|
35
|
+
Requires-Dist: gitpython>=3.1.0; extra == "upload"
|
|
36
|
+
Requires-Dist: cryptography>=3.4.0; extra == "upload"
|
|
37
|
+
Provides-Extra: encryption
|
|
38
|
+
Requires-Dist: cryptography>=3.4.0; extra == "encryption"
|
|
39
|
+
Requires-Dist: gmssl>=3.2.1; extra == "encryption"
|
|
40
|
+
Provides-Extra: dev
|
|
41
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
|
42
|
+
Requires-Dist: pytest-cov>=2.0; extra == "dev"
|
|
43
|
+
Requires-Dist: pytest-mock>=3.6.0; extra == "dev"
|
|
44
|
+
Requires-Dist: black>=22.0; extra == "dev"
|
|
45
|
+
Requires-Dist: flake8>=4.0; extra == "dev"
|
|
46
|
+
Requires-Dist: mypy>=0.950; extra == "dev"
|
|
47
|
+
Requires-Dist: isort>=5.10.0; extra == "dev"
|
|
48
|
+
Requires-Dist: build>=0.8.0; extra == "dev"
|
|
49
|
+
Requires-Dist: twine>=4.0.0; extra == "dev"
|
|
50
|
+
Requires-Dist: gitpython>=3.1.0; extra == "dev"
|
|
51
|
+
Requires-Dist: cryptography>=3.4.0; extra == "dev"
|
|
52
|
+
Requires-Dist: gmssl>=3.2.1; extra == "dev"
|
|
53
|
+
Provides-Extra: all
|
|
54
|
+
Requires-Dist: gitpython>=3.1.0; extra == "all"
|
|
55
|
+
Requires-Dist: cryptography>=3.4.0; extra == "all"
|
|
56
|
+
Requires-Dist: gmssl>=3.2.1; extra == "all"
|
|
57
|
+
Dynamic: author
|
|
58
|
+
Dynamic: home-page
|
|
59
|
+
Dynamic: license-file
|
|
60
|
+
Dynamic: maintainer
|
|
61
|
+
Dynamic: requires-python
|
|
62
|
+
|
|
63
|
+
# XiaoShi AI Hub Python SDK
|
|
64
|
+
|
|
65
|
+
[](https://badge.fury.io/py/xiaoshiai-hub)
|
|
66
|
+
[](https://pypi.org/project/xiaoshiai-hub/)
|
|
67
|
+
[](https://opensource.org/licenses/Apache-2.0)
|
|
68
|
+
|
|
69
|
+
XiaoShi AI Hub Python SDK 是一个功能强大的 Python 库,用于与 XiaoShi AI Hub 平台进行交互。它提供了简单易用的 API,支持模型和数据集的上传、下载、加密等功能。
|
|
70
|
+
|
|
71
|
+
[English](README_EN.md) | 简体中文
|
|
72
|
+
|
|
73
|
+
## ✨ 特性
|
|
74
|
+
|
|
75
|
+
- 🚀 **简单易用** - 类似 Hugging Face Hub 的 API 设计,上手即用
|
|
76
|
+
- 📥 **下载功能** - 支持下载单个文件或整个仓库
|
|
77
|
+
- 📤 **上传功能** - 支持上传文件和文件夹到仓库
|
|
78
|
+
- 🔐 **加密支持** - 内置多种加密算法(AES、SM4、RSA、SM2)
|
|
79
|
+
- 🎯 **模式匹配** - 支持使用 allow/ignore 模式过滤文件
|
|
80
|
+
- 📊 **进度显示** - 下载和上传时显示进度条
|
|
81
|
+
- 🔑 **多种认证** - 支持用户名/密码和 Token 认证
|
|
82
|
+
- 🌐 **环境变量配置** - 灵活的 Hub URL 配置
|
|
83
|
+
- 💾 **缓存支持** - 高效的文件缓存机制
|
|
84
|
+
- 🔍 **类型提示** - 完整的类型注解,IDE 友好
|
|
85
|
+
|
|
86
|
+
## 📦 安装
|
|
87
|
+
|
|
88
|
+
### 基础安装(仅下载功能)
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
pip install xiaoshiai-hub
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### 完整安装(包含上传功能)
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
pip install xiaoshiai-hub[upload]
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### 开发安装
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install xiaoshiai-hub[dev]
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### 完整安装(所有功能)
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
pip install xiaoshiai-hub[all]
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 🚀 快速开始
|
|
113
|
+
|
|
114
|
+
### 下载单个文件
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
from xiaoshiai_hub import moha_hub_download
|
|
118
|
+
|
|
119
|
+
# 下载单个文件
|
|
120
|
+
file_path = moha_hub_download(
|
|
121
|
+
repo_id="demo/demo",
|
|
122
|
+
filename="config.yaml",
|
|
123
|
+
repo_type="models", # 或 "datasets"
|
|
124
|
+
username="your-username",
|
|
125
|
+
password="your-password",
|
|
126
|
+
)
|
|
127
|
+
print(f"文件已下载到: {file_path}")
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### 下载整个仓库
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
from xiaoshiai_hub import snapshot_download
|
|
134
|
+
|
|
135
|
+
# 下载整个仓库
|
|
136
|
+
repo_path = snapshot_download(
|
|
137
|
+
repo_id="demo/demo",
|
|
138
|
+
repo_type="models",
|
|
139
|
+
username="your-username",
|
|
140
|
+
password="your-password",
|
|
141
|
+
)
|
|
142
|
+
print(f"仓库已下载到: {repo_path}")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### 使用过滤器下载
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from xiaoshiai_hub import snapshot_download
|
|
149
|
+
|
|
150
|
+
# 只下载 YAML 和 Markdown 文件
|
|
151
|
+
repo_path = snapshot_download(
|
|
152
|
+
repo_id="demo/demo",
|
|
153
|
+
allow_patterns=["*.yaml", "*.yml", "*.md"],
|
|
154
|
+
ignore_patterns=[".git*", "*.log"],
|
|
155
|
+
username="your-username",
|
|
156
|
+
password="your-password",
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 上传文件
|
|
161
|
+
|
|
162
|
+
```python
|
|
163
|
+
from xiaoshiai_hub import upload_file
|
|
164
|
+
|
|
165
|
+
# 上传单个文件
|
|
166
|
+
commit_hash = upload_file(
|
|
167
|
+
path_or_fileobj="./config.yaml",
|
|
168
|
+
path_in_repo="config.yaml",
|
|
169
|
+
repo_id="demo/my-model",
|
|
170
|
+
repo_type="models",
|
|
171
|
+
commit_message="Upload config file",
|
|
172
|
+
username="your-username",
|
|
173
|
+
password="your-password",
|
|
174
|
+
)
|
|
175
|
+
print(f"提交哈希: {commit_hash}")
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 上传文件夹
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from xiaoshiai_hub import upload_folder
|
|
182
|
+
|
|
183
|
+
# 上传整个文件夹
|
|
184
|
+
commit_hash = upload_folder(
|
|
185
|
+
folder_path="./my_model",
|
|
186
|
+
repo_id="demo/my-model",
|
|
187
|
+
repo_type="models",
|
|
188
|
+
commit_message="Upload model files",
|
|
189
|
+
ignore_patterns=["*.log", ".git*"], # 忽略这些文件
|
|
190
|
+
username="your-username",
|
|
191
|
+
password="your-password",
|
|
192
|
+
)
|
|
193
|
+
print(f"提交哈希: {commit_hash}")
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
### 加密上传和下载
|
|
197
|
+
|
|
198
|
+
```python
|
|
199
|
+
from xiaoshiai_hub import upload_file, moha_hub_download
|
|
200
|
+
from xiaoshiai_hub.encryption import EncryptionAlgorithm
|
|
201
|
+
|
|
202
|
+
# 上传加密文件
|
|
203
|
+
commit_hash = upload_file(
|
|
204
|
+
path_or_fileobj="./secret.txt",
|
|
205
|
+
path_in_repo="secret.txt",
|
|
206
|
+
repo_id="demo/encrypted-repo",
|
|
207
|
+
encryption_key="your-32-character-secret-key",
|
|
208
|
+
encryption_algorithm=EncryptionAlgorithm.AES_256_CBC,
|
|
209
|
+
username="your-username",
|
|
210
|
+
password="your-password",
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
# 下载并解密文件
|
|
214
|
+
file_path = moha_hub_download(
|
|
215
|
+
repo_id="demo/encrypted-repo",
|
|
216
|
+
filename="secret.txt",
|
|
217
|
+
decryption_key="your-32-character-secret-key",
|
|
218
|
+
decryption_algorithm=EncryptionAlgorithm.AES_256_CBC,
|
|
219
|
+
username="your-username",
|
|
220
|
+
password="your-password",
|
|
221
|
+
)
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### 使用 HubClient API
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from xiaoshiai_hub import HubClient
|
|
228
|
+
|
|
229
|
+
# 创建客户端
|
|
230
|
+
client = HubClient(
|
|
231
|
+
username="your-username",
|
|
232
|
+
password="your-password",
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
# 获取仓库信息
|
|
236
|
+
repo_info = client.get_repository_info("demo", "models", "my-model")
|
|
237
|
+
print(f"仓库名称: {repo_info.name}")
|
|
238
|
+
print(f"组织: {repo_info.organization}")
|
|
239
|
+
|
|
240
|
+
# 列出分支
|
|
241
|
+
branches = client.list_branches("demo", "models", "my-model")
|
|
242
|
+
for branch in branches:
|
|
243
|
+
print(f"分支: {branch.name} (commit: {branch.commit_sha})")
|
|
244
|
+
|
|
245
|
+
# 浏览仓库内容
|
|
246
|
+
content = client.get_repository_content("demo", "models", "my-model", "main")
|
|
247
|
+
for entry in content.entries:
|
|
248
|
+
print(f"{entry.type}: {entry.name}")
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## 🔐 加密功能
|
|
252
|
+
|
|
253
|
+
SDK 支持多种加密算法:
|
|
254
|
+
|
|
255
|
+
### 对称加密
|
|
256
|
+
|
|
257
|
+
- **AES-256-CBC** - 标准 AES 加密
|
|
258
|
+
- **AES-256-GCM** - AES 加密(带认证)
|
|
259
|
+
- **SM4-CBC** - 国密 SM4 加密
|
|
260
|
+
- **SM4-GCM** - 国密 SM4 加密(带认证)
|
|
261
|
+
|
|
262
|
+
### 非对称加密
|
|
263
|
+
|
|
264
|
+
- **RSA-OAEP** - RSA 加密(推荐)
|
|
265
|
+
- **RSA-PKCS1V15** - RSA 加密(兼容性)
|
|
266
|
+
- **SM2** - 国密 SM2 加密
|
|
267
|
+
|
|
268
|
+
### 生成加密密钥
|
|
269
|
+
|
|
270
|
+
```python
|
|
271
|
+
import secrets
|
|
272
|
+
import string
|
|
273
|
+
|
|
274
|
+
# 生成对称加密密钥(32 字符)
|
|
275
|
+
symmetric_key = ''.join(secrets.choice(string.ascii_letters + string.digits) for _ in range(32))
|
|
276
|
+
print(f"对称密钥: {symmetric_key}")
|
|
277
|
+
|
|
278
|
+
# 生成 RSA 密钥对
|
|
279
|
+
from cryptography.hazmat.primitives.asymmetric import rsa
|
|
280
|
+
from cryptography.hazmat.primitives import serialization
|
|
281
|
+
|
|
282
|
+
private_key = rsa.generate_private_key(
|
|
283
|
+
public_exponent=65537,
|
|
284
|
+
key_size=2048,
|
|
285
|
+
)
|
|
286
|
+
public_key = private_key.public_key()
|
|
287
|
+
|
|
288
|
+
# 序列化公钥
|
|
289
|
+
public_pem = public_key.public_bytes(
|
|
290
|
+
encoding=serialization.Encoding.PEM,
|
|
291
|
+
format=serialization.PublicFormat.SubjectPublicKeyInfo
|
|
292
|
+
).decode()
|
|
293
|
+
|
|
294
|
+
# 序列化私钥
|
|
295
|
+
private_pem = private_key.private_bytes(
|
|
296
|
+
encoding=serialization.Encoding.PEM,
|
|
297
|
+
format=serialization.PrivateFormat.PKCS8,
|
|
298
|
+
encryption_algorithm=serialization.NoEncryption()
|
|
299
|
+
).decode()
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 部分文件加密
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
from xiaoshiai_hub import upload_folder
|
|
306
|
+
from xiaoshiai_hub.encryption import EncryptionAlgorithm
|
|
307
|
+
|
|
308
|
+
# 上传文件夹,只加密部分文件
|
|
309
|
+
commit_hash = upload_folder(
|
|
310
|
+
folder_path="./my_model",
|
|
311
|
+
repo_id="demo/my-model",
|
|
312
|
+
encryption_key="your-secret-key",
|
|
313
|
+
encryption_algorithm=EncryptionAlgorithm.AES_256_CBC,
|
|
314
|
+
encryption_exclude=["README.md", "*.yaml"], # 这些文件不加密
|
|
315
|
+
username="your-username",
|
|
316
|
+
password="your-password",
|
|
317
|
+
)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## ⚙️ 配置
|
|
321
|
+
|
|
322
|
+
### 环境变量
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# Hub 服务端点
|
|
326
|
+
export MOHA_ENDPOINT="https://your-hub-url.com/moha"
|
|
327
|
+
|
|
328
|
+
# 认证信息
|
|
329
|
+
export MOHA_USERNAME="your-username"
|
|
330
|
+
export MOHA_PASSWORD="your-password"
|
|
331
|
+
|
|
332
|
+
# 加密密钥(可选)
|
|
333
|
+
export ENCRYPTION_KEY="your-32-character-encryption-key"
|
|
334
|
+
export DECRYPTION_KEY="your-32-character-decryption-key"
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### 使用 .env 文件
|
|
338
|
+
|
|
339
|
+
创建 `.env` 文件:
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
MOHA_ENDPOINT=https://your-hub-url.com/moha
|
|
343
|
+
MOHA_USERNAME=your-username
|
|
344
|
+
MOHA_PASSWORD=your-password
|
|
345
|
+
ENCRYPTION_KEY=your-encryption-key
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
然后在代码中加载:
|
|
349
|
+
|
|
350
|
+
```python
|
|
351
|
+
from dotenv import load_dotenv
|
|
352
|
+
load_dotenv()
|
|
353
|
+
|
|
354
|
+
from xiaoshiai_hub import moha_hub_download
|
|
355
|
+
|
|
356
|
+
# 自动使用环境变量中的认证信息
|
|
357
|
+
file_path = moha_hub_download(
|
|
358
|
+
repo_id="demo/demo",
|
|
359
|
+
filename="config.yaml",
|
|
360
|
+
)
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## 📚 示例代码
|
|
364
|
+
|
|
365
|
+
项目包含丰富的示例代码,位于 `examples/` 目录:
|
|
366
|
+
|
|
367
|
+
- **01_basic_usage.py** - 基础使用示例
|
|
368
|
+
- **02_download_file.py** - 下载文件示例
|
|
369
|
+
- **03_download_repository.py** - 下载仓库示例
|
|
370
|
+
- **04_upload_file.py** - 上传文件示例
|
|
371
|
+
- **05_upload_folder.py** - 上传文件夹示例
|
|
372
|
+
- **06_encryption.py** - 加密功能示例
|
|
373
|
+
- **07_complete_workflow.py** - 完整工作流示例
|
|
374
|
+
|
|
375
|
+
运行示例:
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
# 设置环境变量
|
|
379
|
+
export MOHA_USERNAME="your-username"
|
|
380
|
+
export MOHA_PASSWORD="your-password"
|
|
381
|
+
|
|
382
|
+
# 运行示例
|
|
383
|
+
python examples/01_basic_usage.py
|
|
384
|
+
python examples/07_complete_workflow.py
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
详细说明请查看 [examples/README.md](examples/README.md)
|
|
388
|
+
|
|
389
|
+
## 🧪 测试
|
|
390
|
+
|
|
391
|
+
运行测试:
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# 安装开发依赖
|
|
395
|
+
pip install xiaoshiai-hub[dev]
|
|
396
|
+
|
|
397
|
+
# 运行所有测试
|
|
398
|
+
pytest
|
|
399
|
+
|
|
400
|
+
# 运行特定测试文件
|
|
401
|
+
pytest tests/test_client.py
|
|
402
|
+
|
|
403
|
+
# 运行测试并显示覆盖率
|
|
404
|
+
pytest --cov=xiaoshiai_hub --cov-report=html
|
|
405
|
+
|
|
406
|
+
# 运行测试(详细输出)
|
|
407
|
+
pytest -v
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
## 📖 API 文档
|
|
411
|
+
|
|
412
|
+
### 核心函数
|
|
413
|
+
|
|
414
|
+
#### `moha_hub_download()`
|
|
415
|
+
|
|
416
|
+
下载单个文件。
|
|
417
|
+
|
|
418
|
+
**参数:**
|
|
419
|
+
- `repo_id` (str): 仓库 ID,格式为 "organization/repo_name"
|
|
420
|
+
- `filename` (str): 要下载的文件名
|
|
421
|
+
- `repo_type` (str): 仓库类型,"models" 或 "datasets",默认 "models"
|
|
422
|
+
- `revision` (str, optional): 分支、标签或提交哈希,默认 "main"
|
|
423
|
+
- `local_dir` (str, optional): 本地保存目录
|
|
424
|
+
- `username` (str, optional): 用户名
|
|
425
|
+
- `password` (str, optional): 密码
|
|
426
|
+
- `token` (str, optional): 认证 Token
|
|
427
|
+
- `decryption_key` (str, optional): 解密密钥
|
|
428
|
+
- `decryption_algorithm` (str, optional): 解密算法
|
|
429
|
+
|
|
430
|
+
**返回:** 下载文件的本地路径
|
|
431
|
+
|
|
432
|
+
#### `snapshot_download()`
|
|
433
|
+
|
|
434
|
+
下载整个仓库。
|
|
435
|
+
|
|
436
|
+
**参数:**
|
|
437
|
+
- `repo_id` (str): 仓库 ID
|
|
438
|
+
- `repo_type` (str): 仓库类型,默认 "models"
|
|
439
|
+
- `revision` (str, optional): 分支、标签或提交哈希,默认 "main"
|
|
440
|
+
- `local_dir` (str, optional): 本地保存目录
|
|
441
|
+
- `allow_patterns` (List[str], optional): 允许下载的文件模式
|
|
442
|
+
- `ignore_patterns` (List[str], optional): 忽略的文件模式
|
|
443
|
+
- `username` (str, optional): 用户名
|
|
444
|
+
- `password` (str, optional): 密码
|
|
445
|
+
- `token` (str, optional): 认证 Token
|
|
446
|
+
- `decryption_key` (str, optional): 解密密钥
|
|
447
|
+
- `decryption_algorithm` (str, optional): 解密算法
|
|
448
|
+
|
|
449
|
+
**返回:** 下载仓库的本地路径
|
|
450
|
+
|
|
451
|
+
#### `upload_file()`
|
|
452
|
+
|
|
453
|
+
上传单个文件。
|
|
454
|
+
|
|
455
|
+
**参数:**
|
|
456
|
+
- `path_or_fileobj` (str | Path | bytes): 文件路径或文件对象
|
|
457
|
+
- `path_in_repo` (str): 仓库中的文件路径
|
|
458
|
+
- `repo_id` (str): 仓库 ID
|
|
459
|
+
- `repo_type` (str): 仓库类型,默认 "models"
|
|
460
|
+
- `revision` (str): 分支名称,默认 "main"
|
|
461
|
+
- `commit_message` (str, optional): 提交信息
|
|
462
|
+
- `commit_description` (str, optional): 提交描述
|
|
463
|
+
- `username` (str, optional): 用户名
|
|
464
|
+
- `password` (str, optional): 密码
|
|
465
|
+
- `token` (str, optional): 认证 Token
|
|
466
|
+
- `encryption_key` (str, optional): 加密密钥
|
|
467
|
+
- `encryption_algorithm` (str, optional): 加密算法
|
|
468
|
+
|
|
469
|
+
**返回:** 提交哈希
|
|
470
|
+
|
|
471
|
+
#### `upload_folder()`
|
|
472
|
+
|
|
473
|
+
上传整个文件夹。
|
|
474
|
+
|
|
475
|
+
**参数:**
|
|
476
|
+
- `folder_path` (str | Path): 文件夹路径
|
|
477
|
+
- `repo_id` (str): 仓库 ID
|
|
478
|
+
- `repo_type` (str): 仓库类型,默认 "models"
|
|
479
|
+
- `revision` (str): 分支名称,默认 "main"
|
|
480
|
+
- `commit_message` (str, optional): 提交信息
|
|
481
|
+
- `commit_description` (str, optional): 提交描述
|
|
482
|
+
- `ignore_patterns` (List[str], optional): 忽略的文件模式
|
|
483
|
+
- `username` (str, optional): 用户名
|
|
484
|
+
- `password` (str, optional): 密码
|
|
485
|
+
- `token` (str, optional): 认证 Token
|
|
486
|
+
- `encryption_key` (str, optional): 加密密钥
|
|
487
|
+
- `encryption_algorithm` (str, optional): 加密算法
|
|
488
|
+
- `encryption_exclude` (List[str], optional): 不加密的文件模式
|
|
489
|
+
|
|
490
|
+
**返回:** 提交哈希
|
|
491
|
+
|
|
492
|
+
### HubClient 类
|
|
493
|
+
|
|
494
|
+
#### 初始化
|
|
495
|
+
|
|
496
|
+
```python
|
|
497
|
+
client = HubClient(
|
|
498
|
+
base_url="https://hub.example.com/moha",
|
|
499
|
+
username="your-username",
|
|
500
|
+
password="your-password",
|
|
501
|
+
)
|
|
502
|
+
```
|
|
503
|
+
|
|
504
|
+
#### 方法
|
|
505
|
+
|
|
506
|
+
- `get_repository_info(org, repo_type, repo_name)` - 获取仓库信息
|
|
507
|
+
- `list_branches(org, repo_type, repo_name)` - 列出分支
|
|
508
|
+
- `list_tags(org, repo_type, repo_name)` - 列出标签
|
|
509
|
+
- `get_repository_content(org, repo_type, repo_name, branch, path)` - 获取仓库内容
|
|
510
|
+
- `download_file(org, repo_type, repo_name, branch, file_path, local_path)` - 下载文件
|
|
511
|
+
- `get_moha_encryption(org, repo_type, repo_name, branch)` - 获取加密元数据
|
|
512
|
+
|
|
513
|
+
## 🔧 开发
|
|
514
|
+
|
|
515
|
+
### 设置开发环境
|
|
516
|
+
|
|
517
|
+
```bash
|
|
518
|
+
# 克隆仓库
|
|
519
|
+
git clone https://github.com/poxiaoyun/XiaoShi-Moha.git
|
|
520
|
+
cd XiaoShi-Moha/python-sdk
|
|
521
|
+
|
|
522
|
+
# 创建虚拟环境
|
|
523
|
+
python -m venv venv
|
|
524
|
+
source venv/bin/activate # Linux/macOS
|
|
525
|
+
# 或
|
|
526
|
+
venv\Scripts\activate # Windows
|
|
527
|
+
|
|
528
|
+
# 安装开发依赖
|
|
529
|
+
pip install -e .[dev]
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
### 代码格式化
|
|
533
|
+
|
|
534
|
+
```bash
|
|
535
|
+
# 使用 black 格式化代码
|
|
536
|
+
black xiaoshiai_hub tests examples
|
|
537
|
+
|
|
538
|
+
# 使用 flake8 检查代码
|
|
539
|
+
flake8 xiaoshiai_hub tests
|
|
540
|
+
|
|
541
|
+
# 使用 mypy 检查类型
|
|
542
|
+
mypy xiaoshiai_hub
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
### 构建和发布
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
# 构建包
|
|
549
|
+
python -m build
|
|
550
|
+
|
|
551
|
+
# 检查包
|
|
552
|
+
twine check dist/*
|
|
553
|
+
|
|
554
|
+
# 上传到 TestPyPI
|
|
555
|
+
twine upload --repository testpypi dist/*
|
|
556
|
+
|
|
557
|
+
# 上传到 PyPI
|
|
558
|
+
twine upload dist/*
|
|
559
|
+
```
|
|
560
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
xiaoshiai_hub/__init__.py,sha256=YGJ6E_7kpDcXQvDwhCtbn_ZjW3dYQCE5x56qgiUGycM,1578
|
|
2
|
+
xiaoshiai_hub/client.py,sha256=HWm0slH182ooQ-O9Q6tv51IBnJZOmd4ixxSqqgReOLI,11695
|
|
3
|
+
xiaoshiai_hub/download.py,sha256=9w17b62Pl-AJsZiIyWFsVTZD2h7Laz68yIjmTk_J3II,21342
|
|
4
|
+
xiaoshiai_hub/encryption.py,sha256=1DDOwjrZ0SBJaEPkzF8UnW4Xy1-GlBXxFYRwKdZ1UwY,24829
|
|
5
|
+
xiaoshiai_hub/exceptions.py,sha256=OVxCzbRICqQKOF10yt1COTXnjxkGH51g72a21eJU6Vc,795
|
|
6
|
+
xiaoshiai_hub/types.py,sha256=PGhdIc0ztl_vAKDaPkkZeFZjIXnPL81Tn65rAjedXoM,2262
|
|
7
|
+
xiaoshiai_hub/upload.py,sha256=Owl0-KTy0rY1eDnnht0a5HxKydv0rKexZOySSU32T0A,32332
|
|
8
|
+
xiaoshiai_hub-0.1.1.dist-info/licenses/LICENSE,sha256=tS28u6VpvqNisRWGeufp-XYQc6p194vOGARl3OIjidA,9110
|
|
9
|
+
xiaoshiai_hub-0.1.1.dist-info/METADATA,sha256=KdCrmv_5PaomYJhDs_jDCgF6WhWmuB3mJHa2yuME9Yo,15222
|
|
10
|
+
xiaoshiai_hub-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
+
xiaoshiai_hub-0.1.1.dist-info/top_level.txt,sha256=9AQDFb5Xn7RLQPdbk1aA0QpntbKhlhlT6Z_g-zUBtlM,14
|
|
12
|
+
xiaoshiai_hub-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
10
|
+
|
|
11
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
12
|
+
|
|
13
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
14
|
+
|
|
15
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
16
|
+
|
|
17
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
18
|
+
|
|
19
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
20
|
+
|
|
21
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work.
|
|
22
|
+
|
|
23
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
24
|
+
|
|
25
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
26
|
+
|
|
27
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
28
|
+
|
|
29
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
30
|
+
|
|
31
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
32
|
+
|
|
33
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
34
|
+
|
|
35
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
36
|
+
|
|
37
|
+
(b) You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
38
|
+
|
|
39
|
+
(c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
40
|
+
|
|
41
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
|
|
42
|
+
|
|
43
|
+
You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
|
56
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
xiaoshiai_hub
|