📋 Dress your form processing endpoints. 📋
Introduction
Uniform is a form processing tool that can be easily plugged into your Starlette backend.
It gives you the following:
- Extract and validate form data against
typesystem.Schema
- Return 400 Bad Request with validation problems explained
- 100% test coverage.
- 100% type annotated codebase.
Requirements
Python 3.6+
Installation
$ pip3 install uniform
Example
example.py:
import uvicorn
from starlette.applications import Starlette
from starlette.requests import Request
from starlette.responses import PlainTextResponse
from typesystem import Schema, Boolean
from uniform import Uniform, validate
app = Starlette()
class TestSchema(Schema):
test = Boolean()
@app.route("/")
@validate(Uniform(TestSchema))
async def home(request: Request) -> PlainTextResponse:
return JSONResponse(
content={"ok": True, "description": None, "result": dict(request.state.data)}
)
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8080)
Then run the application...
$ python example.py
Send POST request to http://127.0.0.1:8080/
with application/json
or application/x-www-form-urlencoded
data and it will be validated.
Dependencies
Uniform work with starlette
endpoints and validate forms using typesystem
library.
If you want to parse application/x-www-form-urlencoded
form data - you will also need a python-multipart
.
— 📋 —
Uniform is Unlicensed code in Public Domain.