Skip to content

luolingchun/star-openapi

Repository files navigation

A simple async API framework based on Starlette.

test pypi pypistats pypi versions

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:

Requirements

Python 3.11+

star-openapi is dependent on the following libraries:

Installation

pip install -U star-openapi[swagger]
Optional dependencies
  • httpx - Required if you want to use the TestClient.
  • python-multipart - Required if you want to support form parsing, with request.form().
  • itsdangerous - Required for SessionMiddleware support.
  • pyyaml - Required for SchemaGenerator support.

You can install all of these with pip install star-openapi[full].

You can install all of these with pip install star-openapi[swagger,redoc,rapidoc,rapipdf,scalar,elements].

A Simple Example

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)

API Document

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.

openapi

Packages

No packages published

Contributors 2

  •  
  •  

Languages