-
Notifications
You must be signed in to change notification settings - Fork 203
feat/core python api #1561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat/core python api #1561
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
477e31e
feat: add core_python type def
Nexisato ac900e8
chore: ignore extra ai docs
Nexisato 90bf92d
feat: add util function
Nexisato 3be6e38
feat: add multipart upload util function
Nexisato 6c062cb
feat: add core_python api implementation
Nexisato 04278cd
chore: update type def
Nexisato bd4b63a
chore: switch walrus operator
Nexisato d361dd6
refactor: correct experiment filed
Nexisato cf5bb79
chore: remove unused api
Nexisato c4c9cda
refactor: remove unused api
Nexisato 84d2f6b
chore: remove ununsed imports
Nexisato 5ea0250
chore: remove stop resp data
Nexisato 029f40b
chore: restore init export
Nexisato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,3 +56,5 @@ FEATURE_SUMMARY.md | |
| GEMINI.md | ||
| QWEN.md | ||
| .omx/ | ||
| .opencode/ | ||
| CODEBUDDY.md | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| """ | ||
| @author: cunyue | ||
| @file: self_hosted.py | ||
| @time: 2026/4/14 19:00 | ||
| @description: SwanLab 私有化部署API | ||
| """ | ||
|
|
||
| from swanlab.sdk.internal.core_python import client | ||
| from swanlab.sdk.typings.core_python.api.user import SelfHostedInfoType | ||
|
|
||
|
|
||
| def get_self_hosted_init() -> SelfHostedInfoType: | ||
| """ | ||
| 获取私有化部署信息 | ||
| """ | ||
| return client.get("/self_hosted/info").data | ||
|
|
||
|
|
||
| def create_user(*, username: str, password: str) -> None: | ||
| """ | ||
| 添加用户(私有化管理员限定) | ||
| :param username: 用户名 | ||
| :param password: 用户密码 | ||
| """ | ||
| data = {"users": [{"username": username, "password": password}]} | ||
| client.post("/self_hosted/users", data=data) | ||
|
|
||
|
|
||
| def get_users(*, page: int = 1, size: int = 20): | ||
| """ | ||
| 分页获取用户(管理员限定) | ||
| :param page: 页码 | ||
| :param size: 每页大小 | ||
| """ | ||
| params = {"page": page, "size": size} | ||
| return client.get("/self_hosted/users", params=params).data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| """ | ||
| @author: cunyue | ||
| @file: user.py | ||
| @time: 2026/4/14 19:00 | ||
| @description: SwanLab 运行时用户API | ||
| """ | ||
|
|
||
| from typing import List, Optional | ||
|
|
||
| from swanlab.sdk.internal.core_python import client | ||
| from swanlab.sdk.typings.core_python.api.user import ApiKeyType, GroupType | ||
| from swanlab.sdk.typings.core_python.api.workspace import WorkspaceInfoType | ||
|
|
||
|
|
||
| def create_api_key(*, name: Optional[str] = None) -> None: | ||
| """ | ||
| 创建一个api_key | ||
| :param name: api_key 的名称 | ||
| """ | ||
| client.post("/user/key", data={"name": name} if name else None) | ||
|
|
||
|
|
||
| def delete_api_key(*, key_id: int) -> None: | ||
| """ | ||
| 删除指定id的api_key | ||
| :param key_id: api_key的id | ||
| """ | ||
| client.delete(f"/user/key/{key_id}") | ||
|
|
||
|
|
||
| def get_user_groups(*, username: str) -> List[GroupType]: | ||
| """ | ||
| 获取用户加入的组织 | ||
| :param username: 用户名称 | ||
| """ | ||
| return client.get(f"/user/{username}/groups").data | ||
|
|
||
|
|
||
| def get_workspace_info(*, path: str) -> WorkspaceInfoType: | ||
| """ | ||
| 获取指定工作空间的信息 | ||
| :param path: 工作空间名称 | ||
| """ | ||
| return client.get(f"/group/{path}").data | ||
|
|
||
|
|
||
| def get_api_keys() -> List[ApiKeyType]: | ||
| """ | ||
| 获取当前全部的api_key | ||
| """ | ||
| return client.get("/user/key").data | ||
|
|
||
|
|
||
| def get_latest_api_key() -> ApiKeyType: | ||
| """ | ||
| 获取最新的api_key | ||
| """ | ||
| return client.get("/user/key/latest").data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
Nexisato marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| """Common Type Definition""" | ||
|
|
||
| from typing import TypedDict | ||
|
|
||
|
|
||
| class LabelType(TypedDict): | ||
| name: str |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.