apispec-plugins
APISpec plugins for easy integration with different components (web frameworks, packages, etc).
Features
Support for the OpenAPI Specification (versions 2 and 3)
Support for frameworks/plugins which include:
apispec_plugins.webframeworks.flask
apispec_plugins.ext.pydantic
Installation
Install the package directly from PyPI (recommended):
$ pip install apispec-plugins
Plugin dependencies like flask and pydantic are not installed with the package by default. To have flask and pydantic installed, run:
$ pip install apispec-plugins[flask,pydantic]
Example Usage
from typing import Optional
from apispec import APISpec
from apispec_plugins.base.mixin import RegistryMixin
from apispec_plugins.ext.pydantic import PydanticPlugin
from apispec_plugins.webframeworks.flask import FlaskPlugin
from flask import Flask
from pydantic import BaseModel
# set APISpec plugins
spec = APISpec(
title="Pet Store",
version="1.0.0",
openapi_version="3.0.3",
info=dict(description="A minimal pet store API"),
plugins=(FlaskPlugin(), PydanticPlugin()),
)
# optional Flask support
app = Flask(__name__)
# optional pydantic support
class Pet(BaseModel, RegistryMixin):
id: Optional[int]
name: str
@app.route("/pet/<petId>")
def pet(petId):
"""Find pet by ID.
---
get:
parameters:
- in: path
name: petId
responses:
200:
description: display pet data
content:
application/json:
schema: Pet
"""
return f"Display pet with ID {petId}"
# register `path` for the Flask route
with app.test_request_context():
spec.path(view=pet)
Alternatively, to Flask routes, MethodView can be used:
from flask.views import MethodView
class PetAPI(MethodView):
def get(self, petId):
# get pet by ID
pass
app.add_url_rule("/pet/<petId>", view_func=PetAPI.as_view("pet_view"))
Dynamic specs
As seen so far, specs are specified in the docstring of the view or class. However, with the spec_from decorator, one can dynamically set specs:
from apispec_plugins import spec_from
@spec_from(
{
"parameters": {"in": "path", "name": "petId"},
"responses": {200: {"description": "display pet data"}},
}
)
def pet(petID):
"""Find pet by ID."""
pass
Why not apispec-webframeworks?
The conceiving of this project was based on apispec-webframeworks. While that project is focused on integrating web frameworks with APISpec, this project goes a step further in providing the best integration possible with the APISpec standards. Some limitations on that project were also addressed, like:
a path cannot register no more than 1 single rule per endpoint;
limited docstring spec processing;
Tests & linting 🚥
Run tests with tox:
# ensure tox is installed
$ tox
Run linter only:
$ tox -e lint
Optionally, run coverage as well with:
$ tox -e coverage
License
MIT licensed. See LICENSE.
Metadata
Release files for apispec-plugins 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| apispec_plugins-1.1.1.tar.gz | 9.8 kB | Without provenance | Details for apispec_plugins-1.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| apispec_plugins-1.1.1-py3-none-any.whl | Python 3 | none | any | Details for apispec_plugins-1.1.1-py3-none-any.whl |
Total release size: 20.5 kB
Release files / apispec_plugins-1.1.1.tar.gz
| Download URL | apispec_plugins-1.1.1.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8242c262faca3bc30e17c98337db7fc905ed5767a0f0f71b8e2cd6952263afea
|
|
BLAKE2b-256 checksum How to use checksums |
4679cef8ba8b4f79f41d3dc29729ccc2900272adb228d3d189b9235df733299d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure
|
Release files / apispec_plugins-1.1.1-py3-none-any.whl
| Download URL | apispec_plugins-1.1.1-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
908ec5eae4eeb822c093685146c951924511c38ccaef9acda9be40cc738e5ba6
|
|
BLAKE2b-256 checksum How to use checksums |
03750423f2e4f93e857388ec8008f96cba26e065ad7d3ee463f9b145c901227f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.4.1 CPython/3.9.16 Linux/5.15.0-1034-azure
|
Security for apispec-plugins 1.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.