Registry / web-framework / apispec-webframeworks

apispec-webframeworks

JSON →
library1.2.0pypypi✓ verified 21d ago

apispec-webframeworks is a Python library providing plugins to integrate `apispec` with various web frameworks like Flask, Aiohttp, Bottle, and Tornado. These plugins were originally part of `apispec.ext` but were moved to this separate package to streamline `apispec`'s core. It is currently at version 1.2.0 and receives updates to maintain compatibility with `apispec` and relevant frameworks.

pip install apispec-webframeworks apispec[marshmallow] flask marshmallow
INSTALL
IMPORT
SIG · APISPEC-WEBFRAMEWO
A
apispec-webframeworks
web-frameworkpythonv1.2.0
Install
2.3s avg
Import
622ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.640s · 26.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.3s · import 0.604s · 28MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FlaskPlugin
from apispec_webframeworks.flask import FlaskPlugin
from apispec.ext.flask import FlaskPlugin
Web framework plugins were moved from `apispec.ext` to `apispec_webframeworks` in `apispec` versions >= 1.0.0.
AiohttpPlugin
from apispec_webframeworks.aiohttp import AiohttpPlugin
BottlePlugin
from apispec_webframeworks.bottle import BottlePlugin
TornadoPlugin
from apispec_webframeworks.tornado import TornadoPlugin

This quickstart demonstrates how to integrate `apispec-webframeworks` with Flask and `marshmallow` to automatically generate OpenAPI specifications from view function docstrings and Marshmallow schemas. It sets up a basic Flask application, defines an API endpoint, and exposes the generated OpenAPI JSON.

from flask import Flask from apispec import APISpec from apispec.ext.marshmallow import MarshmallowPlugin from apispec_webframeworks.flask import FlaskPlugin from marshmallow import Schema, fields # 1. Create an APISpec instance spec = APISpec( title="My Awesome API", version="1.0.0", openapi_version="3.0.2", info=dict(description="A minimal Flask API example"), plugins=[ FlaskPlugin(), MarshmallowPlugin() ], ) # 2. Define a Marshmallow Schema class ItemSchema(Schema): id = fields.Int(dump_only=True) name = fields.Str(required=True, description="The item's name") # 3. Register the schema with APISpec spec.components.schema("Item", schema=ItemSchema) # 4. Initialize Flask app app = Flask(__name__) # 5. Define a Flask route with OpenAPI docstrings @app.route("/items/<int:item_id>") def get_item(item_id): """Get item by ID --- parameters: - in: path name: item_id schema: type: integer required: true description: Numeric ID of the item to retrieve responses: 200: description: Item details content: application/json: schema: ItemSchema 404: description: Item not found """ # In a real app, you'd fetch from a DB if item_id == 1: return ItemSchema().dump({'id': 1, 'name': 'Sample Item'}) return {"message": "Item not found"}, 404 # 6. Register the Flask path with APISpec (must be in request context) with app.test_request_context(): spec.path(view=get_item) # 7. Add an endpoint to serve the OpenAPI spec @app.route("/swagger.json") def swagger_spec(): return spec.to_dict() # To run this example: # 1. Save as app.py # 2. Run: flask run # 3. Access: http://127.0.0.1:5000/swagger.json
Debug
Known issues
breakingThe web framework plugins (e.g., `FlaskPlugin`, `AiohttpPlugin`) were moved from `apispec.ext` to the dedicated `apispec-webframeworks` package. If upgrading `apispec` from a version older than `1.0.0`, you must update your imports.
fix
Change imports from `from apispec.ext.flask import FlaskPlugin` to `from apispec_webframeworks.flask import FlaskPlugin`.
affects: < 1.0.0 (for apispec) / all (for apispec-webframeworks)
gotchaWhen using `spec.path(view=...)` for Flask views, the call must be made within an active Flask application context or a `test_request_context` for `apispec` to correctly inspect the view and its route.
fix
Wrap calls to `spec.path()` in a `with app.test_request_context():` block or ensure a request context is active.
affects: all
gotchaThis library provides *plugins* for web frameworks but does not install the frameworks themselves. You must explicitly install your chosen web framework (e.g., `flask`, `aiohttp`, `bottle`, `tornado`) separately.
fix
Install your desired web framework (e.g., `pip install flask`) alongside `apispec-webframeworks`.
affects: all
gotchaAs of version 1.2.0, `apispec-webframeworks` does not officially provide a plugin for Starlette. If you are looking for Starlette integration, consider alternative packages like `starlette-apispec` or `apispec-plugins`.
fix
Use a community-maintained Starlette plugin (e.g., `starlette-apispec`) or implement custom integration.
affects: all
gotchaSupport for Flask Blueprints within `apispec-webframeworks.flask.FlaskPlugin` may be limited, potentially requiring manual workarounds or alternative libraries like `flask-apispec` or `apispec-plugins` for full integration. There are open discussions about enhancing this.
fix
For complex Flask Blueprint setups, investigate `flask-apispec` or `apispec-plugins`, or implement custom path registration within your Blueprints.
affects: all
Upgrade
Version history
1.2.0latest on PyPI · released Sep 16, 2024
Audit
Dependencies
apispecrequiredThis library provides plugins for apispec.
flaskoptionalRequired to use the FlaskPlugin. Not installed by apispec-webframeworks itself.
aiohttpoptionalRequired to use the AiohttpPlugin. Not installed by apispec-webframeworks itself.
bottleoptionalRequired to use the BottlePlugin. Not installed by apispec-webframeworks itself.
tornadooptionalRequired to use the TornadoPlugin. Not installed by apispec-webframeworks itself.
marshmallowoptionalCommonly used with apispec for schema generation, especially via `apispec.ext.marshmallow.MarshmallowPlugin`.
Agent activity
26 hits · last 30 days
node
22
OpenAI (training)
1
Resources
apispec-webframeworks — pip install apispec-webframeworks · libregistry