Skip to main content

openxlab-cli

Getting started

代码结构

├─openxlab
│  ├─config                存放通用配置
│  ├─demo                  给出的一个demo,模型中心,应用中心可以创建自己的文件夹
│  ├─types     通用参数定义
│  ├─utils     存放通用方法
│  ├─xlab     主站逻辑

架构说明

types 中定义定义命令基类

  • sub_command_list 填入下一级命令对应的类定义
  • add_args 用于添加当前命令的参数 --xxx
  • take_action 用于定义当前命令的行为,未实现默认使用 argparse 的 help

命令继承基类实现,通过 sub_command_list 实现多级子命令

安装依赖环境

python -m pip install .

本地测试

 python -m openxlab.cli
 python -m openxlab.cli  demo help  
 python -m openxlab.cli  demo upload

testpypi 联调

修改 config -> version.py 的版本 +1

pip install build

打包,  命令将生成一个 dist 目录
python -m build

本地安装
pip install .\dist\openxlab-0.0.7-py3-none-any.whl

# 上传 pip 包到 test pypi
twine upload --repository testpypi dist/*

# 从 test pypi 下载
pip install -i https://test.pypi.org/simple/ openxlab==0.0.1

从 test pypi 更新
pip install -i https://test.pypi.org/simple/ -U openxlab

ak和sk的设置

设置ak,sk的有一下几种方法,任选一种即可:

  1. 本地使用python -m openxlab.cli config命令调试,按照提示输入对应的access key和secret access key。完成后会在~/.openxlab目录下生成config.json文件,格式如下:

    {
        "ak": "xxx",
        "sk": "xxx"
    }
    
  2. 直接在~/.openxlab目录下创建对应的config.json文件,格式如上。

  3. 设置环境变量。可以将access key设置到名为OPENXLAB_AK的环境变量下,secret access key设置到名为OPENXLAB_SK的环境变量下。

token的获取

在设置好ak和sk之后,业务方可以调用openxlab.xlab.handler.user_token.get_jwt方法获得token。

def get_jwt(ak=None, sk=None):
    return get_token(ak, sk).jwt

该方法拥有ak和sk两个可选参数,允许业务方调用该方法时传递ak和sk。ak和sk生效的优先级如下:

get_jwt方法中的ak和sk参数(如果不为空) > ~/.openxlab/config.json文件 > OPENXLAB_AK和OPENXLAB_SK环境变量。   

如果上面三者都为空,则在调用get_jwt方法时会抛出异常如下:

ValueError("Local config must not be empty before get token via api. "
                         "Please use the 'openxlab config' command to set the config")

get_jwt方法调用成功后,会在~/.openxlab目录下生成token.json文件,格式如下:

{
    "expiration": "2023-05-16 16:29:03",
    "jwt": "Bearer eyJxxx",
    "refresh_expiration": "2023-05-23 15:29:03",
    "refresh_time": "2023-05-16 15:29:03",
    "refresh_token": "Bearer eyJxxx",
    "sso_uid": "xxx"
}

Change Log

v0.1.0

  • Release the initial version

Metadata

Release files for openxlab-test 0.0.26

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openxlab-test 0.0.26
File Size Uploaded
openxlab_test-0.0.26.tar.gz 271.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openxlab-test 0.0.26
File Interpreter ABI Platform
openxlab_test-0.0.26-py3-none-any.whl Python 3 none any Details

Total release size: 568.9 kB

Release files / openxlab_test-0.0.26.tar.gz

Download URL openxlab_test-0.0.26.tar.gz
Size 271.0 kB
Tags Source
SHA-256 checksum
How to use checksums
d36deb5e0178720ed5ce596c70dad5749e2dd58eda0d01a573415e4f3f0532a2
BLAKE2b-256 checksum
How to use checksums
5c7d117fa90bbcb32c0bd89b32faf76c3647eeb1875d2f24c14ef6ea8fee84e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / openxlab_test-0.0.26-py3-none-any.whl

Download URL openxlab_test-0.0.26-py3-none-any.whl
Size 297.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
930a54e86141cd92f0415798e878a3852697bd03788dd9d2d3da71d49eaa5bc3
BLAKE2b-256 checksum
How to use checksums
303e79bd10b5a072de3d60d1a96a835a630bd2bb7ed0731cc8ba7b623044a1b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.0.26 This release

2 release files

0.0.25

2 release files

0.0.23

2 release files

0.0.22

2 release files

0.0.21

2 release files

0.0.20

2 release files

0.0.19

2 release files

0.0.18

2 release files

0.0.17

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page