Skip to main content

基于 Sanic 的类型化表单验证后端脚手架

Project description

iSanic-e

基于 Sanic 的类型化表单验证后端脚手架。

安装后可以通过 isanic init 快速生成一个完整可运行的 Sanic 项目,内置:

  • 控制器自动路由注册
  • Pydantic v2 表单验证
  • 统一成功和错误响应
  • 全局异常处理
  • 示例控制器、表单模型和测试

安装

python -m pip install isanic-e

初始化项目

isanic init demo
cd demo
python -m pip install -e ".[dev]"
python -m pytest
python -m app.main

控制器示例

from app.api.schemas.login import LoginForm
from isanic import ApiController


class Login(ApiController):
    async def post_submit(self, form: LoginForm) -> dict[str, str]:
        return {"token": f"token-for-{form.username}"}

上面的代码会自动注册为:

POST /login/submit

业务异常

from isanic import AppError

raise AppError("用户已被禁用", code="USER_DISABLED", status_code=403)

返回:

{
  "code": "USER_DISABLED",
  "message": "用户已被禁用",
  "data": null
}

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

isanic_e-0.1.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

isanic_e-0.1.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file isanic_e-0.1.0.tar.gz.

File metadata

  • Download URL: isanic_e-0.1.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for isanic_e-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d860089bfc638b505312d12ea98f4c56b8859d581fc22e6c86b2876e4c6ad799
MD5 53864adca5a4755eee300e20bd87b69c
BLAKE2b-256 aacf2636f42cc97a66b0efe047be0799264e6801fdbe6e8aeed5ca9a2cafaf5b

See more details on using hashes here.

File details

Details for the file isanic_e-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: isanic_e-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for isanic_e-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 496b5f9aa34c3c0e6032ab4ab789a9cdda5e8e4f5c27d1a3cb55a991906563e5
MD5 7ec37bee65cc4f75e08e3744b2e146f4
BLAKE2b-256 1d277ca5f6d768952a95847340cf9c5edc4601b32a323a224aab0d1ab8a9cd71

See more details on using hashes here.

Supported by

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