apispec 6.8.4


pip install apispec

  Latest version

Released: Sep 22, 2025


Meta
Author: Steven Loria
Maintainer: Steven Loria, Jérôme Lafréchoux
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

Intended Audience
  • Developers

License
  • OSI Approved :: MIT License

Programming Language
  • Python :: 3
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13

PyPI package Build status Documentation marshmallow 3|4 compatible OpenAPI Specification 2/3 compatible

A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification).

Features

  • Supports the OpenAPI Specification (versions 2 and 3)

  • Framework-agnostic

  • Built-in support for marshmallow

  • Utilities for parsing docstrings

Installation

$ pip install -U apispec

When using the marshmallow plugin, ensure a compatible marshmallow version is used:

$ pip install -U apispec[marshmallow]

Example Application

from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_webframeworks.flask import FlaskPlugin
from flask import Flask
from marshmallow import Schema, fields


# Create an APISpec
spec = APISpec(
    title="Swagger Petstore",
    version="1.0.0",
    openapi_version="3.0.2",
    plugins=[FlaskPlugin(), MarshmallowPlugin()],
)


# Optional marshmallow support
class CategorySchema(Schema):
    id = fields.Int()
    name = fields.Str(required=True)


class PetSchema(Schema):
    category = fields.List(fields.Nested(CategorySchema))
    name = fields.Str()


# Optional security scheme support
api_key_scheme = {"type": "apiKey", "in": "header", "name": "X-API-Key"}
spec.components.security_scheme("ApiKeyAuth", api_key_scheme)


# Optional Flask support
app = Flask(__name__)


@app.route("/random")
def random_pet():
    """A cute furry animal endpoint.
    ---
    get:
      description: Get a random pet
      security:
        - ApiKeyAuth: []
      responses:
        200:
          content:
            application/json:
              schema: PetSchema
    """
    pet = get_random_pet()
    return PetSchema().dump(pet)


# Register the path and the entities within it
with app.test_request_context():
    spec.path(view=random_pet)

Generated OpenAPI Spec

import json

print(json.dumps(spec.to_dict(), indent=2))
# {
#   "paths": {
#     "/random": {
#       "get": {
#         "description": "Get a random pet",
#         "security": [
#           {
#             "ApiKeyAuth": []
#           }
#         ],
#         "responses": {
#           "200": {
#             "content": {
#               "application/json": {
#                 "schema": {
#                   "$ref": "#/components/schemas/Pet"
#                 }
#               }
#             }
#           }
#         }
#       }
#     }
#   },
#   "tags": [],
#   "info": {
#     "title": "Swagger Petstore",
#     "version": "1.0.0"
#   },
#   "openapi": "3.0.2",
#   "components": {
#     "parameters": {},
#     "responses": {},
#     "schemas": {
#       "Category": {
#         "type": "object",
#         "properties": {
#           "name": {
#             "type": "string"
#           },
#           "id": {
#             "type": "integer",
#             "format": "int32"
#           }
#         },
#         "required": [
#           "name"
#         ]
#       },
#       "Pet": {
#         "type": "object",
#         "properties": {
#           "name": {
#             "type": "string"
#           },
#           "category": {
#             "type": "array",
#             "items": {
#               "$ref": "#/components/schemas/Category"
#             }
#           }
#         }
#       }
#       "securitySchemes": {
#          "ApiKeyAuth": {
#            "type": "apiKey",
#            "in": "header",
#            "name": "X-API-Key"
#         }
#       }
#     }
#   }
# }

print(spec.to_yaml())
# components:
#   parameters: {}
#   responses: {}
#   schemas:
#     Category:
#       properties:
#         id: {format: int32, type: integer}
#         name: {type: string}
#       required: [name]
#       type: object
#     Pet:
#       properties:
#         category:
#           items: {$ref: '#/components/schemas/Category'}
#           type: array
#         name: {type: string}
#       type: object
#   securitySchemes:
#     ApiKeyAuth:
#       in: header
#       name: X-API-KEY
#       type: apiKey
# info: {title: Swagger Petstore, version: 1.0.0}
# openapi: 3.0.2
# paths:
#   /random:
#     get:
#       description: Get a random pet
#       responses:
#         200:
#           content:
#             application/json:
#               schema: {$ref: '#/components/schemas/Pet'}
#       security:
#       - ApiKeyAuth: []
# tags: []

Documentation

Documentation is available at https://apispec.readthedocs.io/ .

Ecosystem

A list of apispec-related libraries can be found at the GitHub wiki here:

https://github.com/marshmallow-code/apispec/wiki/Ecosystem

Support apispec

apispec is maintained by a group of volunteers. If you’d like to support the future of the project, please consider contributing to our Open Collective:

Donate to our collective

Professional Support

Professionally-supported apispec is available through the Tidelift Subscription.

Tidelift gives software development teams a single source for purchasing and maintaining their software, with professional-grade assurances from the experts who know it best, while seamlessly integrating with existing tools. [Get professional support]

Get supported apispec with Tidelift

