Package: rAPIdy
rAPIdy 💮write quickly🚀write beautifully🌸rAPIdyis a minimalistic, asynchronous, fast web framework based in aiohttp and pydantic.pip install rapidyKey Features:✏️ easy to write and read code📔pydanticnative support ->yeswe supportV1️⃣ andV2️⃣❗🚀aiohttpbased and native features support - aiohttp one of the fastest and most productive HTTP servers📤 convenient support for basic types of incoming data extractionQuickstartCreate endpoint using RouteTableDefrAPIdy inherits the basic functionality of aiohttpquickstartfromrapidyimportwebfromtyping_extensionsimportAnnotatedroutes=web.RouteTableDef()@routes.get('/hello')asyncdefhello(request:web.Request,username:Annotated[str,web.JsonBody(min_length=3,max_length=20)],password:Annotated[str,web.JsonBody(min_length=8,max_length=40)],)->web.Response:# write you business code herereturnweb.json_response({'username':username,'password':password})app=web.Application()app.add_routes(routes)if__name__=='__main__':web.run_app(app,port=8000)Create endpoint using web.<method_name>fromrapidyimportwebfromtyping_extensionsimportAnnotatedasyncdefhello(request:web.Request,username:Annotated[str,web.JsonBody(min_length=3,max_length=20)],password:Annotated[str,web.JsonBody(min_length=8,max_length=40)],)->web.Response:# write you business code herereturnweb.json_response({'username':username,'password':password})app=web.Application()app.add_routes([web.post('/hello',hello)])if__name__=='__main__':web.run_app(app,port=8000)Create endpoint using web.viewfromrapidyimportwebfromtyping_extensionsimportAnnotatedclassHandler(web.View):asyncdefpost(self,username:Annotated[str,web.JsonBody(min_length=3,max_length=20)],password:Annotated[str,web.JsonBody(min_length=8,max_length=40)],)->web.Response:# write you business code herereturnweb.json_response({'username':username,'password':password})app=web.Application()app.add_routes([web.view('/hello',Handler)])if__name__=='__main__':web.run_app(app,port=8000)Pydantic native supportfromrapidyimportwebfromtyping_extensionsimportAnnotatedasyncdefhello_handler(request:web.Request,username:Annotated[str,web.JsonBody(min_length=3,max_length=20)],password:Annotated[str,web.JsonBody(min_length=8,max_length=40)],)->web.Response:# write you business code herereturnweb.json_response({'username':username,'password':password})app=web.Application()app.add_routes([web.post('/hello',hello_handler)])web.run_app(app,port=8000)✅✅✅ Success request validation ✅✅✅curl -X POST \
-H "Content-Type: application/json" -d '{"username": "Max", "password": "myAwesomePass"}' -v \
http://127.0.0.1:8000/hello

< HTTP/1.1 200 OK ... {"username": "Max", "password": "myAwesomePass"}❌❌❌ Request validation failure ❌❌❌curl -X POST \
-H "Content-Type: application/json" -d '{"username": "M", "password": "m"}' -v \
http://127.0.0.1:8000/hello

< HTTP/1.1 422 Unprocessable Entity ...
{
    "errors": [
        {
            "loc": ["body", "username"],
            "type": "string_too_short",
            "msg": "String should have at least 3 characters",
            "ctx": {"min_length": 3}
        },
        {
            "type": "string_too_short",
            "loc": ["body", "password"],
            "msg": "String should have at least 8 characters",
            "ctx": {"min_length": 8}
        }
    ]
}Choose your pathYou can create APIs the way you want.rAPIdysupports 3 basic types for defining incoming parameters🌒 paramPathHeaderCookieQueryBodyJsonFormDataBodyMultipartBody🌕 schemaPathSchemaHeaderSchemaCookieSchemaQuerySchemaBodyJsonSchemaFormDataBodySchemaMultipartBodySchema🌑 raw data (no validate with pydantic)PathRaw -Dict[str, str]HeaderRaw -Dict[str, str]CookieRaw -Dict[str, str]QueryRaw -Dict[str, str]BodyJsonRaw -Dict[str, Any]FormDataBodyRaw -Dict[str, Any]MultipartBodyRaw -Dict[str, Any]TextBody -strBytesBody -bytesStreamBody -aiohttp.streams.StreamReader# defining request attributes as param 🌒fromrapidyimportwebfromtyping_extensionsimportAnnotatedasyncdefhello_handler(request:web.Request,# path paramspath_param:Annotated[str,web.Path],# headershost:Annotated[str,web.Header(alias='Host')],user_agent:Annotated[str,web.Header(alias='User-Agent')],# cookieuser_cookie1:Annotated[str,web.Cookie(alias='UserCookie1')],user_cookie2:Annotated[str,web.Cookie(alias='UserCookie2')],# query paramsuser_param1:Annotated[str,web.Query(alias='UserQueryParam1')],user_param2:Annotated[str,web.Cookie(alias='UserQueryParam2')],# bodyusername:Annotated[str,web.JsonBody(min_length=3,max_length=20)],password:Annotated[str,web.JsonBody(min_length=8,max_length=40)],)->web.Response:# write you business code here# ...returnweb.Response()app=web.Application()app.add_routes([web.post('/hello/{path_param}',hello_handler)])# defining request attributes as schema 🌕frompydanticimportBaseModel,FieldclassPathRequestSchema(BaseModel):path_param:strclassHeaderRequestSchema(BaseModel):host:str=Field(alias='Host')user_agent:str=Field(alias='User-Agent')classCookieRequestSchema(BaseModel):user_cookie1:str=Field(alias='UserCookie1')user_cookie2:str=Field(alias='UserCookie2')classQueryRequestSchema(BaseModel):user_cookie1:str=Field(alias='UserQueryParam1')user_cookie2:str=Field(alias='UserQueryParam1')classBodyRequestSchema(BaseModel):username:str=Field(min_length=3,max_length=20)password:str=Field(min_length=8,max_length=40)asyncdefhello_handler(request:web.Request,path:Annotated[PathRequestSchema,web.PathSchema],headers:Annotated[HeaderRequestSchema,web.HeaderSchema],cookies:Annotated[CookieRequestSchema,web.Cookie],query:Annotated[QueryRequestSchema,web.QuerySchema],body:Annotated[BodyRequestSchema,web.JsonBodySchema],)->web.Response:# defining request attributes as raw 🌑asyncdefhello_handler(request:web.Request,path:Annotated[Dict[str,str],web.PathRaw],headers:Annotated[Dict[str,str],web.HeaderRaw],cookies:Annotated[Dict[str,str],web.CookieRaw],query:Annotated[Dict[str,str],web.QueryRaw],body:Annotated[Dict[str,Any],web.JsonBodyRaw],)->web.Response:# also you may to combine 🌒 🌕 🌑asyncdefhello_handler(request:web.Request,path_param:Annotated[str,web.Path],headers:Annotated[Dict[str,str],web.HeaderRaw],body:Annotated[BodyRequestSchema,web.JsonBodySchema],)->web.Response: