xiaoshiai-hub 0.1.0__tar.gz → 0.1.2__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.
Files changed (51) hide show
  1. xiaoshiai_hub-0.1.2/MANIFEST.in +31 -0
  2. xiaoshiai_hub-0.1.2/PKG-INFO +560 -0
  3. xiaoshiai_hub-0.1.2/README.md +498 -0
  4. xiaoshiai_hub-0.1.2/README_EN.md +348 -0
  5. xiaoshiai_hub-0.1.2/examples/01_basic_usage.py +168 -0
  6. xiaoshiai_hub-0.1.2/examples/02_download_file.py +196 -0
  7. xiaoshiai_hub-0.1.2/examples/03_download_repository.py +260 -0
  8. xiaoshiai_hub-0.1.2/examples/04_upload_file.py +288 -0
  9. xiaoshiai_hub-0.1.2/examples/05_upload_folder.py +328 -0
  10. xiaoshiai_hub-0.1.2/examples/06_encryption.py +317 -0
  11. xiaoshiai_hub-0.1.2/examples/07_complete_workflow.py +376 -0
  12. xiaoshiai_hub-0.1.2/examples/README.md +344 -0
  13. xiaoshiai_hub-0.1.2/pyproject.toml +144 -0
  14. xiaoshiai_hub-0.1.2/requirements-dev.txt +28 -0
  15. xiaoshiai_hub-0.1.2/requirements-test.txt +12 -0
  16. xiaoshiai_hub-0.1.2/requirements.txt +2 -0
  17. xiaoshiai_hub-0.1.2/setup.py +194 -0
  18. xiaoshiai_hub-0.1.2/xiaoshiai_hub/__init__.py +83 -0
  19. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub/client.py +119 -18
  20. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub/download.py +190 -56
  21. xiaoshiai_hub-0.1.2/xiaoshiai_hub/encryption.py +777 -0
  22. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub/exceptions.py +6 -1
  23. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub/types.py +21 -4
  24. xiaoshiai_hub-0.1.2/xiaoshiai_hub/upload.py +831 -0
  25. xiaoshiai_hub-0.1.2/xiaoshiai_hub.egg-info/PKG-INFO +560 -0
  26. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub.egg-info/SOURCES.txt +12 -8
  27. xiaoshiai_hub-0.1.2/xiaoshiai_hub.egg-info/not-zip-safe +1 -0
  28. xiaoshiai_hub-0.1.2/xiaoshiai_hub.egg-info/requires.txt +29 -0
  29. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub.egg-info/top_level.txt +0 -1
  30. xiaoshiai_hub-0.1.0/MANIFEST.in +0 -8
  31. xiaoshiai_hub-0.1.0/PKG-INFO +0 -321
  32. xiaoshiai_hub-0.1.0/README.md +0 -281
  33. xiaoshiai_hub-0.1.0/examples/README.md +0 -72
  34. xiaoshiai_hub-0.1.0/examples/download_repository.py +0 -25
  35. xiaoshiai_hub-0.1.0/examples/download_single_file.py +0 -26
  36. xiaoshiai_hub-0.1.0/examples/download_with_filters.py +0 -31
  37. xiaoshiai_hub-0.1.0/examples/download_with_progress.py +0 -67
  38. xiaoshiai_hub-0.1.0/examples/list_repository_content.py +0 -90
  39. xiaoshiai_hub-0.1.0/examples/using_environment_variables.py +0 -128
  40. xiaoshiai_hub-0.1.0/pyproject.toml +0 -64
  41. xiaoshiai_hub-0.1.0/requirements-dev.txt +0 -7
  42. xiaoshiai_hub-0.1.0/requirements.txt +0 -3
  43. xiaoshiai_hub-0.1.0/setup.py +0 -47
  44. xiaoshiai_hub-0.1.0/tests/__init__.py +0 -4
  45. xiaoshiai_hub-0.1.0/tests/test_download.py +0 -142
  46. xiaoshiai_hub-0.1.0/xiaoshiai_hub/__init__.py +0 -41
  47. xiaoshiai_hub-0.1.0/xiaoshiai_hub.egg-info/PKG-INFO +0 -321
  48. xiaoshiai_hub-0.1.0/xiaoshiai_hub.egg-info/requires.txt +0 -11
  49. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/LICENSE +0 -0
  50. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/setup.cfg +0 -0
  51. {xiaoshiai_hub-0.1.0 → xiaoshiai_hub-0.1.2}/xiaoshiai_hub.egg-info/dependency_links.txt +0 -0
@@ -0,0 +1,31 @@
1
+ # Include documentation files
2
+ include README.md
3
+ include README_EN.md
4
+ include LICENSE
5
+
6
+ # Include requirements files
7
+ include requirements.txt
8
+ include requirements-dev.txt
9
+ include requirements-test.txt
10
+
11
+ # Include configuration files
12
+ include pyproject.toml
13
+ include setup.py
14
+
15
+ # Include package files
16
+ recursive-include xiaoshiai_hub *.py
17
+
18
+ # Include examples (optional, for reference)
19
+ recursive-include examples *.py *.md
20
+
21
+ # Exclude test files from distribution
22
+ recursive-exclude tests *
23
+
24
+ # Exclude development files
25
+ exclude .gitignore
26
+
27
+ # Exclude build artifacts
28
+ global-exclude __pycache__
29
+ global-exclude *.py[cod]
30
+ global-exclude *.so
31
+ global-exclude .DS_Store
@@ -0,0 +1,560 @@
1
+ Metadata-Version: 2.4
2
+ Name: xiaoshiai-hub
3
+ Version: 0.1.2
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
+ [![PyPI version](https://badge.fury.io/py/xiaoshiai-hub.svg)](https://badge.fury.io/py/xiaoshiai-hub)
66
+ [![Python Support](https://img.shields.io/pypi/pyversions/xiaoshiai-hub.svg)](https://pypi.org/project/xiaoshiai-hub/)
67
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](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
+