yicloud-sdk-python 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.
Files changed (65) hide show
  1. yicloud_sdk_python-0.1.0/LICENSE +202 -0
  2. yicloud_sdk_python-0.1.0/PKG-INFO +145 -0
  3. yicloud_sdk_python-0.1.0/README.md +106 -0
  4. yicloud_sdk_python-0.1.0/pyproject.toml +52 -0
  5. yicloud_sdk_python-0.1.0/setup.cfg +4 -0
  6. yicloud_sdk_python-0.1.0/version.py +9 -0
  7. yicloud_sdk_python-0.1.0/yicloud/__init__.py +7 -0
  8. yicloud_sdk_python-0.1.0/yicloud/base/__init__.py +58 -0
  9. yicloud_sdk_python-0.1.0/yicloud/base/auth/__init__.py +10 -0
  10. yicloud_sdk_python-0.1.0/yicloud/base/auth/credential.py +64 -0
  11. yicloud_sdk_python-0.1.0/yicloud/base/auth/sign.py +80 -0
  12. yicloud_sdk_python-0.1.0/yicloud/base/client.py +313 -0
  13. yicloud_sdk_python-0.1.0/yicloud/base/config.py +62 -0
  14. yicloud_sdk_python-0.1.0/yicloud/base/errs/__init__.py +292 -0
  15. yicloud_sdk_python-0.1.0/yicloud/base/log/__init__.py +43 -0
  16. yicloud_sdk_python-0.1.0/yicloud/base/log/logger.py +123 -0
  17. yicloud_sdk_python-0.1.0/yicloud/base/log/std.py +70 -0
  18. yicloud_sdk_python-0.1.0/yicloud/base/msgs/__init__.py +226 -0
  19. yicloud_sdk_python-0.1.0/yicloud/base/utils/__init__.py +6 -0
  20. yicloud_sdk_python-0.1.0/yicloud/base/utils/helps.py +110 -0
  21. yicloud_sdk_python-0.1.0/yicloud/base/utils/retry/__init__.py +27 -0
  22. yicloud_sdk_python-0.1.0/yicloud/base/utils/retry/retry.py +162 -0
  23. yicloud_sdk_python-0.1.0/yicloud/services/__init__.py +24 -0
  24. yicloud_sdk_python-0.1.0/yicloud/services/bc/__init__.py +9 -0
  25. yicloud_sdk_python-0.1.0/yicloud/services/bc/actions.py +23 -0
  26. yicloud_sdk_python-0.1.0/yicloud/services/bc/client.py +19 -0
  27. yicloud_sdk_python-0.1.0/yicloud/services/bc/models.py +61 -0
  28. yicloud_sdk_python-0.1.0/yicloud/services/fs/__init__.py +29 -0
  29. yicloud_sdk_python-0.1.0/yicloud/services/fs/actions.py +109 -0
  30. yicloud_sdk_python-0.1.0/yicloud/services/fs/client.py +19 -0
  31. yicloud_sdk_python-0.1.0/yicloud/services/fs/models.py +152 -0
  32. yicloud_sdk_python-0.1.0/yicloud/services/iam/__init__.py +27 -0
  33. yicloud_sdk_python-0.1.0/yicloud/services/iam/actions.py +304 -0
  34. yicloud_sdk_python-0.1.0/yicloud/services/iam/client.py +19 -0
  35. yicloud_sdk_python-0.1.0/yicloud/services/iam/models.py +276 -0
  36. yicloud_sdk_python-0.1.0/yicloud/services/job/__init__.py +44 -0
  37. yicloud_sdk_python-0.1.0/yicloud/services/job/actions.py +167 -0
  38. yicloud_sdk_python-0.1.0/yicloud/services/job/client.py +19 -0
  39. yicloud_sdk_python-0.1.0/yicloud/services/job/models.py +268 -0
  40. yicloud_sdk_python-0.1.0/yicloud/services/mc/__init__.py +59 -0
  41. yicloud_sdk_python-0.1.0/yicloud/services/mc/actions.py +221 -0
  42. yicloud_sdk_python-0.1.0/yicloud/services/mc/client.py +21 -0
  43. yicloud_sdk_python-0.1.0/yicloud/services/mc/models.py +322 -0
  44. yicloud_sdk_python-0.1.0/yicloud/services/modelrepo/__init__.py +33 -0
  45. yicloud_sdk_python-0.1.0/yicloud/services/modelrepo/actions.py +163 -0
  46. yicloud_sdk_python-0.1.0/yicloud/services/modelrepo/client.py +19 -0
  47. yicloud_sdk_python-0.1.0/yicloud/services/modelrepo/models.py +146 -0
  48. yicloud_sdk_python-0.1.0/yicloud/services/modelset/__init__.py +45 -0
  49. yicloud_sdk_python-0.1.0/yicloud/services/modelset/actions.py +130 -0
  50. yicloud_sdk_python-0.1.0/yicloud/services/modelset/client.py +19 -0
  51. yicloud_sdk_python-0.1.0/yicloud/services/modelset/models.py +356 -0
  52. yicloud_sdk_python-0.1.0/yicloud/services/oss/__init__.py +25 -0
  53. yicloud_sdk_python-0.1.0/yicloud/services/oss/actions.py +83 -0
  54. yicloud_sdk_python-0.1.0/yicloud/services/oss/client.py +19 -0
  55. yicloud_sdk_python-0.1.0/yicloud/services/oss/models.py +113 -0
  56. yicloud_sdk_python-0.1.0/yicloud/services/registry/__init__.py +42 -0
  57. yicloud_sdk_python-0.1.0/yicloud/services/registry/actions.py +208 -0
  58. yicloud_sdk_python-0.1.0/yicloud/services/registry/client.py +19 -0
  59. yicloud_sdk_python-0.1.0/yicloud/services/registry/models.py +183 -0
  60. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/PKG-INFO +145 -0
  61. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/SOURCES.txt +63 -0
  62. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/dependency_links.txt +1 -0
  63. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/not-zip-safe +1 -0
  64. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/requires.txt +17 -0
  65. yicloud_sdk_python-0.1.0/yicloud_sdk_python.egg-info/top_level.txt +3 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.4
