Skip to main content

Sphinx plugin which renders a OpenAPI specification with Swagger

Project description

REUSE status Code style: black Coverage Status

Swagger Plugin for Sphinx

This is a handy plugin to bring Swagger and Sphinx together.

It can generate one or multiple swagger HTML pages with a custom configuration that hosts an OpenAPI specification.

Install

Just run pip install swagger-plugin-for-sphinx

Usage

Enable the Plugin

First, add the plugin to the extensions list:

extensions = ["swagger_plugin_for_sphinx"]

Global Configuration

Swagger uses two JavaScript and one CSS file to render the output. These can be set in conf.py:

swagger_present_uri = ""
swagger_bundle_uri = ""
swagger_css_uri = ""

These correspond to the modules explained here. By default, the latest release is used from here.

Optionally if you do now want to redirect users to the mirror but prefer local serving you can mirror the Swagger dependencies into the generated doctree in conf.py via:

swagger_mirror_external_resources = True

Directive

To include a Swagger API specification into an HTML page specify the swagger-plugin directive and the relative path to the specification:

.. swagger-plugin:: path/to/spec.yaml

The spec is automatically copied into the _static build output directory.

The directive supports the following options

  • id: specifies an unique ID for the specification per page (see below)
  • full-page: if set, all other content on the page is dropped and only the Swagger part is rendered
  • page-title: the name of the HTML page if full-page is specified
  • swagger-options: JSON string that is passed to Swagger to enable additional options as described on the configuration page of the Swagger documentation.

By default, the directive creates a <div> element with the ID swagger-ui-container. If you put more than one swagger-plugin directive in a file, specify unique IDs:

.. swagger-plugin:: path/to/one.yaml
   :id: spec-one

.. swagger-plugin:: path/to/two.yaml
   :id: spec-two

Development

This project uses uv. To install uv, and setup a venv for development, use:

python3.14 -m venv venv && \
    source venv/bin/activate && \
    pip install uv && uv sync --all-groups && \
    deactivate  && \
    rm -rf venv/

This will create a temporary venv, install uv to bootstrap the project .venv, and remove the temporary venv again. Then use source .venv/bin/activate to activate your venv.

Build and Publish

Execute the release action with the proper version.

Support, Feedback, Contributing

This project is open to feature requests/suggestions, bug reports etc., via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright 2025 SAP SE or an SAP affiliate company and swagger-plugin-for-sphinx contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

Project details


Download files

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

Source Distribution

swagger_plugin_for_sphinx-7.2.1.tar.gz (121.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swagger_plugin_for_sphinx-7.2.1-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file swagger_plugin_for_sphinx-7.2.1.tar.gz.

File metadata

File hashes

Hashes for swagger_plugin_for_sphinx-7.2.1.tar.gz
Algorithm Hash digest
SHA256 6387af0489087f7c3e9806b7c14a10abe2b78b417f660adbe503ec21e8dbe860
MD5 3fc704e8a6d0ad073a4245ce8f063b07
BLAKE2b-256 f1344cf23d045435f598c556f017b296b5ee017bb2fd03eecf044c3a8243fff1

See more details on using hashes here.

Provenance

The following attestation bundles were made for swagger_plugin_for_sphinx-7.2.1.tar.gz:

Publisher: release.yml on SAP/swagger-plugin-for-sphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file swagger_plugin_for_sphinx-7.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for swagger_plugin_for_sphinx-7.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 125bf3bae5d63fb59afd1595077c2f8b87cefcc1fe8f7813ad72a887ed3664d3
MD5 84e7a5bc00f5246c0a7094991cf3d7ac
BLAKE2b-256 0646daa5f14ec4f5cc21f886b4677e9db342886874f975fe02033a96355e2d85

See more details on using hashes here.

Provenance

The following attestation bundles were made for swagger_plugin_for_sphinx-7.2.1-py3-none-any.whl:

Publisher: release.yml on SAP/swagger-plugin-for-sphinx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page