Skip to main content

Library for accessing Swagger-enabled API's

Project description

**ORIGINAL REPO:** [digium/swagger-py](

----- is a Python library for using
`Swagger ` [codet-swaggerpy]( __ defined API's.

Swagger itself is best described on the Swagger home page:

Swagger is a specification and complete framework implementation for
describing, producing, consuming, and visualizing RESTful web

The `Swagger
specification <>`__ defines
how API's may be described using Swagger. also supports a WebSocket extension, allowing a WebSocket to
be documented, and auto-generated WebSocket client code.

python -v


Install the latest release from PyPI.


$ sudo pip install codet-swaggerpy

Or install from source using the ```` script.


$ pip install -e ./

=== will dynamically build an object model from a Swagger-enabled

Here is a simple example using the `Asterisk REST
Interface <>`__

.. code:: Python

#!/usr/bin/env python

import json

from swaggerpy.client import SwaggerClient
from swaggerpy.http_client import SynchronousHttpClient

http_client = SynchronousHttpClient()
http_client.set_basic_auth('localhost', 'hey', 'peekaboo')

ari = SwaggerClient(

ws ='hello')

for msg_str in iter(lambda: ws.recv(), None):
msg_json = json.loads(msg_str)
if msg_json['type'] == 'StasisStart':
channelId = msg_json['channel']['id']


There are the beginnings of a Mustache-based code generator, but it's
not functional... yet.

.. Inspired by the original [swagger-codegen][] project, templates are
written using [Mustache][] templates ([Pystache][], specifically).
There are several important differences.

* The model that is fed into the mustache templates is almost
identical to Swagger's API resource listing and API declaration
model. The differences are listed [below](#model).
* The templates themselves are completely self contained, with the
logic to enrich the model being specified in `` in the
same directory as the `*.mustache` files.

Data model

The data model presented by the ``swagger_model`` module is nearly
identical to the original Swagger API resource listing and API
declaration. This means that if you add extra custom metadata to your
docs (such as a ``_author`` or ``_copyright`` field), they will carry
forward into the object model. I recommend prefixing custom fields with
an underscore, to avoid collisions with future versions of Swagger.

There are a few meaningful differences.

- Resource listing
- The ``file`` and ``base_dir`` fields have been added, referencing the
original ``.json`` file.
- The objects in a ``resource_listing``'s ``api`` array contains a
field ``api_declaration``, which is the processed result from the
referenced API doc.
- API declaration
- A ``file`` field has been added, referencing the original ``.json``


The code is documented using `Sphinx <>`__, which
allows `IntelliJ IDEA <>`__
to do a better job at inferring types for autocompletion.

To keep things isolated, I also recommend installing (and using)
`virtualenv <>`__.


$ sudo pip install virtualenv
$ mkdir -p ~/virtualenv
$ virtualenv ~/virtualenv/swagger
$ . ~/virtualenv/swagger/bin/activate

`Setuptools <>`__ is used for
building. `Nose <>`__ is used
for unit testing, with the `coverage
<>`__ plugin installed to
generated code coverage reports. Pass ``--with-coverage`` to generate
the code coverage report. HTML versions of the reports are put in


$ ./ develop # prep for development (install deps, launchers, etc.)
$ ./ test # run unit tests
$ ./ bdist_egg # build distributable


Copyright (c) 2013, Digium, Inc. All rights reserved. is licensed with a `BSD 3-Clause
License <>`__.

Project details

Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
codet_swaggerpy-0.2.1-py3.5.egg (29.8 kB) Copy SHA256 hash SHA256 Egg 3.5
codet-swaggerpy-0.2.1.tar.gz (21.1 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page