fastapi app class the main entrypoint to use fastapi read more in the fastapi docs for first stepshttps fastapi tiangolo comtutorialfirststeps example python from fastapi import fastapi app fastapi boolean indicating if debug tracebacks should be returned on server errors read more in the starlette docs for applicationshttps www starlette ioapplicationsinstantiatingtheapplication note you probably shouldn t use this parameter it is inherited from starlette and supported for compatibility a list of routes to serve incoming http and websocket requests you normally wouldn t use this parameter with fastapi it is inherited from starlette and supported for compatibility in fastapi you normally would use the path operation methods like app get app post etc the title of the api it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urlshttps fastapi tiangolo comtutorialmetadatametadataforapi example python from fastapi import fastapi app fastapititlechimichangapp a short summary of the api it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urlshttps fastapi tiangolo comtutorialmetadatametadataforapi example python from fastapi import fastapi app fastapisummarydeadpond s favorite app nuff said a description of the api supports markdown using commonmark syntaxhttps commonmark org it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urlshttps fastapi tiangolo comtutorialmetadatametadataforapi example python from fastapi import fastapi app fastapi description chimichangapp api helps you do awesome stuff items you can read items users you will be able to create users not implemented read users not implemented version annotated str doc 0 1 0 openapiurl annotated optionalstr doc openapi json openapitags annotated optionallistdictstr any doc none servers annotated optionallistdictstr unionstr any doc none dependencies annotated optionalsequencedepends doc none defaultresponseclass annotated typeresponse doc defaultjsonresponse redirectslashes annotated bool doc true docsurl annotated optionalstr doc docs redocurl annotated optionalstr doc redoc swaggeruioauth2redirecturl annotated optionalstr doc docsoauth2redirect swaggeruiinitoauth annotated optionaldictstr any doc none middleware annotated optionalsequencemiddleware doc none exceptionhandlers annotated optional dict unionint typeexception callablerequest any coroutineany any response doc none onstartup annotated optionalsequencecallable any doc none onshutdown annotated optionalsequencecallable any doc none lifespan annotated optionallifespanapptype doc none termsofservice annotated optionalstr doc none contact annotated optionaldictstr unionstr any doc none licenseinfo annotated optionaldictstr unionstr any doc none openapiprefix annotated str doc deprecated rootpath annotated str doc rootpathinservers annotated bool doc true responses annotated optionaldictunionint str dictstr any doc none callbacks annotated optionallistbaseroute doc none webhooks annotated optionalrouting apirouter doc none deprecated annotated optionalbool doc none includeinschema annotated bool doc true swaggeruiparameters annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid separateinputoutputschemas annotated bool doc true extra annotated any doc none self debug debug self title title self summary summary self description description self version version self termsofservice termsofservice self contact contact self licenseinfo licenseinfo self openapiurl openapiurl self openapitags openapitags self rootpathinservers rootpathinservers self docsurl docsurl self redocurl redocurl self swaggeruioauth2redirecturl swaggeruioauth2redirecturl self swaggeruiinitoauth swaggeruiinitoauth self swaggeruiparameters swaggeruiparameters self servers servers or self separateinputoutputschemas separateinputoutputschemas self extra extra self openapiversion annotated str doc 3 1 0 self openapischema optionaldictstr any none if self openapiurl assert self title a title must be provided for openapi e g my api assert self version a version must be provided for openapi e g 2 1 0 todo remove when discarding the openapiprefix parameter if openapiprefix logger warning openapiprefix has been deprecated in favor of rootpath which follows more closely the asgi standard is simpler and more automatic check the docs at https fastapi tiangolo comadvancedsubapplications self webhooks annotated routing apirouter doc webhooks or routing apirouter self rootpath rootpath or openapiprefix self state annotated state doc state self dependencyoverrides annotated dictcallable any callable any doc self router routing apirouter routing apirouter routesroutes redirectslashesredirectslashes dependencyoverridesproviderself onstartuponstartup onshutdownonshutdown lifespanlifespan defaultresponseclassdefaultresponseclass dependenciesdependencies callbackscallbacks deprecateddeprecated includeinschemaincludeinschema responsesresponses generateuniqueidfunctiongenerateuniqueidfunction self exceptionhandlers dict any callablerequest any unionresponse awaitableresponse if exceptionhandlers is none else dictexceptionhandlers self exceptionhandlers setdefaulthttpexception httpexceptionhandler self exceptionhandlers setdefault requestvalidationerror requestvalidationexceptionhandler self exceptionhandlers setdefault websocketrequestvalidationerror starlette still has incorrect type specification for the handlers websocketrequestvalidationexceptionhandler type ignore self usermiddleware listmiddleware if middleware is none else listmiddleware self middlewarestack unionasgiapp none none self setup def buildmiddlewarestackself asgiapp duplicateoverride from starlette to add asyncexitstackmiddleware inside of exceptionmiddleware inside of custom user middlewares debug self debug errorhandler none exceptionhandlers for key value in self exceptionhandlers items if key in 500 exception errorhandler value else exceptionhandlerskey value middleware middlewareservererrormiddleware handlererrorhandler debugdebug self usermiddleware middleware exceptionmiddleware handlersexceptionhandlers debugdebug add fastapispecific asyncexitstackmiddleware for dependencies with contextvars this needs to happen after user middlewares because those create a new contextvars context copy by using a new anyio task group the initial part of dependencies with yield is executed in the fastapi code inside all the middlewares however the teardown part after yield is executed in the asyncexitstack in this middleware if the asyncexitstack lived outside of the custom middlewares and contextvars were set in a dependency with yield in that internal contextvars context the values would not be available in the outer context of the asyncexitstack by placing the middleware and the asyncexitstack here inside all user middlewares the code before and after yield in dependencies with yield is executed in the same contextvars context thus all values set in contextvars before yield are still available after yield as expected additionally by having this asyncexitstack here after the exceptionmiddleware dependencies can now catch handled exceptions e g httpexception to customize the teardown code e g db session rollback middlewareasyncexitstackmiddleware app self router for cls options in reversedmiddleware app clsappapp options return app def openapiself dictstr any if not self openapischema self openapischema getopenapi titleself title versionself version openapiversionself openapiversion summaryself summary descriptionself description termsofserviceself termsofservice contactself contact licenseinfoself licenseinfo routesself routes webhooksself webhooks routes tagsself openapitags serversself servers separateinputoutputschemasself separateinputoutputschemas return self openapischema def setupself none if self openapiurl urls serverdata geturl for serverdata in self servers serverurls url for url in urls if url async def openapireq request jsonresponse rootpath req scope getrootpath rstrip if rootpath not in serverurls if rootpath and self rootpathinservers self servers insert0 url rootpath serverurls addrootpath return jsonresponseself openapi self addrouteself openapiurl openapi includeinschemafalse if self openapiurl and self docsurl async def swaggeruihtmlreq request htmlresponse rootpath req scope getrootpath rstrip openapiurl rootpath self openapiurl oauth2redirecturl self swaggeruioauth2redirecturl if oauth2redirecturl oauth2redirecturl rootpath oauth2redirecturl return getswaggeruihtml openapiurlopenapiurl titleself title swagger ui oauth2redirecturloauth2redirecturl initoauthself swaggeruiinitoauth swaggeruiparametersself swaggeruiparameters self addrouteself docsurl swaggeruihtml includeinschemafalse if self swaggeruioauth2redirecturl async def swaggeruiredirectreq request htmlresponse return getswaggeruioauth2redirecthtml self addroute self swaggeruioauth2redirecturl swaggeruiredirect includeinschemafalse if self openapiurl and self redocurl async def redochtmlreq request htmlresponse rootpath req scope getrootpath rstrip openapiurl rootpath self openapiurl return getredochtml openapiurlopenapiurl titleself title redoc self addrouteself redocurl redochtml includeinschemafalse async def callself scope scope receive receive send send none if self rootpath scoperootpath self rootpath await super callscope receive send def addapiroute self path str endpoint callable coroutineany any response responsemodel any defaultnone statuscode optionalint none tags optionallistunionstr enum none dependencies optionalsequencedepends none summary optionalstr none description optionalstr none responsedescription str successful response responses optionaldictunionint str dictstr any none deprecated optionalbool none methods optionalliststr none operationid optionalstr none responsemodelinclude optionalincex none responsemodelexclude optionalincex none responsemodelbyalias bool true responsemodelexcludeunset bool false responsemodelexcludedefaults bool false responsemodelexcludenone bool false includeinschema bool true responseclass uniontyperesponse defaultplaceholder default jsonresponse name optionalstr none openapiextra optionaldictstr any none generateuniqueidfunction callablerouting apiroute str default generateuniqueid none self router addapiroute path endpointendpoint responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated methodsmethods operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def apiroute self path str responsemodel any defaultnone statuscode optionalint none tags optionallistunionstr enum none dependencies optionalsequencedepends none summary optionalstr none description optionalstr none responsedescription str successful response responses optionaldictunionint str dictstr any none deprecated optionalbool none methods optionalliststr none operationid optionalstr none responsemodelinclude optionalincex none responsemodelexclude optionalincex none responsemodelbyalias bool true responsemodelexcludeunset bool false responsemodelexcludedefaults bool false responsemodelexcludenone bool false includeinschema bool true responseclass typeresponse defaultjsonresponse name optionalstr none openapiextra optionaldictstr any none generateuniqueidfunction callablerouting apiroute str default generateuniqueid callabledecoratedcallable decoratedcallable def decoratorfunc decoratedcallable decoratedcallable self router addapiroute path func responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated methodsmethods operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction return func return decorator def addapiwebsocketroute self path str endpoint callable any name optionalstr none dependencies optionalsequencedepends none none self router addapiwebsocketroute path endpoint namename dependenciesdependencies def websocket self path annotated str doc name annotated optionalstr doc none dependencies annotated optionalsequencedepends doc none callabledecoratedcallable decoratedcallable def decoratorfunc decoratedcallable decoratedcallable self addapiwebsocketroute path func namename dependenciesdependencies return func return decorator def includerouter self router annotatedrouting apirouter docthe apirouter to include prefix annotatedstr docan optional path prefix for the router tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none includeinschema annotated bool doc true defaultresponseclass annotated typeresponse doc defaultjsonresponse callbacks annotated optionallistbaseroute doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid none example self router includerouter router prefixprefix tagstags dependenciesdependencies responsesresponses deprecateddeprecated includeinschemaincludeinschema defaultresponseclassdefaultresponseclass callbackscallbacks generateuniqueidfunctiongenerateuniqueidfunction def get self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router get path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def put self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router put path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def post self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router post path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def delete self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router delete path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def options self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router options path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def head self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router head path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def patch self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router patch path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def trace self path annotated str doc responsemodel annotated any doc defaultnone statuscode annotated optionalint doc none tags annotated optionallistunionstr enum doc none dependencies annotated optionalsequencedepends doc none summary annotated optionalstr doc none description annotated optionalstr doc none responsedescription annotated str doc successful response responses annotated optionaldictunionint str dictstr any doc none deprecated annotated optionalbool doc none operationid annotated optionalstr doc none responsemodelinclude annotated optionalincex doc none responsemodelexclude annotated optionalincex doc none responsemodelbyalias annotated bool doc true responsemodelexcludeunset annotated bool doc false responsemodelexcludedefaults annotated bool doc false responsemodelexcludenone annotated bool doc false includeinschema annotated bool doc true responseclass annotated typeresponse doc defaultjsonresponse name annotated optionalstr doc none callbacks annotated optionallistbaseroute doc none openapiextra annotated optionaldictstr any doc none generateuniqueidfunction annotated callablerouting apiroute str doc defaultgenerateuniqueid callabledecoratedcallable decoratedcallable example return self router trace path responsemodelresponsemodel statuscodestatuscode tagstags dependenciesdependencies summarysummary descriptiondescription responsedescriptionresponsedescription responsesresponses deprecateddeprecated operationidoperationid responsemodelincluderesponsemodelinclude responsemodelexcluderesponsemodelexclude responsemodelbyaliasresponsemodelbyalias responsemodelexcludeunsetresponsemodelexcludeunset responsemodelexcludedefaultsresponsemodelexcludedefaults responsemodelexcludenoneresponsemodelexcludenone includeinschemaincludeinschema responseclassresponseclass namename callbackscallbacks openapiextraopenapiextra generateuniqueidfunctiongenerateuniqueidfunction def websocketroute self path str name unionstr none none callabledecoratedcallable decoratedcallable def decoratorfunc decoratedcallable decoratedcallable self router addwebsocketroutepath func namename return func return decorator deprecated def onevent self eventtype annotated str doc callabledecoratedcallable decoratedcallable return self router oneventeventtype def middleware self middlewaretype annotated str doc callabledecoratedcallable decoratedcallable example def decoratorfunc decoratedcallable decoratedcallable self addmiddlewarebasehttpmiddleware dispatchfunc return func return decorator def exceptionhandler self excclassorstatuscode annotated unionint typeexception doc callabledecoratedcallable decoratedcallable example def decoratorfunc decoratedcallable decoratedcallable self addexceptionhandlerexcclassorstatuscode func return func return decorator type ignore attr defined fastapi app class the main entrypoint to use fastapi read more in the fastapi docs for first steps https fastapi tiangolo com tutorial first steps example python from fastapi import fastapi app fastapi boolean indicating if debug tracebacks should be returned on server errors read more in the starlette docs for applications https www starlette io applications instantiating the application note you probably shouldn t use this parameter it is inherited from starlette and supported for compatibility a list of routes to serve incoming http and websocket requests you normally wouldn t use this parameter with fastapi it is inherited from starlette and supported for compatibility in fastapi you normally would use the path operation methods like app get app post etc the title of the api it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python from fastapi import fastapi app fastapi title chimichangapp a short summary of the api it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python from fastapi import fastapi app fastapi summary deadpond s favorite app nuff said a description of the api supports markdown using commonmark syntax https commonmark org it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python from fastapi import fastapi app fastapi description chimichangapp api helps you do awesome stuff items you can read items users you will be able to create users _not implemented_ read users _not implemented_ the version of the api note this is the version of your application not the version of the openapi specification nor the version of fastapi being used it will be added to the generated openapi e g visible at docs read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python from fastapi import fastapi app fastapi version 0 0 1 the url where the openapi schema will be served from if you set it to none no openapi schema will be served publicly and the default automatic endpoints docs and redoc will also be disabled read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata openapi url example python from fastapi import fastapi app fastapi openapi_url api v1 openapi json a list of tags used by openapi these are the same tags you can set in the path operations like app get users tags users app get items tags items the order of the tags can be used to specify the order shown in tools like swagger ui used in the automatic path docs it s not required to specify all the tags used the tags that are not declared may be organized randomly or based on the tools logic each tag name in the list must be unique the value of each item is a dict containing name the name of the tag description a short description of the tag commonmark syntax https commonmark org may be used for rich text representation externaldocs additional external documentation for this tag if provided it would contain a dict with description a short description of the target documentation commonmark syntax https commonmark org may be used for rich text representation url the url for the target documentation value must be in the form of a url read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for tags example python from fastapi import fastapi tags_metadata name users description operations with users the login logic is also here name items description manage items so _fancy_ they have their own docs externaldocs description items external docs url https fastapi tiangolo com app fastapi openapi_tags tags_metadata a list of dict s with connectivity information to a target server you would use it for example if your application is served from different domains and you want to use the same swagger ui in the browser to interact with each of them instead of having multiple browser tabs open or if you want to leave fixed the possible urls if the servers list is not provided or is an empty list the default value would be a a dict with a url value of each item in the list is a dict containing url a url to the target host this url supports server variables and may be relative to indicate that the host location is relative to the location where the openapi document is being served variable substitutions will be made when a variable is named in brackets description an optional string describing the host designated by the url commonmark syntax https commonmark org may be used for rich text representation variables a dict between a variable name and its value the value is used for substitution in the server s url template read more in the fastapi docs for behind a proxy https fastapi tiangolo com advanced behind a proxy additional servers example python from fastapi import fastapi app fastapi servers url https stag example com description staging environment url https prod example com description production environment a list of global dependencies they will be applied to each path operation including in sub routers read more about it in the fastapi docs for global dependencies https fastapi tiangolo com tutorial dependencies global dependencies example python from fastapi import depends fastapi from dependencies import func_dep_1 func_dep_2 app fastapi dependencies depends func_dep_1 depends func_dep_2 the default response class to be used read more in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response default response class example python from fastapi import fastapi from fastapi responses import orjsonresponse app fastapi default_response_class orjsonresponse whether to detect and redirect slashes in urls when the client doesn t use the same format example python from fastapi import fastapi app fastapi redirect_slashes true the default app get items async def read_items return item_id foo with this app if a client goes to items without a trailing slash they will be automatically redirected with an http status code of 307 to items the path to the automatic interactive api documentation it is handled in the browser by swagger ui the default url is docs you can disable it by setting it to none if openapi_url is set to none this will be automatically disabled read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata docs urls example python from fastapi import fastapi app fastapi docs_url documentation redoc_url none the path to the alternative automatic interactive api documentation provided by redoc the default url is redoc you can disable it by setting it to none if openapi_url is set to none this will be automatically disabled read more in the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata docs urls example python from fastapi import fastapi app fastapi docs_url documentation redoc_url redocumentation the oauth2 redirect endpoint for the swagger ui by default it is docs oauth2 redirect this is only used if you use oauth2 with the ize button with swagger ui oauth2 configuration for the swagger ui by default shown at docs read more about the available configuration options in the swagger ui docs https swagger io docs open source tools swagger ui usage oauth2 list of middleware to be added when creating the application in fastapi you would normally do this with app add_middleware instead read more in the fastapi docs for middleware https fastapi tiangolo com tutorial middleware a dictionary with handlers for exceptions in fastapi you would normally use the decorator app exception_handler read more in the fastapi docs for handling errors https fastapi tiangolo com tutorial handling errors a list of startup event handler functions you should instead use the lifespan handlers read more in the fastapi docs for lifespan https fastapi tiangolo com advanced events a list of shutdown event handler functions you should instead use the lifespan handlers read more in the fastapi docs for lifespan https fastapi tiangolo com advanced events a lifespan context manager handler this replaces startup and shutdown functions with a single context manager read more in the fastapi docs for lifespan https fastapi tiangolo com advanced events a url to the terms of service for your api it will be added to the generated openapi e g visible at docs read more at the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python app fastapi terms_of_service http example com terms a dictionary with the contact information for the exposed api it can contain several fields name str the name of the contact person organization url str a url pointing to the contact information must be in the format of a url email str the email address of the contact person organization must be in the format of an email address it will be added to the generated openapi e g visible at docs read more at the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python app fastapi contact name deadpoolio the amazing url http x force example com contact email dp x force example com a dictionary with the license information for the exposed api it can contain several fields name str required if a license_info is set the license name used for the api identifier str an spdx https spdx dev license expression for the api the identifier field is mutually exclusive of the url field available since openapi 3 1 0 fastapi 0 99 0 url str a url to the license used for the api this must be the format of a url it will be added to the generated openapi e g visible at docs read more at the fastapi docs for metadata and docs urls https fastapi tiangolo com tutorial metadata metadata for api example python app fastapi license_info name apache 2 0 url https www apache org licenses license 2 0 html a url prefix for the openapi url openapi_prefix has been deprecated in favor of root_path which follows more closely the asgi standard is simpler and more automatic a path prefix handled by a proxy that is not seen by the application but is seen by external clients which affects things like swagger ui read more about it at the fastapi docs for behind a proxy https fastapi tiangolo com advanced behind a proxy example python from fastapi import fastapi app fastapi root_path api v1 to disable automatically generating the urls in the servers field in the autogenerated openapi using the root_path read more about it in the fastapi docs for behind a proxy https fastapi tiangolo com advanced behind a proxy disable automatic server from root_path example python from fastapi import fastapi app fastapi root_path_in_servers false additional responses to be shown in openapi it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for additional responses in openapi https fastapi tiangolo com advanced additional responses and in the fastapi docs for bigger applications https fastapi tiangolo com tutorial bigger applications include an apirouter with a custom prefix tags responses and dependencies openapi callbacks that should apply to all path operations it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks add openapi webhooks this is similar to callbacks but it doesn t depend on specific path operations it will be added to the generated openapi e g visible at docs note this is available since openapi 3 1 0 fastapi 0 99 0 read more about it in the fastapi docs for openapi webhooks https fastapi tiangolo com advanced openapi webhooks mark all path operations as deprecated you probably don t need it but it s available it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration to include or not all the path operations in the generated openapi you probably don t need it but it s available this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi parameters to configure swagger ui the autogenerated interactive api documentation by default at docs read more about it in the fastapi docs about how to configure swagger ui https fastapi tiangolo com how to configure swagger ui customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function whether to generate separate openapi schemas for request body and response body when the results would be more precise this is particularly useful when automatically generating clients for example if you have a model like python from pydantic import basemodel class item basemodel name str tags list str when item is used for input a request body tags is not required the client doesn t have to provide it but when using item for output for a response body tags is always available because it has a default value even if it s just an empty list so the client should be able to always expect it in this case there would be two different schemas one for input and another one for output extra keyword arguments to be stored in the app not used by fastapi anywhere the version string of openapi fastapi will generate openapi version 3 1 0 and will output that as the openapi version but some tools even though they might be compatible with openapi 3 1 0 might not recognize it as a valid so you could override this value to trick those tools into using the generated openapi have in mind that this is a hack but if you avoid using features added in openapi 3 1 0 it might work for your use case this is not passed as a parameter to the fastapi class to avoid giving the false idea that fastapi would generate a different openapi schema it is only available as an attribute example python from fastapi import fastapi app fastapi app openapi_version 3 0 2 todo remove when discarding the openapi_prefix parameter the app webhooks attribute is an apirouter with the path operations that will be used just for documentation of webhooks read more about it in the fastapi docs for openapi webhooks https fastapi tiangolo com advanced openapi webhooks a state object for the application this is the same object for the entire application it doesn t change from request to request you normally woudln t use this in fastapi for most of the cases you would instead use fastapi dependencies this is simply inherited from starlette read more about it in the starlette docs for applications https www starlette io applications storing state on the app instance a dictionary with overrides for the dependencies each key is the original dependency callable and the value is the actual dependency that should be called this is for testing to replace expensive dependencies with testing versions read more about it in the fastapi docs for testing dependencies with overrides https fastapi tiangolo com advanced testing dependencies starlette still has incorrect type specification for the handlers type ignore duplicate override from starlette to add asyncexitstackmiddleware inside of exceptionmiddleware inside of custom user middlewares add fastapi specific asyncexitstackmiddleware for dependencies with contextvars this needs to happen after user middlewares because those create a new contextvars context copy by using a new anyio task group the initial part of dependencies with yield is executed in the fastapi code inside all the middlewares however the teardown part after yield is executed in the asyncexitstack in this middleware if the asyncexitstack lived outside of the custom middlewares and contextvars were set in a dependency with yield in that internal contextvars context the values would not be available in the outer context of the asyncexitstack by placing the middleware and the asyncexitstack here inside all user middlewares the code before and after yield in dependencies with yield is executed in the same contextvars context thus all values set in contextvars before yield are still available after yield as expected additionally by having this asyncexitstack here after the exceptionmiddleware dependencies can now catch handled exceptions e g httpexception to customize the teardown code e g db session rollback generate the openapi schema of the application this is called by fastapi internally the first time it is called it stores the result in the attribute app openapi_schema and next times it is called it just returns that same result to avoid the cost of generating the schema every time if you need to modify the generated openapi schema you could modify it read more in the fastapi docs for openapi https fastapi tiangolo com how to extending openapi websocket path a name for the websocket only used internally a list of dependencies using depends to be used for this websocket read more about it in the fastapi docs for websockets https fastapi tiangolo com advanced websockets decorate a websocket function read more about it in the fastapi docs for websockets https fastapi tiangolo com advanced websockets example python from fastapi import fastapi websocket app fastapi app websocket ws async def websocket_endpoint websocket websocket await websocket accept while true data await websocket receive_text await websocket send_text f message text was data a list of tags to be applied to all the path operations in this router it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a list of dependencies using depends to be applied to all the path operations in this router read more about it in the fastapi docs for bigger applications multiple files https fastapi tiangolo com tutorial bigger applications include an apirouter with a custom prefix tags responses and dependencies example python from fastapi import depends fastapi from dependencies import get_token_header from internal import admin app fastapi app include_router admin router dependencies depends get_token_header additional responses to be shown in openapi it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for additional responses in openapi https fastapi tiangolo com advanced additional responses and in the fastapi docs for bigger applications https fastapi tiangolo com tutorial bigger applications include an apirouter with a custom prefix tags responses and dependencies mark all the path operations in this router as deprecated it will be added to the generated openapi e g visible at docs example python from fastapi import fastapi from internal import old_api app fastapi app include_router old_api router deprecated true include or not all the path operations in this router in the generated openapi schema this affects the generated openapi e g visible at docs example python from fastapi import fastapi from internal import old_api app fastapi app include_router old_api router include_in_schema false default response class to be used for the path operations in this router read more in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response default response class example python from fastapi import fastapi from fastapi responses import orjsonresponse from internal import old_api app fastapi app include_router old_api router default_response_class orjsonresponse list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function include an apirouter in the same app read more about it in the fastapi docs for bigger applications https fastapi tiangolo com tutorial bigger applications example python from fastapi import fastapi from users import users_router app fastapi app include_router users_router the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http get operation example python from fastapi import fastapi app fastapi app get items def read_items return name empanada name arepa the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http put operation example python from fastapi import fastapi from pydantic import basemodel class item basemodel name str description str none none app fastapi app put items item_id def replace_item item_id str item item return message item replaced id item_id the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http post operation example python from fastapi import fastapi from pydantic import basemodel class item basemodel name str description str none none app fastapi app post items def create_item item item return message item created the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http delete operation example python from fastapi import fastapi app fastapi app delete items item_id def delete_item item_id str return message item deleted the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http options operation example python from fastapi import fastapi app fastapi app options items def get_item_options return additions aji guacamole the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http head operation example python from fastapi import fastapi response app fastapi app head items status_code 204 def get_items_headers response response response headers x cat dog alone in the world the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http patch operation example python from fastapi import fastapi from pydantic import basemodel class item basemodel name str description str none none app fastapi app patch items def update_item item item return message item updated in place the url path to be used for this path operation for example in http example com items the path is items the type to use for the response it could be any valid pydantic field type so it doesn t have to be a pydantic model it could be other things like a list dict etc it will be used for documentation the generated openapi and the ui at docs will show it as the response json schema serialization you could return an arbitrary object and the response_model would be used to serialize that object into the corresponding json filtering the json sent to the client will only contain the data fields defined in the response_model if you returned an object that contains an attribute password but the response_model does not include that field the json sent to the client would not have that password validation whatever you return will be serialized with the response_model converting any data as necessary to generate the corresponding json but if the data in the object returned is not valid that would mean a violation of the contract with the client so it s an error from the api developer so fastapi will raise an error and return a 500 error code internal server error read more about it in the fastapi docs for response model https fastapi tiangolo com tutorial response model the default status code to be used for the response you could override the status code by returning a response directly read more about it in the fastapi docs for response status code https fastapi tiangolo com tutorial response status code a list of tags to be applied to the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration tags a list of dependencies using depends to be applied to the path operation read more about it in the fastapi docs for dependencies in path operation decorators https fastapi tiangolo com tutorial dependencies dependencies in path operation decorators a summary for the path operation it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration a description for the path operation if not provided it will be extracted automatically from the docstring of the path operation function it can contain markdown it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for path operation configuration https fastapi tiangolo com tutorial path operation configuration the description for the default response it will be added to the generated openapi e g visible at docs additional responses that could be returned by this path operation it will be added to the generated openapi e g visible at docs mark this path operation as deprecated it will be added to the generated openapi e g visible at docs custom operation id to be used by this path operation by default it is generated automatically if you provide a custom operation id you need to make sure it is unique for the whole api you can customize the operation id generation with the parameter generate_unique_id_function in the fastapi class read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function configuration passed to pydantic to include only certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to exclude certain fields in the response data read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response model should be serialized by alias when an alias is used read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_include and response_model_exclude configuration passed to pydantic to define if the response data should have all the fields including the ones that were not set and have their default values this is different from response_model_exclude_defaults in that if the fields are set they will be included in the response even if the value is the same as the default when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should have all the fields including the ones that have the same value as the default this is different from response_model_exclude_unset in that if the fields are set but contain the same default values they will be excluded from the response when true default values are omitted from the response read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model use the response_model_exclude_unset parameter configuration passed to pydantic to define if the response data should exclude fields set to none this is much simpler less smart than response_model_exclude_unset and response_model_exclude_defaults you probably want to use one of those two instead of this one as those allow returning none values when it makes sense read more about it in the fastapi docs for response model return type https fastapi tiangolo com tutorial response model response_model_exclude_none include this path operation in the generated openapi schema this affects the generated openapi e g visible at docs read more about it in the fastapi docs for query parameters and string validations https fastapi tiangolo com tutorial query params str validations exclude from openapi response class to be used for this path operation this will not be used if you return a response directly read more about it in the fastapi docs for custom response html stream file others https fastapi tiangolo com advanced custom response redirectresponse name for this path operation only used internally list of path operations that will be used as openapi callbacks this is only for openapi documentation the callbacks won t be used directly it will be added to the generated openapi e g visible at docs read more about it in the fastapi docs for openapi callbacks https fastapi tiangolo com advanced openapi callbacks extra metadata to be included in the openapi schema for this path operation read more about it in the fastapi docs for path operation advanced configuration https fastapi tiangolo com advanced path operation advanced configuration custom openapi path operation schema customize the function used to generate unique ids for the path operations shown in the generated openapi this is particularly useful when automatically generating clients or sdks for your api read more about it in the fastapi docs about how to generate clients https fastapi tiangolo com advanced generate clients custom generate unique id function add a path operation using an http trace operation example python from fastapi import fastapi app fastapi app put items item_id def trace_item item_id str return none on_event is deprecated use lifespan event handlers instead read more about it in the fastapi docs for lifespan events https fastapi tiangolo com advanced events the type of event startup or shutdown add an event handler for the application on_event is deprecated use lifespan event handlers instead read more about it in the fastapi docs for lifespan events https fastapi tiangolo com advanced events alternative events deprecated the type of middleware currently only supports http add a middleware to the application read more about it in the fastapi docs for middleware https fastapi tiangolo com tutorial middleware example python import time from fastapi import fastapi request app fastapi app middleware http async def add_process_time_header request request call_next start_time time time response await call_next request process_time time time start_time response headers x process time str process_time return response the exception class this would handle or a status code add an exception handler to the app read more about it in the fastapi docs for handling errors https fastapi tiangolo com tutorial handling errors example python from fastapi import fastapi request from fastapi responses import jsonresponse class unicornexception exception def __init__ self name str self name name app fastapi app exception_handler unicornexception async def unicorn_exception_handler request request exc unicornexception return jsonresponse status_code 418 content message f oops exc name did something there goes a rainbow
from enum import Enum
from typing import (
    Any,
    Awaitable,
    Callable,
    Coroutine,
    Dict,
    List,
    Optional,
    Sequence,
    Type,
    TypeVar,
    Union,
)

