Skip to main content

A python sdk for AIIT OS

Project description

AIIT-SDK

安装

pip install aiit-sdk

如果需要指定安装源,可以使用 -i 参数

pip install aiit-sdk  --index-url https://pypi.org/simple/

版本更新,可以使用 --upgrade 参数更新

pip install --upgrade aiit-sdk  --index-url https://pypi.org/simple/

使用说明

登陆模块

在 settings.py 的 SIMPLE_JWT.AUTH_TOKEN_CLASSES 参数下面添加 aiit_sdk.auth.AiitToken

配置完成以后,通过大数据OS颁发的 token 就可以正常获取数据,并且后端可以通过 request.user 获取到用户信息。

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(days=1),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=7),
    'ROTATE_REFRESH_TOKENS': True,
    'BLACKLIST_AFTER_ROTATION': True,

    'ALGORITHM': 'HS256',
    'SIGNING_KEY': JWT_SIGNING_KEY,
    'VERIFYING_KEY': None,

    'AUTH_HEADER_TYPES': ('Bearer', 'JWT'),
    'USER_ID_FIELD': 'id',
    'USER_ID_CLAIM': 'user_id',

    'AUTH_TOKEN_CLASSES': (
        'aiit_sdk.auth.AiitToken',  # 允许大数据OS颁发的Token访问
        'rest_framework_simplejwt.tokens.AccessToken',
    ),
    'TOKEN_TYPE_CLAIM': 'token_type',

    'JTI_CLAIM': 'jti',

    'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
    'SLIDING_TOKEN_LIFETIME': timedelta(days=7),
    'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=30),
}

接口返回

为了规范数据返回格式,建议通过 APIResponse 进行数据返回。

示例代码:

from aiit_sdk.response import APIResponse


class FileUploadView(APIView):
    def post(self, request):
        #  业务代码
        data = {}  # 要返回的数据
        return APIResponse(data=data)

返回的数据格式:

{
    "data": {},
    "message": "ok",
    "code": 200
}

分页模块

默认分页模块的配置

将 settings.py 的 REST_FRAMEWORK.DEFAULT_PAGINATION_CLASS 参数设置成 aiit_sdk.page.NormalResultsSetPagination

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'rest_framework_simplejwt.authentication.JWTTokenUserAuthentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        # 'rest_framework.permissions.IsAuthenticated',
    ),
    'DATETIME_FORMAT': '%Y-%m-%d %H:%M:%S',
    'DEFAULT_PAGINATION_CLASS': 'aiit_sdk.page.NormalResultsSetPagination',  # 默认分页模块的配置
    'DEFAULT_FILTER_BACKENDS': (
        'django_filters.rest_framework.DjangoFilterBackend',
        'rest_framework.filters.OrderingFilter',
        'rest_framework.filters.SearchFilter'
    ),
    'PAGE_SIZE': 20,
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
}

模版视图

位于 view 模块下面,有以下几个类:

  • AiitListAPIView 列表视图
  • AiitCreateAPIView 创建视图
  • AiitListCreateAPIView 列表和创建视图
  • AiitRetrieveAPIView 详情查看视图
  • AiitRetrieveUpdateAPIView 详情查看和更新视图
  • AiitRetrieveUpdateDestroyAPIView 详情查看、更新和删除视图

算法调用模块

位于 algo 模块下面的 exec_algo() 函数,通过算法名称调用算法,如果一个算法有多个版本,默认调用最后上传的那个版本。

from aiit_sdk.algo import exec_algo


res = exec_algo(algo_name='cv_name_extra', **params)

参数:

  • algo_name:算法名称;
  • params:调用算法的参数,每个算法有所不同。

文件存储

将 settings.py 的 DEFAULT_FILE_STORAGE 参数设置成 aiit_sdk.storage.AiitStorage

DEFAULT_FILE_STORAGE = 'aiit_sdk.storage.AiitStorage'

日志记录模块

位于 log 模块下面,有 create_addition_log()create_change_log()create_delete_log() 3个函数,分别用于记录添加数据更新数据删除数据的操作。

日志会被记录到 django.contrib.admin.models 内的 LogEntry 模块内。

更新流程

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiit_sdk-0.0.12.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

aiit_sdk-0.0.12-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file aiit_sdk-0.0.12.tar.gz.

File metadata

  • Download URL: aiit_sdk-0.0.12.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for aiit_sdk-0.0.12.tar.gz
Algorithm Hash digest
SHA256 f104791a317181829519fd371f85cb79e17599cbd019edd48f135dd70c42e17c
MD5 cb14a31c40f27f295aebf758324f01cf
BLAKE2b-256 64bd8f85d15421253fec2e0cbf9e03f1cc5fc90f00e3daeab11d75de542b5cc9

See more details on using hashes here.

File details

Details for the file aiit_sdk-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: aiit_sdk-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for aiit_sdk-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 80ffe20489606d3e18b99048e22bcc57eb82ef2241f4145e22c755e48f1de8c7
MD5 6814e9023ca33478444987e82c04fe58
BLAKE2b-256 5b2e39590d7f12d490770f86d3905099acfc7b6781fd4d234dcbc5357d1603e4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page