openxlab tools
Project description
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的有一下几种方法,任选一种即可:
-
本地使用python -m openxlab.cli config命令调试,按照提示输入对应的access key和secret access key。完成后会在~/.openxlab目录下生成config.json文件,格式如下:
{ "ak": "xxx", "sk": "xxx" }
-
直接在~/.openxlab目录下创建对应的config.json文件,格式如上。
-
设置环境变量。可以将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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openxlab_test-0.0.26.tar.gz.
File metadata
- Download URL: openxlab_test-0.0.26.tar.gz
- Upload date:
- Size: 271.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36deb5e0178720ed5ce596c70dad5749e2dd58eda0d01a573415e4f3f0532a2
|
|
| MD5 |
bf051247dc609549667c4cb02254f05f
|
|
| BLAKE2b-256 |
5c7d117fa90bbcb32c0bd89b32faf76c3647eeb1875d2f24c14ef6ea8fee84e0
|
File details
Details for the file openxlab_test-0.0.26-py3-none-any.whl.
File metadata
- Download URL: openxlab_test-0.0.26-py3-none-any.whl
- Upload date:
- Size: 297.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
930a54e86141cd92f0415798e878a3852697bd03788dd9d2d3da71d49eaa5bc3
|
|
| MD5 |
4349e5108c5f4121a14ce26d818d1b8a
|
|
| BLAKE2b-256 |
303e79bd10b5a072de3d60d1a96a835a630bd2bb7ed0731cc8ba7b623044a1b3
|