Security Contact Information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

License

MIT licensed. See the bundled LICENSE file for more details.

6.8.4 Sep 22, 2025
6.8.3 Sep 07, 2025
6.8.2 May 12, 2025
6.8.1 Jan 07, 2025
6.8.0 Dec 02, 2024
6.7.1 Nov 04, 2024
6.7.0 Oct 20, 2024
6.6.1 Apr 22, 2024
6.6.0 Mar 15, 2024
6.5.0 Feb 26, 2024
6.4.0 Jan 10, 2024
6.3.1 Dec 21, 2023
6.3.0 Mar 10, 2023
6.2.0 Mar 06, 2023
6.1.0 Mar 03, 2023
6.0.2 Nov 10, 2022
6.0.1 Nov 05, 2022
6.0.0 Oct 14, 2022
6.0.0b1 Oct 04, 2022
5.2.2 May 12, 2022
5.2.1 May 01, 2022
5.2.0 Apr 29, 2022
5.1.1 Sep 27, 2021
5.1.0 Aug 10, 2021
5.0.0 Jul 29, 2021
5.0.0b1 Jul 21, 2021
4.7.1 Jul 06, 2021
4.7.0 Jun 28, 2021
4.6.0 Jun 14, 2021
4.5.0 Jun 04, 2021
4.4.2 May 24, 2021
4.4.1 May 07, 2021
4.4.0 Mar 31, 2021
4.3.0 Feb 10, 2021
4.2.0 Feb 06, 2021
4.1.0 Feb 06, 2021
4.0.0 Sep 30, 2020
4.0.0b1.post0 Oct 02, 2020
3.3.2 Aug 29, 2020
3.3.1 Jun 06, 2020
3.3.0 Feb 14, 2020
3.2.0 Dec 22, 2019
3.1.1 Dec 17, 2019
3.1.0 Nov 04, 2019
3.0.0 Sep 17, 2019
2.0.2 Jul 04, 2019
2.0.1 Jun 26, 2019
2.0.0 Jun 18, 2019
1.3.3 May 05, 2019
1.3.2 May 02, 2019
1.3.1 Apr 30, 2019
1.3.0 Apr 24, 2019
1.2.1 Apr 18, 2019
1.2.0 Apr 08, 2019
1.1.2 Apr 07, 2019
1.1.1 Apr 03, 2019
1.1.0 Mar 17, 2019
1.0.0 Feb 08, 2019
1.0.0rc1 Jan 30, 2019
1.0.0b6 Dec 16, 2018
1.0.0b5 Nov 07, 2018
1.0.0b4 Oct 28, 2018
1.0.0b3 Oct 08, 2018
1.0.0b2 Sep 10, 2018
1.0.0b1 Jul 30, 2018
0.39.0 Jun 29, 2018
0.38.0 Jun 10, 2018
0.37.1 May 29, 2018
0.37.0 May 14, 2018
0.36.0 May 08, 2018
0.35.0 Apr 11, 2018
0.34.0 Apr 05, 2018
0.33.0 Apr 01, 2018
0.32.0 Mar 24, 2018
0.31.0 Jan 31, 2018
0.30.0 Jan 31, 2018
0.29.0 Jan 05, 2018
0.28.0 Dec 09, 2017
0.27.1 Dec 06, 2017
0.27.0 Oct 31, 2017
0.26.0 Oct 23, 2017
0.25.4 Oct 09, 2017
0.25.3 Sep 27, 2017
0.25.2 Sep 06, 2017
0.25.1 Aug 24, 2017
0.25.0 Aug 16, 2017
0.24.0 Aug 15, 2017
0.23.1 Aug 09, 2017
0.23.0 Aug 04, 2017
0.22.3 Jul 16, 2017
0.22.2 Jul 12, 2017
0.22.1 Jun 26, 2017
0.22.0 May 31, 2017
0.21.0 Apr 21, 2017
0.20.1 Apr 18, 2017
0.20.0 Mar 19, 2017
0.19.0 Mar 05, 2017
0.18.0 Feb 19, 2017
0.17.4 Feb 17, 2017
0.17.3 Jan 21, 2017
0.17.2 Jan 04, 2017
0.17.1 Nov 19, 2016
0.17.0 Oct 30, 2016
0.16.0 Oct 13, 2016
0.15.0 Oct 03, 2016
0.14.0 Aug 15, 2016
0.13.0 Jul 03, 2016
0.12.0 May 22, 2016
0.11.1 May 03, 2016
0.11.0 Apr 13, 2016
0.10.1 Apr 09, 2016
0.9.1 Mar 18, 2016
0.9.0 Mar 14, 2016
0.8.0 Mar 06, 2016
0.7.0 Feb 11, 2016
0.6.0 Jan 05, 2016
0.5.0 Dec 14, 2015
0.4.2 Nov 23, 2015
0.4.1 Oct 20, 2015
0.4.0 Oct 18, 2015
0.3.0 Oct 03, 2015

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
packaging (>=21.3)