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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiit_sdk-0.0.9.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.9.tar.gz
Algorithm Hash digest
SHA256 b17448972c9f0acdd9d215c118d6cbaf0f9b643857e1f2c6ab2b2fa102a82bf8
MD5 cf2329d69ee409d5e545bfcccb3ae420
BLAKE2b-256 e6d0bdf3d1f8867a9ea37d8e66d4c87671c0c59db8f1c440b5a30108a2c980ac

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiit_sdk-0.0.9-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.9-py3-none-any.whl
Algorithm Hash digest
SHA256 3cde1028b7d6ec971e08f76430824f96d3aacc04800997ba160a7f26e2d15775
MD5 d331d12469241de96273adace0261040
BLAKE2b-256 d8288d3cf184c44a86247169ea0f12c9b2f527822f0f7267d03e5401eee5fe72

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