Skip to main content

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 模块内。

更新流程

Metadata

Release files for aiit-sdk 0.0.12

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

Source distribution (sdist)

Source distribution for aiit-sdk 0.0.12
File Size Uploaded Provenance
aiit_sdk-0.0.12.tar.gz 23.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiit-sdk 0.0.12
File Interpreter ABI Platform
aiit_sdk-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 47.3 kB

Release files / aiit_sdk-0.0.12.tar.gz

Download URL aiit_sdk-0.0.12.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f104791a317181829519fd371f85cb79e17599cbd019edd48f135dd70c42e17c
BLAKE2b-256 checksum
How to use checksums
64bd8f85d15421253fec2e0cbf9e03f1cc5fc90f00e3daeab11d75de542b5cc9
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / aiit_sdk-0.0.12-py3-none-any.whl

Download URL aiit_sdk-0.0.12-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80ffe20489606d3e18b99048e22bcc57eb82ef2241f4145e22c755e48f1de8c7
BLAKE2b-256 checksum
How to use checksums
5b2e39590d7f12d490770f86d3905099acfc7b6781fd4d234dcbc5357d1603e4
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for aiit-sdk 0.0.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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