Package: openapipages
Open API PagesTotally Pythonic, OpenAPI Based customizable documentation pages forSwaggerUI,ReDoc,RapiDoc,Elements,Scalar.Keep in mind, that this package doesn't generateOpenAPISpec, it just renders the pages with the given configuration.Table of ContentsOpen API PagesTable of ContentsFeaturesProgressInstallationUsageFastAPILitestarMotivationDeveloper ExperienceConfigurationAlternativesStandardisationSee AlsoProjectsIssues, PRs, and DiscussionsAuthorDisclaimerLicenseFeaturesGimme an OpenAPI Spec, leave the rest to me...Framework agnostic.Zero dependencies, just Python standard library.Fully typed.Highly extensible.ProgressDocumentationPageConfigSwaggerUI:white_check_mark::heavy_check_mark:ReDoc:white_check_mark::heavy_check_mark:RapiDoc:white_check_mark::heavy_check_mark:Elements:white_check_mark::heavy_check_mark:Scalar:white_check_mark::heavy_check_mark:Emoji Key:EmojiMeaning:white_check_mark:Ready:heavy_check_mark:Partially:x:Failed:construction:In Progress:white_square_button:Pending:warning:Not sureInstallationpip install openapipagesUsageI know it looks a bit boilerplate but it's all straight-forward. The.render()method returns the HTML as a string. Thanks to this design, you can extend and configure the pages as you wish (e.g. add extra logic to restrict access to the page).FastAPITheinclude_in_schemaparameter is set toFalsein each endpoint to avoid including these endpoints in the OpenAPI Spec.fromfastapiimportFastAPIfromfastapi.responsesimportHTMLResponsefromopenapipagesimportElements,RapiDoc,ReDoc,Scalar,SwaggerUIapp=FastAPI()@app.get("/")defroot()->dict[str,str]:return{"Hello":"World"}@app.get("/swaggerui",response_class=HTMLResponse,include_in_schema=False)defget_swaggerui()->str:returnSwaggerUI(title="Swagger UI").render()@app.get("/redoc",response_class=HTMLResponse,include_in_schema=False)defget_redoc()->str:returnReDoc(title="ReDoc").render()@app.get("/scalar",response_class=HTMLResponse,include_in_schema=False)defget_scalar()->str:returnScalar(title="Scalar").render()@app.get("/elements",response_class=HTMLResponse,include_in_schema=False)defget_elements()->str:returnElements(title="Elements").render()@app.get("/rapidoc",response_class=HTMLResponse,include_in_schema=False)defget_rapidoc()->str:returnRapiDoc(title="RapiDoc").render()LitestarTheinclude_in_schemaparameter is set toFalsein each endpoint to avoid including these endpoints in the OpenAPI Spec.fromlitestarimportLitestar,MediaType,getfromopenapipagesimportElements,RapiDoc,ReDoc,Scalar,SwaggerUIopenapi_url="/schema/openapi.json"@get("/")defroot()->dict[str,str]:return{"Hello":"World"}@get("/swaggerui",media_type=MediaType.HTML,include_in_schema=False)defget_swaggerui()->str:returnSwaggerUI(title="Swagger UI",openapi_url=openapi_url).render()@get("/redoc",media_type=MediaType.HTML,include_in_schema=False)defget_redoc()->str:returnReDoc(title="ReDoc",openapi_url=openapi_url).render()@get("/scalar",media_type=MediaType.HTML,include_in_schema=False)defget_scalar()->str:returnScalar(title="Scalar",openapi_url=openapi_url).render()@get("/elements",media_type=MediaType.HTML,include_in_schema=False)defget_elements()->str:returnElements(title="Elements",openapi_url=openapi_url).render()@get("/rapidoc",media_type=MediaType.HTML,include_in_schema=False)defget_rapidoc()->str:returnRapiDoc(title="RapiDoc",openapi_url=openapi_url).render()app=Litestar([root,get_swaggerui,get_redoc,get_scalar,get_elements,get_rapidoc])MotivationTL;DR - I don't want to copy and paste it again...Developer ExperienceSeveral API Documentation tools are ready to use at your fingertips with a standard interface.No more copying and pasting the same thing from one project to another. Import the package and use it!ConfigurationHere is a pull request made to theFastAPIrepo. This was the point I understood the configuration was limited and it wouldn't change...Allow passing ui parameters to redoc html by adriantre · Pull Request #10437 · tangelo/fastapiAlso, the author's answer to this PR shows that we won't be seeing more alternative documentation tools in the future.AlternativesHere is another pull request made to theFastAPIrepo. It bringsScalarsupport, but it's not approved/merged yet and we think it will stay that way thanks to the previous PR.feat: add scalar integration (additional alternative to Swagger UI/Redoc) by marclave · Pull Request #10674 · tiangolo/fastapiStandardisationA standard interface for many API Documentation Interfaces with configuration features.Lately, OpenAPI Spec-based Documentation tools have become popular in the Python community. We see a lot of projects (FastAPI,Litestar,APISpec,flasgger,SpecTree,Connexion, etc) offering support for OpenAPI Specification out of the box.Litestarhas support forSwaggerUI,ReDoc,RapiDoc, andElementsandFastAPIhas support forSwaggerUI, andReDocbut what is next? Will the next one be enough?They all have one thing in common, some HTML (as Python string or a file) templated with the given configuration.Do you see where I am going?I wantopenapipagesto be SQLAlchemy of OpenAPI Spec-based Documentation tools.One interface for many! And of course Framework agnostic... So you can use it in yourFastAPI,Litestarprojects, or any other project that generates OpenAPI specifications.See AlsoProjectskemingy/defspec: Create the OpenAPI spec and document from dataclass, attrs, etc.spec-first/swagger_ui_bundle: bundled swagger-ui pip packagespec-first/connexion: Connexion is a modern Python web framework that makes spec-first and api-first development easy.sveint/flask-swagger-ui: Swagger UI blueprint for flaskflasgger/flasgger: Easy OpenAPI specs and Swagger UI for your Flask APImarshmallow-code/apispec: A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..jmcarp/flask-apispecIssues, PRs, and Discussions[Question] Is it possible to load the Swagger UI offline? · Issue #261 · 0b01001001/spectreeSwagger with hosted files does not work after upgrade · tiangolo/fastapi · Discussion #10426♻️ Generate cleaner Swagger HTML by s-rigaud · Pull Request #11072 · tiangolo/fastapiAuthorHasan Sezer Tasan, It's me :wave:DisclaimerFastAPIandLitestarprojects and the two pull requests mentioned above inspired me to create this package.Licenseopenapipagesis distributed under the terms of theMITlicense.