This release is a pre-release and may not be stable for production use.
A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification).
Features
Supports OpenAPI Specification version 2 (f.k.a. the Swagger specification) with limited support for version 3.
Framework-agnostic
Includes plugins for marshmallow, Flask, Tornado, and bottle.
Utilities for parsing docstrings
Example Application
from apispec import APISpec
from apispec.ext.flask import FlaskPlugin
from apispec.ext.marshmallow import MarshmallowPlugin
from flask import Flask, jsonify
from marshmallow import Schema, fields
# Create an APISpec
spec = APISpec(
title='Swagger Petstore',
version='1.0.0',
openapi_version='2.0',
plugins=[
FlaskPlugin(),
MarshmallowPlugin(),
],
)
# 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"
# }
# }
# }
# },
# }
spec.to_yaml()
# definitions:
# Pet:
# enum: [name, photoUrls]
# properties:
# id: {format: int64, type: integer}
# name: {example: doggie, type: string}
# info: {description: 'This is a sample Petstore server. You can find out more ', title: Swagger Petstore, version: 1.0.0}
# parameters: {}
# paths: {}
# security:
# - apiKey: []
# swagger: '2.0'
# tags: []
Documentation
Documentation is available at http://apispec.readthedocs.io/ .
Ecosystem
A list of apispec-related libraries can be found at the GitHub wiki here:
License
MIT licensed. See the bundled LICENSE file for more details.
Metadata
Release files for apispec 1.0.0b1
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 | |
|---|---|---|---|---|
| apispec-1.0.0b1.tar.gz | 54.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| apispec-1.0.0b1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 79.6 kB
Release files / apispec-1.0.0b1.tar.gz
| Download URL | apispec-1.0.0b1.tar.gz |
|---|---|
| Size | 54.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a860054f06aea397b1f60386ab4dc69c91e4f369548bd1034d15232026dbd781
|
|
BLAKE2b-256 checksum How to use checksums |
f920764ef8a3b5361ef19f810165d619432135a5e23409c801042d530a32e907
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
|
Release files / apispec-1.0.0b1-py2.py3-none-any.whl
| Download URL | apispec-1.0.0b1-py2.py3-none-any.whl |
|---|---|
| Size | 25.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
77fdd3929bc8c8832c302a4e8ca8e03428231b14805219a26e71d467f6ea409f
|
|
BLAKE2b-256 checksum How to use checksums |
2aa027a8d90e0ab6f650ed119808b7dd3ef48a0c37325ecf3a52cc3d513c3331
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.3
|
Security for apispec 1.0.0b1
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.