pyramid_apispec
pyramid_apispec allows you to create an OpenAPI specification file using apispec and an online OpenAPI explorer using the Swagger UI project for your Pyramid application and its marshmallow schemas.
Installation
pip install pyramid_apispec
Basic usage
Check out the demo folder and minimal application example by running:
pip install -e .[demo]
python demo/app.py
You can then visit your API explorer page at http://0.0.0.0:6543/api-explorer.
Examples
Hinting a route and its view:
@view_config(route_name='foo_route', renderer='json')
def foo_view():
"""A greeting endpoint.
---
x-extension: value
get:
description: some description
responses:
200:
description: response for 200 code
schema:
$ref: #/definitions/BarBodySchema
"""
return 'hi'
Rendering the spec as JSON response:
from pyramid_apispec.helpers import add_pyramid_paths
@view_config(route_name='openapi_spec', renderer='json')
def api_spec(request):
spec = APISpec(
title='Some API',
version='1.0.0',
plugins=[
'apispec.ext.marshmallow'
],
)
# using marshmallow plugin here
spec.definition('SomeFooBody', schema=MarshmallowSomeFooBodySchema)
# inspect the `foo_route` and generate operations from docstring
add_pyramid_paths(spec, 'foo_route', request=request)
# inspection supports filtering via pyramid add_view predicate arguments
add_pyramid_paths(
spec, 'bar_route', request=request, request_method='post')
return spec.to_dict()
Adding the API explorer view
To complement the specification file generation, this package can also provide an API explorer for your application's API via the Swagger UI project:
config.include('pyramid_apispec.views')
config.pyramid_apispec_add_explorer(
spec_route_name='openapi_spec')
By default you need to pass the route name of the view that serves the OpenAPI
specification in your application. If needed you can specify a Pyramid permission or
custom callable (script_generator argument) to override the default JavaScript
configuration of Swagger UI.
The default URL for the explorer is /api-explorer. This setting is controlled
via the explorer_route_path argument.
Running tests
pip install -e .[dev]
tox
Release files for pyramid-apispec 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyramid_apispec-0.1.4.tar.gz | 8.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyramid_apispec-0.1.4-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 18.2 kB
Release files / pyramid_apispec-0.1.4.tar.gz
| Download URL | pyramid_apispec-0.1.4.tar.gz |
|---|---|
| Size | 8.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e47048e383f2f5ce5c3c60ef2d2ba20b6cf795adc06377a584af190c5d6099e5
|
|
BLAKE2b-256 checksum How to use checksums |
fe78535a3061e732ae19266ac4f8c69d282d1002961fb4b65d6ad86371e03a11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / pyramid_apispec-0.1.4-py2.py3-none-any.whl
| Download URL | pyramid_apispec-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
aa96b7799671453060d7d0bafb21105bd7849c4f8c3e2fe8fe46b0d465fdd75c
|
|
BLAKE2b-256 checksum How to use checksums |
0307acab350df2abccda3e471e3065b124d320b0b17652387b19866532a4888f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |