Skip to main content

A request parameter checking and parsing library based on pydantic under the sanic framework

Project description

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

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

sanic-dantic-1.1.6.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

sanic_dantic-1.1.6-py3.8.egg (11.6 kB view details)

Uploaded Source

File details

Details for the file sanic-dantic-1.1.6.tar.gz.

File metadata

  • Download URL: sanic-dantic-1.1.6.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.2

File hashes

Hashes for sanic-dantic-1.1.6.tar.gz
Algorithm Hash digest
SHA256 128c8c63246e1ffab4bb16920961c7162a6d3156294f738d9d72cfdab616b5f5
MD5 7b6836f27fa9f49682d79da22556df35
BLAKE2b-256 f5d3488efbba9888e370179c1e7fa9f107b360002055f86385d4c30c20cee214

See more details on using hashes here.

File details

Details for the file sanic_dantic-1.1.6-py3.8.egg.

File metadata

  • Download URL: sanic_dantic-1.1.6-py3.8.egg
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.2

File hashes

Hashes for sanic_dantic-1.1.6-py3.8.egg
Algorithm Hash digest
SHA256 be8695858f291b86f211dbae354d9483d683b31432bac5883dd22e7e235eaad1
MD5 2afb7eb767388a7bd992a11671dbb14c
BLAKE2b-256 a3360a234e617ad23975a09742c800d9aae2e2b55fdd76d662355e42634844cc

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