Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

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

Project Description

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

Features

  • Supports OpenAPI 2.0 specification (f.k.a. Swagger)
  • Framework-agnostic
  • Includes plugins for marshmallow, Flask, Tornado, and bottle.
  • Utilities for parsing docstrings

Example Application

from apispec import APISpec
from flask import Flask, jsonify
from marshmallow import Schema, fields

# Create an APISpec
spec = APISpec(
    title='Swagger Petstore',
    version='1.0.0',
    plugins=[
        'apispec.ext.flask',
        'apispec.ext.marshmallow',
    ],
)

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

class PetSchema(Schema):
    category = fields.Nested(CategorySchema, many=True)
    name = fields.Str()

# Optional Flask support
app = Flask(__name__)

@app.route('/random')
def random_pet():
    """A cute furry animal endpoint.
    ---
    get:
        description: Get a random pet
        responses:
            200:
                description: A pet to be returned
                schema: PetSchema
    """
    pet = get_random_pet()
    return jsonify(PetSchema().dump(pet).data)

# Register entities and paths
spec.definition('Category', schema=CategorySchema)
spec.definition('Pet', schema=PetSchema)
with app.test_request_context():
    spec.add_path(view=random_pet)

Generated OpenAPI Spec

spec.to_dict()
# {
#   "info": {
#     "title": "Swagger Petstore",
#     "version": "1.0.0"
#   },
#   "swagger": "2.0",
#   "paths": {
#     "/random": {
#       "get": {
#         "description": "A cute furry animal endpoint.",
#         "responses": {
#           "200": {
#             "schema": {
#               "$ref": "#/definitions/Pet"
#             },
#             "description": "A pet to be returned"
#           }
#         },
#       }
#     }
#   },
#   "definitions": {
#     "Pet": {
#       "properties": {
#         "category": {
#           "type": "array",
#           "items": {
#             "$ref": "#/definitions/Category"
#           }
#         },
#         "name": {
#           "type": "string"
#         }
#       }
#     },
#     "Category": {
#       "required": [
#         "name"
#       ],
#       "properties": {
#         "name": {
#           "type": "string"
#         },
#         "id": {
#           "type": "integer",
#           "format": "int32"
#         }
#       }
#     }
#   },
# }

Documentation

Documentation is available at http://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

License

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

Release History

Release History

This version
History Node

0.25.2

History Node

0.25.1

History Node

0.25.0

History Node

0.24.0

History Node

0.23.1

History Node

0.23.0

History Node

0.22.3

History Node

0.22.2

History Node

0.22.1

History Node

0.22.0

History Node

0.21.0

History Node

0.20.1

History Node

0.20.0

History Node

0.19.0

History Node

0.18.0

History Node

0.17.4

History Node

0.17.3

History Node

0.17.2

History Node

0.17.1

History Node

0.17.0

History Node

0.16.0

History Node

0.15.0

History Node

0.14.0

History Node

0.13.0

History Node

0.12.0

History Node

0.11.1

History Node

0.11.0

History Node

0.10.1

History Node

0.10.0

History Node

0.9.1

History Node

0.9.0

History Node

0.8.0

History Node

0.7.0

History Node

0.6.0

History Node

0.5.0

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
apispec-0.25.2-py2.py3-none-any.whl (22.2 kB) Copy SHA256 Checksum SHA256 py2.py3 Wheel Sep 6, 2017
apispec-0.25.2.tar.gz (41.8 kB) Copy SHA256 Checksum SHA256 Source Sep 6, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting