Skip to main content

**ORIGINAL REPO:** [digium/swagger-py](https://github.com/digium/swagger-py.git)

About
-----

Swagger.py is a Python library for using
`Swagger ` [codet-swaggerpy](https://github.com/Thulebona/codet-swaggerpy.git) __ 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
services.

The `Swagger
specification <https://github.com/wordnik/swagger-core/wiki>`__ defines
how API's may be described using Swagger.

Swagger.py also supports a WebSocket extension, allowing a WebSocket to
be documented, and auto-generated WebSocket client code.

python -v
---------
Python3

Usage
-----

Install the latest release from PyPI.

::

$ sudo pip install codet-swaggerpy

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

::

$ pip install -e ./

API
===

Swagger.py will dynamically build an object model from a Swagger-enabled
RESTful API.

Here is a simple example using the `Asterisk REST
Interface <https://wiki.asterisk.org/wiki/display/AST/Asterisk+12+ARI>`__

.. 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(
"http://localhost:8088/ari/api-docs/resources.json",
http_client=http_client)

ws = ari.events.eventWebsocket(app='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']
ari.channels.answer(channelId=channelId)
ari.channels.play(channelId=channelId,
media='sound:hello-world')
ari.channels.continueInDialplan(channelId=channelId)

swagger-codegen
===============

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 `translate.py` 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``
file.

Development
-----------

The code is documented using `Sphinx <http://sphinx-doc.org/>`__, which
allows `IntelliJ IDEA <http://confluence.jetbrains.net/display/PYH/>`__
to do a better job at inferring types for autocompletion.

To keep things isolated, I also recommend installing (and using)
`virtualenv <http://www.virtualenv.org/>`__.

::

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

`Setuptools <http://pypi.python.org/pypi/setuptools>`__ is used for
building. `Nose <http://nose.readthedocs.org/en/latest/>`__ is used
for unit testing, with the `coverage
<http://nedbatchelder.com/code/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
``cover/index.html``.

::

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



License
-------

Copyright (c) 2013, Digium, Inc. All rights reserved.

Swagger.py is licensed with a `BSD 3-Clause
License <http://opensource.org/licenses/BSD-3-Clause>`__.

Release files for codet-swaggerpy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codet-swaggerpy 0.2.1
File Size Uploaded
codet-swaggerpy-0.2.1.tar.gz 21.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codet-swaggerpy 0.2.1
File Interpreter ABI Platform
codet_swaggerpy-0.2.1-py3.5.egg Legacy Egg format - - Details

Total release size: 50.9 kB

Release files / codet-swaggerpy-0.2.1.tar.gz

Download URL codet-swaggerpy-0.2.1.tar.gz
Size 21.1 kB
Tags Source
SHA-256 checksum
How to use checksums
547b2a66b1eb82bed13db4e3fb03f77c0bb0f4afbfeff87bf42a97ff322d9e51
BLAKE2b-256 checksum
How to use checksums
b8c3ede3991ade683c69c4ffe5b5717da637f22679012709817ca5768297e527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / codet_swaggerpy-0.2.1-py3.5.egg

Download URL codet_swaggerpy-0.2.1-py3.5.egg
Size 29.8 kB
Tags Egg
SHA-256 checksum
How to use checksums
0e2660e220059f82d739dbdd38966cca7f91ace65f9e8f8035b2bd880d5f631e
BLAKE2b-256 checksum
How to use checksums
b9c18c1f5d9f4aaa29b9f53ba57b71d73d2ac387134dd89145abc7fb95716dd1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page