xiaoshiai-hub 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.
@@ -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,8 @@
1
+ include README.md
2
+ include LICENSE
3
+ include requirements.txt
4
+ include requirements-dev.txt
5
+ recursive-include xiaoshiai_hub *.py
6
+ recursive-include examples *.py *.md
7
+ recursive-include tests *.py
8
+
@@ -0,0 +1,321 @@
1
+ Metadata-Version: 2.4
2
+ Name: xiaoshiai-hub
3
+ Version: 0.1.0
4
+ Summary: Python SDK for XiaoShi AI Hub
5
+ Home-page: https://github.com/poxiaoyun/XiaoShi-Moha
6
+ Author: XiaoShi AI
7
+ Author-email: XiaoShi AI <support@xiaoshiai.cn>
8
+ License: Apache-2.0
9
+ Project-URL: Homepage, https://github.com/poxiaoyun/XiaoShi-Moha
10
+ Project-URL: Documentation, https://github.com/poxiaoyun/XiaoShi-Moha/tree/main/python-sdk
11
+ Project-URL: Repository, https://github.com/poxiaoyun/XiaoShi-Moha
12
+ Project-URL: Issues, https://github.com/poxiaoyun/XiaoShi-Moha/issues
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Requires-Python: >=3.7
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: requests>=2.20.0
27
+ Requires-Dist: tqdm>=4.62.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=6.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
31
+ Requires-Dist: black>=22.0; extra == "dev"
32
+ Requires-Dist: flake8>=4.0; extra == "dev"
33
+ Requires-Dist: mypy>=0.950; extra == "dev"
34
+ Requires-Dist: build>=0.8.0; extra == "dev"
35
+ Requires-Dist: twine>=4.0.0; extra == "dev"
36
+ Dynamic: author
37
+ Dynamic: home-page
38
+ Dynamic: license-file
39
+ Dynamic: requires-python
40
+
41
+ # XiaoShi AI Hub Python SDK
42
+
43
+ Python SDK for interacting with XiaoShi AI Hub repositories. This library provides a simple and intuitive interface for downloading models and datasets from XiaoShi AI Hub, similar to the Hugging Face Hub API.
44
+
45
+ ## Installation
46
+
47
+ ```bash
48
+ pip install xiaoshiai-hub
49
+ ```
50
+
51
+ Or install from source:
52
+
53
+ ```bash
54
+ cd python-sdk
55
+ pip install -e .
56
+ ```
57
+
58
+ ## Features
59
+
60
+ - ✅ **Download single files or entire repositories**
61
+ - ✅ **Progress bars** (like Hugging Face Hub) for download tracking
62
+ - ✅ **Pattern-based filtering** with allow/ignore patterns
63
+ - ✅ **Multiple authentication methods** (username/password, token)
64
+ - ✅ **Environment variable configuration** for flexible Hub URL setup
65
+ - ✅ **Caching support** for efficient reuse
66
+ - ✅ **Type hints** for better IDE support
67
+
68
+ ## Quick Start
69
+
70
+ ### Download a Single File
71
+
72
+ ```python
73
+ from xiaoshiai_hub import hf_hub_download
74
+
75
+ # Download a single file
76
+ file_path = hf_hub_download(
77
+ repo_id="demo/demo",
78
+ filename="config.yaml",
79
+ repo_type="models", # or "datasets"
80
+ username="your-username",
81
+ password="your-password",
82
+ )
83
+
84
+ print(f"File downloaded to: {file_path}")
85
+ ```
86
+
87
+ ### Download Entire Repository
88
+
89
+ ```python
90
+ from xiaoshiai_hub import snapshot_download
91
+
92
+ # Download entire repository
93
+ repo_path = snapshot_download(
94
+ repo_id="demo/demo",
95
+ repo_type="models",
96
+ username="your-username",
97
+ password="your-password",
98
+ )
99
+
100
+ print(f"Repository downloaded to: {repo_path}")
101
+ ```
102
+
103
+ ### Download with Filters
104
+
105
+ ```python
106
+ from xiaoshiai_hub import snapshot_download
107
+
108
+ # Download only YAML files, ignoring .git files
109
+ repo_path = snapshot_download(
110
+ repo_id="demo/demo",
111
+ repo_type="models",
112
+ allow_patterns=["*.yaml", "*.yml"],
113
+ ignore_patterns=[".git*"],
114
+ username="your-username",
115
+ password="your-password",
116
+ )
117
+ ```
118
+
119
+ ## Advanced Usage
120
+
121
+ ### Using the Client Directly
122
+
123
+ ```python
124
+ from xiaoshiai_hub import HubClient
125
+
126
+ # Create a client
127
+ client = HubClient(
128
+ base_url="https://rune.develop.xiaoshiai.cn/api/moha",
129
+ username="your-username",
130
+ password="your-password",
131
+ )
132
+
133
+ # Get repository information
134
+ repo_info = client.get_repository_info(
135
+ organization="demo",
136
+ repo_type="models",
137
+ repo_name="demo",
138
+ )
139
+ print(f"Repository: {repo_info.name}")
140
+ print(f"Default branch: {repo_info.default_branch}")
141
+
142
+ # List branches and tags
143
+ refs = client.get_repository_refs(
144
+ organization="demo",
145
+ repo_type="models",
146
+ repo_name="demo",
147
+ )
148
+ for ref in refs:
149
+ print(f"{ref.type}: {ref.name} ({ref.hash})")
150
+
151
+ # Get repository content
152
+ content = client.get_repository_content(
153
+ organization="demo",
154
+ repo_type="models",
155
+ repo_name="demo",
156
+ branch="main",
157
+ path="", # root directory
158
+ )
159
+
160
+ # List files
161
+ if content.entries:
162
+ for entry in content.entries:
163
+ print(f"{entry.type}: {entry.path} ({entry.size} bytes)")
164
+
165
+ # Download a specific file
166
+ client.download_file(
167
+ organization="demo",
168
+ repo_type="models",
169
+ repo_name="demo",
170
+ branch="main",
171
+ file_path="config.yaml",
172
+ local_path="./config.yaml",
173
+ )
174
+ ```
175
+
176
+ ### Authentication
177
+
178
+ The SDK supports multiple authentication methods:
179
+
180
+ #### Username and Password
181
+
182
+ ```python
183
+ from xiaoshiai_hub import HubClient
184
+
185
+ client = HubClient(
186
+ username="your-username",
187
+ password="your-password",
188
+ )
189
+ ```
190
+
191
+ #### Token-based Authentication
192
+
193
+ ```python
194
+ from xiaoshiai_hub import HubClient
195
+
196
+ client = HubClient(
197
+ token="your-api-token",
198
+ )
199
+ ```
200
+
201
+ ### Custom Base URL
202
+
203
+ ```python
204
+ from xiaoshiai_hub import snapshot_download
205
+
206
+ repo_path = snapshot_download(
207
+ repo_id="demo/demo",
208
+ base_url="https://your-custom-hub.example.com/api/moha",
209
+ username="your-username",
210
+ password="your-password",
211
+ )
212
+ ```
213
+
214
+ ### Specify Revision (Branch/Tag)
215
+
216
+ ```python
217
+ from xiaoshiai_hub import snapshot_download
218
+
219
+ # Download from a specific branch
220
+ repo_path = snapshot_download(
221
+ repo_id="demo/demo",
222
+ revision="develop",
223
+ username="your-username",
224
+ password="your-password",
225
+ )
226
+ ```
227
+
228
+ ### Cache Directory
229
+
230
+ ```python
231
+ from xiaoshiai_hub import snapshot_download
232
+
233
+ # Use a custom cache directory
234
+ repo_path = snapshot_download(
235
+ repo_id="demo/demo",
236
+ cache_dir="~/.cache/xiaoshiai",
237
+ username="your-username",
238
+ password="your-password",
239
+ )
240
+ ```
241
+
242
+ ## API Reference
243
+
244
+ ### Functions
245
+
246
+ #### `hf_hub_download()`
247
+
248
+ Download a single file from a repository.
249
+
250
+ **Parameters:**
251
+ - `repo_id` (str): Repository ID in format "organization/repo_name"
252
+ - `filename` (str): Path to the file in the repository
253
+ - `repo_type` (str, optional): "models" or "datasets" (default: "models")
254
+ - `revision` (str, optional): Branch/tag/commit to download from
255
+ - `cache_dir` (str | Path, optional): Directory to cache files
256
+ - `local_dir` (str | Path, optional): Directory to save the file
257
+ - `base_url` (str, optional): Base URL of the Hub API
258
+ - `username` (str, optional): Username for authentication
259
+ - `password` (str, optional): Password for authentication
260
+ - `token` (str, optional): Token for authentication
261
+
262
+ **Returns:** Path to the downloaded file
263
+
264
+ #### `snapshot_download()`
265
+
266
+ Download an entire repository snapshot.
267
+
268
+ **Parameters:**
269
+ - `repo_id` (str): Repository ID in format "organization/repo_name"
270
+ - `repo_type` (str, optional): "models" or "datasets" (default: "models")
271
+ - `revision` (str, optional): Branch/tag/commit to download from
272
+ - `cache_dir` (str | Path, optional): Directory to cache files
273
+ - `local_dir` (str | Path, optional): Directory to save files
274
+ - `allow_patterns` (str | List[str], optional): Patterns to allow (e.g., "*.yaml")
275
+ - `ignore_patterns` (str | List[str], optional): Patterns to ignore (e.g., ".git*")
276
+ - `base_url` (str, optional): Base URL of the Hub API
277
+ - `username` (str, optional): Username for authentication
278
+ - `password` (str, optional): Password for authentication
279
+ - `token` (str, optional): Token for authentication
280
+ - `verbose` (bool, optional): Print progress messages (default: True)
281
+
282
+ **Returns:** Path to the downloaded repository
283
+
284
+ ### Classes
285
+
286
+ #### `HubClient`
287
+
288
+ Main client for interacting with the Hub API.
289
+
290
+ **Methods:**
291
+ - `get_repository_info(organization, repo_type, repo_name)`: Get repository information
292
+ - `get_repository_refs(organization, repo_type, repo_name)`: List branches and tags
293
+ - `get_repository_content(organization, repo_type, repo_name, branch, path)`: Get content at path
294
+ - `download_file(organization, repo_type, repo_name, branch, file_path, local_path)`: Download a file
295
+
296
+ ## API Endpoints
297
+
298
+ The SDK uses the following API endpoints:
299
+
300
+ 1. **Repository Info**: `GET /organizations/{org}/{type}/{repo}`
301
+ 2. **Repository Refs**: `GET /organizations/{org}/{type}/{repo}/refs`
302
+ 3. **Repository Content**: `GET /organizations/{org}/{type}/{repo}/contents/{branch}/{path}`
303
+ 4. **File Download**: `GET /organizations/{org}/{type}/{repo}/resolve/{branch}/{file}`
304
+
305
+ ## Examples
306
+
307
+ See the `examples/` directory for more examples:
308
+
309
+ - `examples/download_single_file.py`: Download a single file
310
+ - `examples/download_repository.py`: Download entire repository
311
+ - `examples/download_with_filters.py`: Download with pattern filters
312
+ - `examples/list_repository_content.py`: List repository contents
313
+
314
+ ## License
315
+
316
+ Apache License 2.0
317
+
318
+ ## Contributing
319
+
320
+ Contributions are welcome! Please feel free to submit a Pull Request.
321
+
@@ -0,0 +1,281 @@
1
+ # XiaoShi AI Hub Python SDK
2
+
3
+ Python SDK for interacting with XiaoShi AI Hub repositories. This library provides a simple and intuitive interface for downloading models and datasets from XiaoShi AI Hub, similar to the Hugging Face Hub API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install xiaoshiai-hub
9
+ ```
10
+
11
+ Or install from source:
12
+
13
+ ```bash
14
+ cd python-sdk
15
+ pip install -e .
16
+ ```
17
+
18
+ ## Features
19
+
20
+ - ✅ **Download single files or entire repositories**
21
+ - ✅ **Progress bars** (like Hugging Face Hub) for download tracking
22
+ - ✅ **Pattern-based filtering** with allow/ignore patterns
23
+ - ✅ **Multiple authentication methods** (username/password, token)
24
+ - ✅ **Environment variable configuration** for flexible Hub URL setup
25
+ - ✅ **Caching support** for efficient reuse
26
+ - ✅ **Type hints** for better IDE support
27
+
28
+ ## Quick Start
29
+
30
+ ### Download a Single File
31
+
32
+ ```python
33
+ from xiaoshiai_hub import hf_hub_download
34
+
35
+ # Download a single file
36
+ file_path = hf_hub_download(
37
+ repo_id="demo/demo",
38
+ filename="config.yaml",
39
+ repo_type="models", # or "datasets"
40
+ username="your-username",
41
+ password="your-password",
42
+ )
43
+
44
+ print(f"File downloaded to: {file_path}")
45
+ ```
46
+
47
+ ### Download Entire Repository
48
+
49
+ ```python
50
+ from xiaoshiai_hub import snapshot_download
51
+
52
+ # Download entire repository
53
+ repo_path = snapshot_download(
54
+ repo_id="demo/demo",
55
+ repo_type="models",
56
+ username="your-username",
57
+ password="your-password",
58
+ )
59
+
60
+ print(f"Repository downloaded to: {repo_path}")
61
+ ```
62
+
63
+ ### Download with Filters
64
+
65
+ ```python
66
+ from xiaoshiai_hub import snapshot_download
67
+
68
+ # Download only YAML files, ignoring .git files
69
+ repo_path = snapshot_download(
70
+ repo_id="demo/demo",
71
+ repo_type="models",
72
+ allow_patterns=["*.yaml", "*.yml"],
73
+ ignore_patterns=[".git*"],
74
+ username="your-username",
75
+ password="your-password",
76
+ )
77
+ ```
78
+
79
+ ## Advanced Usage
80
+
81
+ ### Using the Client Directly
82
+
83
+ ```python
84
+ from xiaoshiai_hub import HubClient
85
+
86
+ # Create a client
87
+ client = HubClient(
88
+ base_url="https://rune.develop.xiaoshiai.cn/api/moha",
89
+ username="your-username",
90
+ password="your-password",
91
+ )
92
+
93
+ # Get repository information
94
+ repo_info = client.get_repository_info(
95
+ organization="demo",
96
+ repo_type="models",
97
+ repo_name="demo",
98
+ )
99
+ print(f"Repository: {repo_info.name}")
100
+ print(f"Default branch: {repo_info.default_branch}")
101
+
102
+ # List branches and tags
103
+ refs = client.get_repository_refs(
104
+ organization="demo",
105
+ repo_type="models",
106
+ repo_name="demo",
107
+ )
108
+ for ref in refs:
109
+ print(f"{ref.type}: {ref.name} ({ref.hash})")
110
+
111
+ # Get repository content
112
+ content = client.get_repository_content(
113
+ organization="demo",
114
+ repo_type="models",
115
+ repo_name="demo",
116
+ branch="main",
117
+ path="", # root directory
118
+ )
119
+
120
+ # List files
121
+ if content.entries:
122
+ for entry in content.entries:
123
+ print(f"{entry.type}: {entry.path} ({entry.size} bytes)")
124
+
125
+ # Download a specific file
126
+ client.download_file(
127
+ organization="demo",
128
+ repo_type="models",
129
+ repo_name="demo",
130
+ branch="main",
131
+ file_path="config.yaml",
132
+ local_path="./config.yaml",
133
+ )
134
+ ```
135
+
136
+ ### Authentication
137
+
138
+ The SDK supports multiple authentication methods:
139
+
140
+ #### Username and Password
141
+
142
+ ```python
143
+ from xiaoshiai_hub import HubClient
144
+
145
+ client = HubClient(
146
+ username="your-username",
147
+ password="your-password",
148
+ )
149
+ ```
150
+
151
+ #### Token-based Authentication
152
+
153
+ ```python
154
+ from xiaoshiai_hub import HubClient
155
+
156
+ client = HubClient(
157
+ token="your-api-token",
158
+ )
159
+ ```
160
+
161
+ ### Custom Base URL
162
+
163
+ ```python
164
+ from xiaoshiai_hub import snapshot_download
165
+
166
+ repo_path = snapshot_download(
167
+ repo_id="demo/demo",
168
+ base_url="https://your-custom-hub.example.com/api/moha",
169
+ username="your-username",
170
+ password="your-password",
171
+ )
172
+ ```
173
+
174
+ ### Specify Revision (Branch/Tag)
175
+
176
+ ```python
177
+ from xiaoshiai_hub import snapshot_download
178
+
179
+ # Download from a specific branch
180
+ repo_path = snapshot_download(
181
+ repo_id="demo/demo",
182
+ revision="develop",
183
+ username="your-username",
184
+ password="your-password",
185
+ )
186
+ ```
187
+
188
+ ### Cache Directory
189
+
190
+ ```python
191
+ from xiaoshiai_hub import snapshot_download
192
+
193
+ # Use a custom cache directory
194
+ repo_path = snapshot_download(
195
+ repo_id="demo/demo",
196
+ cache_dir="~/.cache/xiaoshiai",
197
+ username="your-username",
198
+ password="your-password",
199
+ )
200
+ ```
201
+
202
+ ## API Reference
203
+
204
+ ### Functions
205
+
206
+ #### `hf_hub_download()`
207
+
208
+ Download a single file from a repository.
209
+
210
+ **Parameters:**
211
+ - `repo_id` (str): Repository ID in format "organization/repo_name"
212
+ - `filename` (str): Path to the file in the repository
213
+ - `repo_type` (str, optional): "models" or "datasets" (default: "models")
214
+ - `revision` (str, optional): Branch/tag/commit to download from
215
+ - `cache_dir` (str | Path, optional): Directory to cache files
216
+ - `local_dir` (str | Path, optional): Directory to save the file
217
+ - `base_url` (str, optional): Base URL of the Hub API
218
+ - `username` (str, optional): Username for authentication
219
+ - `password` (str, optional): Password for authentication
220
+ - `token` (str, optional): Token for authentication
221
+
222
+ **Returns:** Path to the downloaded file
223
+
224
+ #### `snapshot_download()`
225
+
226
+ Download an entire repository snapshot.
227
+
228
+ **Parameters:**
229
+ - `repo_id` (str): Repository ID in format "organization/repo_name"
230
+ - `repo_type` (str, optional): "models" or "datasets" (default: "models")
231
+ - `revision` (str, optional): Branch/tag/commit to download from
232
+ - `cache_dir` (str | Path, optional): Directory to cache files
233
+ - `local_dir` (str | Path, optional): Directory to save files
234
+ - `allow_patterns` (str | List[str], optional): Patterns to allow (e.g., "*.yaml")
235
+ - `ignore_patterns` (str | List[str], optional): Patterns to ignore (e.g., ".git*")
236
+ - `base_url` (str, optional): Base URL of the Hub API
237
+ - `username` (str, optional): Username for authentication
238
+ - `password` (str, optional): Password for authentication
239
+ - `token` (str, optional): Token for authentication
240
+ - `verbose` (bool, optional): Print progress messages (default: True)
241
+
242
+ **Returns:** Path to the downloaded repository
243
+
244
+ ### Classes
245
+
246
+ #### `HubClient`
247
+
248
+ Main client for interacting with the Hub API.
249
+
250
+ **Methods:**
251
+ - `get_repository_info(organization, repo_type, repo_name)`: Get repository information
252
+ - `get_repository_refs(organization, repo_type, repo_name)`: List branches and tags
253
+ - `get_repository_content(organization, repo_type, repo_name, branch, path)`: Get content at path
254
+ - `download_file(organization, repo_type, repo_name, branch, file_path, local_path)`: Download a file
255
+
256
+ ## API Endpoints
257
+
258
+ The SDK uses the following API endpoints:
259
+
260
+ 1. **Repository Info**: `GET /organizations/{org}/{type}/{repo}`
261
+ 2. **Repository Refs**: `GET /organizations/{org}/{type}/{repo}/refs`
262
+ 3. **Repository Content**: `GET /organizations/{org}/{type}/{repo}/contents/{branch}/{path}`
263
+ 4. **File Download**: `GET /organizations/{org}/{type}/{repo}/resolve/{branch}/{file}`
264
+
265
+ ## Examples
266
+
267
+ See the `examples/` directory for more examples:
268
+
269
+ - `examples/download_single_file.py`: Download a single file
270
+ - `examples/download_repository.py`: Download entire repository
271
+ - `examples/download_with_filters.py`: Download with pattern filters
272
+ - `examples/list_repository_content.py`: List repository contents
273
+
274
+ ## License
275
+
276
+ Apache License 2.0
277
+
278
+ ## Contributing
279
+
280
+ Contributions are welcome! Please feel free to submit a Pull Request.
281
+