2
+ Name: yicloud-sdk-python
3
+ Version: 0.1.0
4
+ Summary: YiCloud OpenAPI SDK for Python
5
+ Author: YiCloud
6
+ Project-URL: Homepage, https://gitee.com/yicloud-team/openapi-sdk-python
7
+ Classifier: Development Status :: 3 - Alpha
8
+ Classifier: Environment :: Console
9
+ Classifier: Environment :: Web Environment
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Intended Audience :: System Administrators
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.7
15
+ Classifier: Programming Language :: Python :: 3.8
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Software Development
21
+ Requires-Python: >=3.7
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: requests
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=7.0; extra == "test"
27
+ Requires-Dist: pytest-cov>=3.0; extra == "test"
28
+ Requires-Dist: requests-mock>=1.10; extra == "test"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest>=7.0; extra == "dev"
31
+ Requires-Dist: pytest-cov>=3.0; extra == "dev"
32
+ Requires-Dist: requests-mock>=1.10; extra == "dev"
33
+ Requires-Dist: black>=23.0; extra == "dev"
34
+ Requires-Dist: ruff>=0.1; extra == "dev"
35
+ Provides-Extra: lint
36
+ Requires-Dist: ruff>=0.1; extra == "lint"
37
+ Requires-Dist: mypy>=1.0; extra == "lint"
38
+ Dynamic: license-file
39
+
40
+ # OpenAPI SDK for Python
41
+
42
+ A Python SDK for the OpenAPI service.
43
+
44
+ ## Installation
45
+
46
+ 使用 pip 安装(推荐):
47
+
48
+ ```bash
49
+ pip install yicloud-sdk-python
50
+ ```
51
+
52
+ 从源码安装(不推荐):
53
+ git clone https://gitee.com/yicloud-team/openapi-sdk-python.git
54
+ cd openapi-sdk-python
55
+ pip install -e .
56
+
57
+ ## Configuration
58
+
59
+ The SDK reads configuration from environment variables:
60
+
61
+ | Variable | Default | Description |
62
+ |----------|---------|-------------|
63
+ | YICLOUD_API_HOST | https://gate.yicloud.com | API endpoint |
64
+ | YICLOUD_TIMEOUT | 30 | Timeout in seconds |
65
+ | YICLOUD_MAX_RETRIES | 0 | Max retry attempts |
66
+ | YICLOUD_PUBLIC_KEY | - | Access key (required) |
67
+ | YICLOUD_SECRET_KEY | - | Secret key (required) |
68
+
69
+ ## Usage
70
+
71
+ ```python
72
+ import yicloud.base as base
73
+ from yicloud.services import iam
74
+ from yicloud.base import msgs
75
+
76
+ # Create config (reads from env vars)
77
+ cfg = base.new_config()
78
+ cfg.log_level = base.log.Level.DEBUG
79
+ cfg.timeout = 10
80
+
81
+ # Create credential (reads from env vars)
82
+ credential = base.new_credential()
83
+
84
+ # Create client
85
+ client = base.new_client(
86
+ base.with_config(cfg),
87
+ base.with_credential(credential),
88
+ )
89
+
90
+ # Inject client into service
91
+ iam.use_client(client)
92
+
93
+ # Create metadata context
94
+ ctx, meta = msgs.new_meta_ctx()
95
+
96
+ # Call API
97
+ try:
98
+ user_data = iam.get_user(ctx, iam.GetUserReq(UserName="admin"))
99
+ print(f"成功返回: {user_data}, RequestID={meta.request_id}")
100
+ except base.exc.ServerException as e:
101
+ print(f"后端错误: action={e.action}, code={e.code}, message={e.message}")
102
+ except base.exc.ClientException as e:
103
+ print(f"客户端错误: action={e.action}")
104
+ except base.exc.YiCloudException as e:
105
+ print(f"SDK 错误: {e}")
106
+ ```
107
+
108
+ ## Services
109
+
110
+ | Service | Package | Actions | Description |
111
+ |---------|---------|---------|-------------|
112
+ | IAM | `yicloud.services.iam` | 22 | User, AccessKey, Project, QuotaGroup management |
113
+ | Job | `yicloud.services.job` | 11 | Job lifecycle, logs, replicas |
114
+ | MC | `yicloud.services.mc` | 16 | Node, SKU, Project, QuotaGroup management |
115
+ | FS | `yicloud.services.fs` | 7 | Fileset, directory operations |
116
+ | OSS | `yicloud.services.oss` | 5 | Bucket CRUD |
117
+ | Registry | `yicloud.services.registry` | 14 | Image and repository management |
118
+ | ModelRepo | `yicloud.services.modelrepo` | 11 | Model and version management |
119
+ | ModelSet | `yicloud.services.modelset` | 9 | ModelSet lifecycle and scaling |
120
+ | BC | `yicloud.services.bc` | 1 | Billing details |
121
+
122
+ ## Project Structure
123
+
124
+ ```
125
+ yicloud/ # Main package
126
+ ├── base/ # Infrastructure
127
+ │ ├── client.py # HTTP client (Get/Post)
128
+ │ ├── config.py # Configuration
129
+ │ ├── exc.py # Exception types
130
+ │ ├── auth/ # HMAC-SHA256 signing
131
+ │ ├── log/ # Logger
132
+ │ ├── msgs/ # Response types (Rsp[T], Header, RspMeta)
133
+ │ └── utils/ # Utilities
134
+ └── services/ # Business services (9 services)
135
+ ├── iam/ # Identity & Access Management
136
+ ├── job/ # Job management
137
+ ├── mc/ # Multi-cluster management
138
+ ├── fs/ # Filesystem management
139
+ ├── oss/ # Object storage
140
+ ├── registry/ # Container registry
141
+ ├── modelrepo/ # Model repository
142
+ ├── modelset/ # ModelSet lifecycle
143
+ └── bc/ # Billing center
144
+ examples/ # Example code (one per service)
145
+ ```
@@ -0,0 +1,106 @@
1
+ # OpenAPI SDK for Python
2
+
3
+ A Python SDK for the OpenAPI service.
4
+
5
+ ## Installation
6
+
7
+ 使用 pip 安装(推荐):
8
+
9
+ ```bash
10
+ pip install yicloud-sdk-python
11
+ ```
12
+
13
+ 从源码安装(不推荐):
14
+ git clone https://gitee.com/yicloud-team/openapi-sdk-python.git
15
+ cd openapi-sdk-python
16
+ pip install -e .
17
+
18
+ ## Configuration
19
+
20
+ The SDK reads configuration from environment variables:
21
+
22
+ | Variable | Default | Description |
23
+ |----------|---------|-------------|
24
+ | YICLOUD_API_HOST | https://gate.yicloud.com | API endpoint |
25
+ | YICLOUD_TIMEOUT | 30 | Timeout in seconds |
26
+ | YICLOUD_MAX_RETRIES | 0 | Max retry attempts |
27
+ | YICLOUD_PUBLIC_KEY | - | Access key (required) |
28
+ | YICLOUD_SECRET_KEY | - | Secret key (required) |
29
+
30
+ ## Usage
31
+
32
+ ```python
33
+ import yicloud.base as base
34
+ from yicloud.services import iam
35
+ from yicloud.base import msgs
36
+
37
+ # Create config (reads from env vars)
38
+ cfg = base.new_config()
39
+ cfg.log_level = base.log.Level.DEBUG
40
+ cfg.timeout = 10
41
+
42
+ # Create credential (reads from env vars)
43
+ credential = base.new_credential()
44
+
45
+ # Create client
46
+ client = base.new_client(
47
+ base.with_config(cfg),
48
+ base.with_credential(credential),
49
+ )
50
+
51
+ # Inject client into service
52
+ iam.use_client(client)
53
+
54
+ # Create metadata context
55
+ ctx, meta = msgs.new_meta_ctx()
56
+
57
+ # Call API
58
+ try:
59
+ user_data = iam.get_user(ctx, iam.GetUserReq(UserName="admin"))
60
+ print(f"成功返回: {user_data}, RequestID={meta.request_id}")
61
+ except base.exc.ServerException as e:
62
+ print(f"后端错误: action={e.action}, code={e.code}, message={e.message}")
63
+ except base.exc.ClientException as e:
64
+ print(f"客户端错误: action={e.action}")
65
+ except base.exc.YiCloudException as e:
66
+ print(f"SDK 错误: {e}")
67
+ ```
68
+
69
+ ## Services
70
+
71
+ | Service | Package | Actions | Description |
72
+ |---------|---------|---------|-------------|
73
+ | IAM | `yicloud.services.iam` | 22 | User, AccessKey, Project, QuotaGroup management |
74
+ | Job | `yicloud.services.job` | 11 | Job lifecycle, logs, replicas |
75
+ | MC | `yicloud.services.mc` | 16 | Node, SKU, Project, QuotaGroup management |
76
+ | FS | `yicloud.services.fs` | 7 | Fileset, directory operations |
77
+ | OSS | `yicloud.services.oss` | 5 | Bucket CRUD |
78
+ | Registry | `yicloud.services.registry` | 14 | Image and repository management |
79
+ | ModelRepo | `yicloud.services.modelrepo` | 11 | Model and version management |
80
+ | ModelSet | `yicloud.services.modelset` | 9 | ModelSet lifecycle and scaling |
81
+ | BC | `yicloud.services.bc` | 1 | Billing details |
82
+
83
+ ## Project Structure
84
+
85
+ ```
86
+ yicloud/ # Main package
87
+ ├── base/ # Infrastructure
88
+ │ ├── client.py # HTTP client (Get/Post)
89
+ │ ├── config.py # Configuration
90
+ │ ├── exc.py # Exception types
91
+ │ ├── auth/ # HMAC-SHA256 signing
92
+ │ ├── log/ # Logger
93
+ │ ├── msgs/ # Response types (Rsp[T], Header, RspMeta)
94
+ │ └── utils/ # Utilities
95
+ └── services/ # Business services (9 services)
96
+ ├── iam/ # Identity & Access Management
97
+ ├── job/ # Job management
98
+ ├── mc/ # Multi-cluster management
99
+ ├── fs/ # Filesystem management
100
+ ├── oss/ # Object storage
101
+ ├── registry/ # Container registry
102
+ ├── modelrepo/ # Model repository
103
+ ├── modelset/ # ModelSet lifecycle
104
+ └── bc/ # Billing center
105
+ examples/ # Example code (one per service)
106
+ ```
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "yicloud-sdk-python"
7
+ version = "0.1.0"
8
+ description = "YiCloud OpenAPI SDK for Python"
9
+ readme = "README.md"
10
+ requires-python = ">=3.7"
11
+ dependencies = [
12
+ "requests",
13
+ ]
14
+ authors = [
15
+ {name = "YiCloud"},
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Environment :: Console",
20
+ "Environment :: Web Environment",
21
+ "Intended Audience :: Developers",
22
+ "Intended Audience :: System Administrators",
23
+ "License :: OSI Approved :: Apache Software License",
24
+ "Programming Language :: Python :: 3 :: Only",
25
+ "Programming Language :: Python :: 3.7",
26
+ "Programming Language :: Python :: 3.8",
27
+ "Programming Language :: Python :: 3.9",
28
+ "Programming Language :: Python :: 3.10",
29
+ "Programming Language :: Python :: 3.11",
30
+ "Programming Language :: Python :: 3.12",
31
+ "Topic :: Software Development",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://gitee.com/yicloud-team/openapi-sdk-python"
36
+
37
+ [project.optional-dependencies]
38
+ test = ["pytest>=7.0", "pytest-cov>=3.0", "requests-mock>=1.10"]
39
+ dev = ["pytest>=7.0", "pytest-cov>=3.0", "requests-mock>=1.10", "black>=23.0", "ruff>=0.1"]
40
+ lint = ["ruff>=0.1", "mypy>=1.0"]
41
+
42
+ [tool.setuptools]
43
+ zip-safe = false
44
+ py-modules = ["version"]
45
+
46
+ [tool.setuptools.packages.find]
47
+ exclude = ["tests*", "examples*", "venv*", ".idea*", "__pycache__*"]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
51
+ python_files = "test_*.py"
52
+ addopts = "-v"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,9 @@
1
+ __version__ = "0.1.0"
2
+
3
+
4
+ def Version() -> str:
5
+ return __version__
6
+
7
+
8
+ def UserAgent() -> str:
9
+ return f"openapi-sdk-python/{__version__}"
@@ -0,0 +1,7 @@
1
+ """
2
+ YiCloud Python SDK
3
+
4
+ A Python SDK for the YiCloud OpenAPI service.
5
+ """
6
+
7
+ __version__ = "0.1.0"
@@ -0,0 +1,58 @@
1
+ from yicloud.base.client import (
2
+ Client,
3
+ DefaultClient,
4
+ new_client,
5
+ get,
6
+ post,
7
+ with_transport,
8
+ with_http_client,
9
+ with_host,
10
+ with_config,
11
+ with_credential,
12
+ with_logger,
13
+ new_net_err,
14
+ is_net_err,
15
+ action_of_path,
16
+ )
17
+
18
+ from yicloud.base import auth, config, errs, log, msgs, utils
19
+
20
+
21
+ def new_config() -> config.Config:
22
+ """Create a new config with default values from environment."""
23
+ return config.Config.new()
24
+
25
+
26
+ def new_credential() -> auth.Credential:
27
+ """Create a new credential with default values from environment."""
28
+ return auth.Credential.new_credential()
29
+
30
+
31
+ __all__ = [
32
+ "Client",
33
+ "DefaultClient",
34
+ "new_client",
35
+ "new_config",
36
+ "new_credential",
37
+ "get",
38
+ "post",
39
+ "with_transport",
40
+ "with_http_client",
41
+ "with_host",
42
+ "with_config",
43
+ "with_credential",
44
+ "with_logger",
45
+ "new_net_err",
46
+ "is_net_err",
47
+ "action_of_path",
48
+ "auth",
49
+ "config",
50
+ "errs",
51
+ "exc",
52
+ "log",
53
+ "msgs",
54
+ "utils",
55
+ ]
56
+
57
+ # exc alias for convenience, matches ucloud-sdk pattern
58
+ exc = errs
@@ -0,0 +1,10 @@
1
+ from yicloud.base.auth.credential import Credential, DefaultCredential, sign
2
+ from yicloud.base.auth.sign import hmac_sign, parse_and_sort_query
3
+
4
+ __all__ = [
5
+ "Credential",
6
+ "DefaultCredential",
7
+ "sign",
8
+ "hmac_sign",
9
+ "parse_and_sort_query",
10
+ ]
@@ -0,0 +1,64 @@
1
+ import os
2
+ import time
3
+ import json as json_module
4
+ from typing import Any
5
+ from yicloud.base.auth.sign import hmac_sign
6
+
7
+
8
+ class Credential:
9
+ """Credential struct matching Go SDK's auth.Credential."""
10
+
11
+ def __init__(self, public_key: str = "", private_key: str = ""):
12
+ self.public_key = public_key
13
+ self.private_key = private_key
14
+
15
+ @classmethod
16
+ def new_credential(cls) -> "Credential":
17
+ """Return credential with default values from env."""
18
+ cred = cls()
19
+ cred._apply_env()
20
+ return cred
21
+
22
+ def _apply_env(self):
23
+ """Apply environment variables to credential."""
24
+ v = os.getenv("YICLOUD_PUBLIC_KEY")
25
+ if v and v.strip():
26
+ self.public_key = v
27
+
28
+ v = os.getenv("YICLOUD_SECRET_KEY")
29
+ if v and v.strip():
30
+ self.private_key = v
31
+
32
+ def sign(self, tick: time.struct_time, query: str, body: Any) -> str:
33
+ """Create signature encoding query string to credential signature."""
34
+ body_str = Credential._any_to_string(body)
35
+ timestamp = str(int(time.mktime(tick) * 1000))
36
+ return hmac_sign(timestamp, self.public_key, self.private_key, query, body_str)
37
+
38
+ @staticmethod
39
+ def _any_to_string(value: Any) -> str:
40
+ """Convert any type to signature string, matching Go SDK's anyToString."""
41
+ if value is None:
42
+ return ""
43
+
44
+ if isinstance(value, str):
45
+ return value
46
+
47
+ if isinstance(value, bytes):
48
+ return value.decode("utf-8")
49
+
50
+ # For complex types (dict, list, etc.), use JSON serialization
51
+ if isinstance(value, (dict, list)):
52
+ return json_module.dumps(value, separators=(",", ":"))
53
+
54
+ # For simple types, use str()
55
+ return str(value)
56
+
57
+
58
+ # Default credential singleton
59
+ DefaultCredential = Credential.new_credential()
60
+
61
+
62
+ def sign(tick: time.struct_time, query: str, body: Any) -> str:
63
+ """Package-level sign function using DefaultCredential."""
64
+ return DefaultCredential.sign(tick, query, body)