Skip to content

Conversation

kites262
Copy link
Member

@kites262 kites262 commented Apr 30, 2025

Description

实现OpenAPI功能, 添加第一个开放API: list_workspaces()

from swanlab import OpenApi

# 使用之前的登录信息(.netrc)
my_api = OpenApi()
my_workspaces = my_api.list_workspaces()

# 使用另一个账户的key
other_api = OpenApi(key='other_api_key')
print(other_api.list_workspaces())

可得到my_workspaces(Python列表)

[{
	'name': 'workspace1',
	'username': 'kites-test3',
	'role': 'OWNER'
},
{
	'name': 'hello-openapi',
	'username': 'kites-test2',
	'role': 'MEMBER'
},
...
]

认证

  • 如果显式提供key, 则使用该key进行认证
  • 否则开放API的认证与swanlab.init()的认证逻辑一致, 即
    • 曾在终端登录过
    • 显式使用swanlab.login()登录

🎯 PRs Should Target Issues

#960 (comment)

@kites262 kites262 requested review from swpfY and SAKURA-CAT April 30, 2025 14:21
@kites262 kites262 requested a review from SAKURA-CAT May 2, 2025 09:53
@SAKURA-CAT SAKURA-CAT added the 💪 enhancement New feature or request label May 5, 2025
@SAKURA-CAT
Copy link
Member

GOOD JOB

@SAKURA-CAT SAKURA-CAT merged commit f262388 into feature/openapis May 6, 2025
5 checks passed
@SAKURA-CAT SAKURA-CAT deleted the feature/openapi/list-workspaces branch May 6, 2025 05:13
SAKURA-CAT added a commit that referenced this pull request May 12, 2025
* feat(openapi): list workspaces (#961)

* feat(openapi): list workspaces

* refa(openapi): login logic

* docs(openapi): revise

* fix(test): no cloud

* feat(openapi): auto catch ApiError

* Add `get_exp_state` for OpenAPI

Add `get_exp_state` for OpenAPI (#963)

---------

Co-authored-by: kites262 <kites262@qq.com>

* feat(openapi): get experiment (#964)

* feature: get experiment
* fix some

* feat(openapi): get project exps

* feat(openapi): types

* fix: py<3.8

* refa(openapi): types for ide

* feat(openapi): list projects (#966)

* feat(openapi): list project

* refactor(openapi): list projects with apiresponse type

* refactor(openapi): rewrite list comprehension

* fix: typo

* refa(openapi): general fetch paginated api

* fix(openapi): test & default value

---------

Co-authored-by: kites262 <kites262@qq.com>

* chore: fix desc & comment

---------

Co-authored-by: hyYY-1024 <75209465+hyYY-1024@users.noreply.github.com>
Co-authored-by: Kaikai <98205900+Kaikaikaifang@users.noreply.github.com>
Co-authored-by: CaddiesNew <50736785+Nexisato@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants