A simple async API framework based on Starlette.
Star OpenAPI is a web API framework based on Starlette. It uses Pydantic to verify data and automatic generation of interaction documentation.
The key features are:
-
Easy to code: Easy to use and easy to learn
-
Standard document specification: Based on OpenAPI Specification
-
Interactive OpenAPI documentation: Swagger, Redoc, RapiDoc, RapiPdf, Scalar, Elements
-
Data validation: Fast data verification based on Pydantic
-
Websocket: Support for websocket
Python 3.11+
star-openapi is dependent on the following libraries:
pip install -U star-openapi[swagger]Optional dependencies
httpx- Required if you want to use theTestClient.python-multipart- Required if you want to support form parsing, withrequest.form().itsdangerous- Required forSessionMiddlewaresupport.pyyaml- Required forSchemaGeneratorsupport.
You can install all of these with pip install star-openapi[full].
- star-openapi-plugins Provide OpenAPI UI for star-openapi.
You can install all of these with pip install star-openapi[swagger,redoc,rapidoc,rapipdf,scalar,elements].
Here's a simple example, further go to the Example.
import uvicorn
from pydantic import BaseModel
from starlette.responses import JSONResponse
from star_openapi import OpenAPI
info = {"title": "Star API", "version": "1.0.0"}
app = OpenAPI(info=info)
book_tag = {"name": "book", "description": "book tag"}
class TestModel(BaseModel):
name: str
age: int
@app.post("/book", summary="get books", tags=[book_tag])
async def create_user(body: TestModel):
"""
get all books
"""
print(body.model_dump_json())
return JSONResponse({"message": "Hello World"})
if __name__ == "__main__":
print(app.routes)
uvicorn.run(app)Run the simple example, and go to http://127.0.0.1:8000/openapi.
OpenAPI UI plugins are optional dependencies that require manual installation.
pip install -U star-openapi[swagger,redoc,rapidoc,rapipdf,scalar,elements]More optional ui templates goto the document about UI_Templates.
