Skip to main content

sanic-dantic

Travis (.com) Codecov Downloads PyPI - Python Version PyPI PyPI - License Docs

sanic-dantic is a request parameter checking and parsing library based on pydantic under the sanic framework

sanic-dantic is a request parameter checking and parsing library based on pydantic under the sanic framework

It is based on pydantic, which can facilitate developers to quickly check and obtain request parameters

Documentation

If you want more usage, please click here

Installation

pip install sanic-dantic

Why use it

Do you have to get the request parameters first every time you process them ?

from sanic import Sanic
from sanic.response import json

app = Sanic("SanicDanticExample")


@app.route('/example')
async def path_param_examples(request):
    name = request.get("name")
    age = request.get("age")
    if not isinstance(name, str) or not isinstance(age, int):
        return json({"error": "parameter type error"})
    return json({"message": f"hello {name} are you {age} years old ?"})

How terrible, and there is no good experience for developers at all.

Therefore, sanic-dantic is to help you improve your development efficiency and experience.

It allows you to skip the process of type checking and parameter acquisition.

How to use

It is based on pydantic, which can facilitate developers to quickly check and obtain request parameters

In sanic-dantic, you can pass the pydantic model to different formal parameters in parse_params to check and parse the values of different types of request parameters

You can get all the parsed parameters by appending the formal parameter , and get the value of the parameter through the attribute params

from sanic import Sanic
from sanic.response import json

from sanic_dantic import parse_params, BaseModel


class Person(BaseModel):
    name: str
    age: int


app = Sanic("SanicDanticExample")


@app.route('/example')
@parse_params(path=Person)
async def path_param_examples(request, params):
    print(params.ctx.name, params.ctx.age)
    return json(
        {"message": f"hello {params.name} are you {params.age} years old ?"})

Do you have a crush? Come and experience it!

more usage please read the documentation

Metadata

Release files for sanic-dantic 1.2.2

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

Source distribution (sdist)

Source distribution for sanic-dantic 1.2.2
File Size Uploaded Provenance Actions
sanic-dantic-1.2.2.tar.gz 6.1 kB Without provenance Details for sanic-dantic-1.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sanic-dantic 1.2.2
File Interpreter ABI Platform Actions
sanic_dantic-1.2.2-py3-none-any.whl Python 3 none any Details for sanic_dantic-1.2.2-py3-none-any.whl

Total release size: 13.0 kB

Release files / sanic-dantic-1.2.2.tar.gz

Download URL sanic-dantic-1.2.2.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5a527baf2b2e86a885236912756a73f9dd21e5d72d65c8322f25f95d2a36a868
BLAKE2b-256 checksum
How to use checksums
0e458e527f075f2ff923dde29917d3a2f0a7eedfe669fa978bb7648b8807f468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Release files / sanic_dantic-1.2.2-py3-none-any.whl

Download URL sanic_dantic-1.2.2-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
850568f8c046ec6643e96aa7152ae46fafe225f3a969aa1e2e4702a52ec26db5
BLAKE2b-256 checksum
How to use checksums
0b48526cca2369ff566aab69a881d214b30d9a40e95cf5f3dfce8b156c605b09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.8

Security for sanic-dantic 1.2.2

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