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.8.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

aiit_sdk-0.0.8-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiit_sdk-0.0.8.tar.gz
  • Upload date:
  • Size: 23.7 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.8.tar.gz
Algorithm Hash digest
SHA256 b8ffc588e938c441f7db95040ec081e1edaa84ea9275bd3831e3e849407cd6df
MD5 d1c66cfa6b2fcd60afc3d57dbedfb802
BLAKE2b-256 2019b44729098ef1602ffedfb6e5d9aea2bfad1c3ee609226ef8cbc39a4f99f9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiit_sdk-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 23.4 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.8-py3-none-any.whl
Algorithm Hash digest
SHA256 3b56e05348e88089d96ac324edcf757c6e5214063e610be8fcdd892762dea679
MD5 f04d8412ac5eaff90094a458402b799c
BLAKE2b-256 3940a237999ddb27417f2af69dcb5bf5378a43563e7ce35043029b067bd6b8f1

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