from fastapi import routing
from fastapi.datastructures import Default, DefaultPlaceholder
from fastapi.exception_handlers import (
    http_exception_handler,
    request_validation_exception_handler,
    websocket_request_validation_exception_handler,
)
from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
from fastapi.logger import logger
from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware
from fastapi.openapi.docs import (
    get_redoc_html,
    get_swagger_ui_html,
    get_swagger_ui_oauth2_redirect_html,
)
from fastapi.openapi.utils import get_openapi
from fastapi.params import Depends
from fastapi.types import DecoratedCallable, IncEx
from fastapi.utils import generate_unique_id
from starlette.applications import Starlette
from starlette.datastructures import State
from starlette.exceptions import HTTPException
from starlette.middleware import Middleware
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.middleware.errors import ServerErrorMiddleware
from starlette.middleware.exceptions import ExceptionMiddleware
from starlette.requests import Request
from starlette.responses import HTMLResponse, JSONResponse, Response
from starlette.routing import BaseRoute
from starlette.types import ASGIApp, Lifespan, Receive, Scope, Send
from typing_extensions import Annotated, Doc, deprecated  

AppType = TypeVar("AppType", bound="FastAPI")


class FastAPI(Starlette):
    

    def __init__(
        self: AppType,
        *,
        debug: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        routes: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
            deprecated(
                
            ),
        ] = None,
        title: Annotated[
            str,
            Doc(
                
            ),
        ] = "FastAPI",
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            str,
            Doc(
                
            ),
        ] = "",
        version: Annotated[
            str,
            Doc(
                
            ),
        ] = "0.1.0",
        openapi_url: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = "/openapi.json",
        openapi_tags: Annotated[
            Optional[List[Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        servers: Annotated[
            Optional[List[Dict[str, Union[str, Any]]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        default_response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        redirect_slashes: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        docs_url: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = "/docs",
        redoc_url: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = "/redoc",
        swagger_ui_oauth2_redirect_url: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = "/docs/oauth2-redirect",
        swagger_ui_init_oauth: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        middleware: Annotated[
            Optional[Sequence[Middleware]],
            Doc(
                
            ),
        ] = None,
        exception_handlers: Annotated[
            Optional[
                Dict[
                    Union[int, Type[Exception]],
                    Callable[[Request, Any], Coroutine[Any, Any, Response]],
                ]
            ],
            Doc(
                
            ),
        ] = None,
        on_startup: Annotated[
            Optional[Sequence[Callable[[], Any]]],
            Doc(
                
            ),
        ] = None,
        on_shutdown: Annotated[
            Optional[Sequence[Callable[[], Any]]],
            Doc(
                
            ),
        ] = None,
        lifespan: Annotated[
            Optional[Lifespan[AppType]],
            Doc(
                
            ),
        ] = None,
        terms_of_service: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        contact: Annotated[
            Optional[Dict[str, Union[str, Any]]],
            Doc(
                
            ),
        ] = None,
        license_info: Annotated[
            Optional[Dict[str, Union[str, Any]]],
            Doc(
                
            ),
        ] = None,
        openapi_prefix: Annotated[
            str,
            Doc(
                
            ),
            deprecated(
                
            ),
        ] = "",
        root_path: Annotated[
            str,
            Doc(
                
            ),
        ] = "",
        root_path_in_servers: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        webhooks: Annotated[
            Optional[routing.APIRouter],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        swagger_ui_parameters: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
        separate_input_output_schemas: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        **extra: Annotated[
            Any,
            Doc(
                
            ),
        ],
    ) -> None:
        self.debug = debug
        self.title = title
        self.summary = summary
        self.description = description
        self.version = version
        self.terms_of_service = terms_of_service
        self.contact = contact
        self.license_info = license_info
        self.openapi_url = openapi_url
        self.openapi_tags = openapi_tags
        self.root_path_in_servers = root_path_in_servers
        self.docs_url = docs_url
        self.redoc_url = redoc_url
        self.swagger_ui_oauth2_redirect_url = swagger_ui_oauth2_redirect_url
        self.swagger_ui_init_oauth = swagger_ui_init_oauth
        self.swagger_ui_parameters = swagger_ui_parameters
        self.servers = servers or []
        self.separate_input_output_schemas = separate_input_output_schemas
        self.extra = extra
        self.openapi_version: Annotated[
            str,
            Doc(
                
            ),
        ] = "3.1.0"
        self.openapi_schema: Optional[Dict[str, Any]] = None
        if self.openapi_url:
            assert self.title, "A title must be provided for OpenAPI, e.g.: 'My API'"
            assert self.version, "A version must be provided for OpenAPI, e.g.: '2.1.0'"
        
        if openapi_prefix:
            logger.warning(
                '"openapi_prefix" has been deprecated in favor of "root_path", which '
                "follows more closely the ASGI standard, is simpler, and more "
                "automatic. Check the docs at "
                "https://fastapi.tiangolo.com/advanced/sub-applications/"
            )
        self.webhooks: Annotated[
            routing.APIRouter,
            Doc(
                
            ),
        ] = webhooks or routing.APIRouter()
        self.root_path = root_path or openapi_prefix
        self.state: Annotated[
            State,
            Doc(
                
            ),
        ] = State()
        self.dependency_overrides: Annotated[
            Dict[Callable[..., Any], Callable[..., Any]],
            Doc(
                
            ),
        ] = {}
        self.router: routing.APIRouter = routing.APIRouter(
            routes=routes,
            redirect_slashes=redirect_slashes,
            dependency_overrides_provider=self,
            on_startup=on_startup,
            on_shutdown=on_shutdown,
            lifespan=lifespan,
            default_response_class=default_response_class,
            dependencies=dependencies,
            callbacks=callbacks,
            deprecated=deprecated,
            include_in_schema=include_in_schema,
            responses=responses,
            generate_unique_id_function=generate_unique_id_function,
        )
        self.exception_handlers: Dict[
            Any, Callable[[Request, Any], Union[Response, Awaitable[Response]]]
        ] = {} if exception_handlers is None else dict(exception_handlers)
        self.exception_handlers.setdefault(HTTPException, http_exception_handler)
        self.exception_handlers.setdefault(
            RequestValidationError, request_validation_exception_handler
        )
        self.exception_handlers.setdefault(
            WebSocketRequestValidationError,
            
            websocket_request_validation_exception_handler,  
        )

        self.user_middleware: List[Middleware] = (
            [] if middleware is None else list(middleware)
        )
        self.middleware_stack: Union[ASGIApp, None] = None
        self.setup()

    def build_middleware_stack(self) -> ASGIApp:
        
        
        debug = self.debug
        error_handler = None
        exception_handlers = {}

        for key, value in self.exception_handlers.items():
            if key in (500, Exception):
                error_handler = value
            else:
                exception_handlers[key] = value

        middleware = (
            [Middleware(ServerErrorMiddleware, handler=error_handler, debug=debug)]
            + self.user_middleware
            + [
                Middleware(
                    ExceptionMiddleware, handlers=exception_handlers, debug=debug
                ),
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                Middleware(AsyncExitStackMiddleware),
            ]
        )

        app = self.router
        for cls, options in reversed(middleware):
            app = cls(app=app, **options)
        return app

    def openapi(self) -> Dict[str, Any]:
        
        if not self.openapi_schema:
            self.openapi_schema = get_openapi(
                title=self.title,
                version=self.version,
                openapi_version=self.openapi_version,
                summary=self.summary,
                description=self.description,
                terms_of_service=self.terms_of_service,
                contact=self.contact,
                license_info=self.license_info,
                routes=self.routes,
                webhooks=self.webhooks.routes,
                tags=self.openapi_tags,
                servers=self.servers,
                separate_input_output_schemas=self.separate_input_output_schemas,
            )
        return self.openapi_schema

    def setup(self) -> None:
        if self.openapi_url:
            urls = (server_data.get("url") for server_data in self.servers)
            server_urls = {url for url in urls if url}

            async def openapi(req: Request) -> JSONResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                if root_path not in server_urls:
                    if root_path and self.root_path_in_servers:
                        self.servers.insert(0, {"url": root_path})
                        server_urls.add(root_path)
                return JSONResponse(self.openapi())

            self.add_route(self.openapi_url, openapi, include_in_schema=False)
        if self.openapi_url and self.docs_url:

            async def swagger_ui_html(req: Request) -> HTMLResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                openapi_url = root_path + self.openapi_url
                oauth2_redirect_url = self.swagger_ui_oauth2_redirect_url
                if oauth2_redirect_url:
                    oauth2_redirect_url = root_path + oauth2_redirect_url
                return get_swagger_ui_html(
                    openapi_url=openapi_url,
                    title=self.title + " - Swagger UI",
                    oauth2_redirect_url=oauth2_redirect_url,
                    init_oauth=self.swagger_ui_init_oauth,
                    swagger_ui_parameters=self.swagger_ui_parameters,
                )

            self.add_route(self.docs_url, swagger_ui_html, include_in_schema=False)

            if self.swagger_ui_oauth2_redirect_url:

                async def swagger_ui_redirect(req: Request) -> HTMLResponse:
                    return get_swagger_ui_oauth2_redirect_html()

                self.add_route(
                    self.swagger_ui_oauth2_redirect_url,
                    swagger_ui_redirect,
                    include_in_schema=False,
                )
        if self.openapi_url and self.redoc_url:

            async def redoc_html(req: Request) -> HTMLResponse:
                root_path = req.scope.get("root_path", "").rstrip("/")
                openapi_url = root_path + self.openapi_url
                return get_redoc_html(
                    openapi_url=openapi_url, title=self.title + " - ReDoc"
                )

            self.add_route(self.redoc_url, redoc_html, include_in_schema=False)

    async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        if self.root_path:
            scope["root_path"] = self.root_path
        await super().__call__(scope, receive, send)

    def add_api_route(
        self,
        path: str,
        endpoint: Callable[..., Coroutine[Any, Any, Response]],
        *,
        response_model: Any = Default(None),
        status_code: Optional[int] = None,
        tags: Optional[List[Union[str, Enum]]] = None,
        dependencies: Optional[Sequence[Depends]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        response_description: str = "Successful Response",
        responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None,
        deprecated: Optional[bool] = None,
        methods: Optional[List[str]] = None,
        operation_id: Optional[str] = None,
        response_model_include: Optional[IncEx] = None,
        response_model_exclude: Optional[IncEx] = None,
        response_model_by_alias: bool = True,
        response_model_exclude_unset: bool = False,
        response_model_exclude_defaults: bool = False,
        response_model_exclude_none: bool = False,
        include_in_schema: bool = True,
        response_class: Union[Type[Response], DefaultPlaceholder] = Default(
            JSONResponse
        ),
        name: Optional[str] = None,
        openapi_extra: Optional[Dict[str, Any]] = None,
        generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
            generate_unique_id
        ),
    ) -> None:
        self.router.add_api_route(
            path,
            endpoint=endpoint,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            methods=methods,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def api_route(
        self,
        path: str,
        *,
        response_model: Any = Default(None),
        status_code: Optional[int] = None,
        tags: Optional[List[Union[str, Enum]]] = None,
        dependencies: Optional[Sequence[Depends]] = None,
        summary: Optional[str] = None,
        description: Optional[str] = None,
        response_description: str = "Successful Response",
        responses: Optional[Dict[Union[int, str], Dict[str, Any]]] = None,
        deprecated: Optional[bool] = None,
        methods: Optional[List[str]] = None,
        operation_id: Optional[str] = None,
        response_model_include: Optional[IncEx] = None,
        response_model_exclude: Optional[IncEx] = None,
        response_model_by_alias: bool = True,
        response_model_exclude_unset: bool = False,
        response_model_exclude_defaults: bool = False,
        response_model_exclude_none: bool = False,
        include_in_schema: bool = True,
        response_class: Type[Response] = Default(JSONResponse),
        name: Optional[str] = None,
        openapi_extra: Optional[Dict[str, Any]] = None,
        generate_unique_id_function: Callable[[routing.APIRoute], str] = Default(
            generate_unique_id
        ),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        def decorator(func: DecoratedCallable) -> DecoratedCallable:
            self.router.add_api_route(
                path,
                func,
                response_model=response_model,
                status_code=status_code,
                tags=tags,
                dependencies=dependencies,
                summary=summary,
                description=description,
                response_description=response_description,
                responses=responses,
                deprecated=deprecated,
                methods=methods,
                operation_id=operation_id,
                response_model_include=response_model_include,
                response_model_exclude=response_model_exclude,
                response_model_by_alias=response_model_by_alias,
                response_model_exclude_unset=response_model_exclude_unset,
                response_model_exclude_defaults=response_model_exclude_defaults,
                response_model_exclude_none=response_model_exclude_none,
                include_in_schema=include_in_schema,
                response_class=response_class,
                name=name,
                openapi_extra=openapi_extra,
                generate_unique_id_function=generate_unique_id_function,
            )
            return func

        return decorator

    def add_api_websocket_route(
        self,
        path: str,
        endpoint: Callable[..., Any],
        name: Optional[str] = None,
        *,
        dependencies: Optional[Sequence[Depends]] = None,
    ) -> None:
        self.router.add_api_websocket_route(
            path,
            endpoint,
            name=name,
            dependencies=dependencies,
        )

    def websocket(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        *,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        

        def decorator(func: DecoratedCallable) -> DecoratedCallable:
            self.add_api_websocket_route(
                path,
                func,
                name=name,
                dependencies=dependencies,
            )
            return func

        return decorator

    def include_router(
        self,
        router: Annotated[routing.APIRouter, Doc("The `APIRouter` to include.")],
        *,
        prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "",
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        default_response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> None:
        
        self.router.include_router(
            router,
            prefix=prefix,
            tags=tags,
            dependencies=dependencies,
            responses=responses,
            deprecated=deprecated,
            include_in_schema=include_in_schema,
            default_response_class=default_response_class,
            callbacks=callbacks,
            generate_unique_id_function=generate_unique_id_function,
        )

    def get(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.get(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def put(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.put(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def post(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.post(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def delete(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.delete(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def options(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.options(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def head(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.head(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def patch(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.patch(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def trace(
        self,
        path: Annotated[
            str,
            Doc(
                
            ),
        ],
        *,
        response_model: Annotated[
            Any,
            Doc(
                
            ),
        ] = Default(None),
        status_code: Annotated[
            Optional[int],
            Doc(
                
            ),
        ] = None,
        tags: Annotated[
            Optional[List[Union[str, Enum]]],
            Doc(
                
            ),
        ] = None,
        dependencies: Annotated[
            Optional[Sequence[Depends]],
            Doc(
                
            ),
        ] = None,
        summary: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        description: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_description: Annotated[
            str,
            Doc(
                
            ),
        ] = "Successful Response",
        responses: Annotated[
            Optional[Dict[Union[int, str], Dict[str, Any]]],
            Doc(
                
            ),
        ] = None,
        deprecated: Annotated[
            Optional[bool],
            Doc(
                
            ),
        ] = None,
        operation_id: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        response_model_include: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_exclude: Annotated[
            Optional[IncEx],
            Doc(
                
            ),
        ] = None,
        response_model_by_alias: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_model_exclude_unset: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_defaults: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        response_model_exclude_none: Annotated[
            bool,
            Doc(
                
            ),
        ] = False,
        include_in_schema: Annotated[
            bool,
            Doc(
                
            ),
        ] = True,
        response_class: Annotated[
            Type[Response],
            Doc(
                
            ),
        ] = Default(JSONResponse),
        name: Annotated[
            Optional[str],
            Doc(
                
            ),
        ] = None,
        callbacks: Annotated[
            Optional[List[BaseRoute]],
            Doc(
                
            ),
        ] = None,
        openapi_extra: Annotated[
            Optional[Dict[str, Any]],
            Doc(
                
            ),
        ] = None,
        generate_unique_id_function: Annotated[
            Callable[[routing.APIRoute], str],
            Doc(
                
            ),
        ] = Default(generate_unique_id),
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.trace(
            path,
            response_model=response_model,
            status_code=status_code,
            tags=tags,
            dependencies=dependencies,
            summary=summary,
            description=description,
            response_description=response_description,
            responses=responses,
            deprecated=deprecated,
            operation_id=operation_id,
            response_model_include=response_model_include,
            response_model_exclude=response_model_exclude,
            response_model_by_alias=response_model_by_alias,
            response_model_exclude_unset=response_model_exclude_unset,
            response_model_exclude_defaults=response_model_exclude_defaults,
            response_model_exclude_none=response_model_exclude_none,
            include_in_schema=include_in_schema,
            response_class=response_class,
            name=name,
            callbacks=callbacks,
            openapi_extra=openapi_extra,
            generate_unique_id_function=generate_unique_id_function,
        )

    def websocket_route(
        self, path: str, name: Union[str, None] = None
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        def decorator(func: DecoratedCallable) -> DecoratedCallable:
            self.router.add_websocket_route(path, func, name=name)
            return func

        return decorator

    @deprecated(
        
    )
    def on_event(
        self,
        event_type: Annotated[
            str,
            Doc(
                
            ),
        ],
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        
        return self.router.on_event(event_type)

    def middleware(
        self,
        middleware_type: Annotated[
            str,
            Doc(
                
            ),
        ],
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        

        def decorator(func: DecoratedCallable) -> DecoratedCallable:
            self.add_middleware(BaseHTTPMiddleware, dispatch=func)
            return func

        return decorator

    def exception_handler(
        self,
        exc_class_or_status_code: Annotated[
            Union[int, Type[Exception]],
            Doc(
                
            ),
        ],
    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
        

        def decorator(func: DecoratedCallable) -> DecoratedCallable:
            self.add_exception_handler(exc_class_or_status_code, func)
            return func

        return decorator