Home

Awesome

<a id="top"></a>

<p align="center"> <img src="https://raw.githubusercontent.com/spec-first/connexion/main/docs/images/logo_banner.svg" width="100%"/> </p> <p align="center"> <a href="https://pypi.org/project/connexion"><img alt="coveralls" src="https://img.shields.io/pypi/status/connexion.svg?style=flat-square&color=brightgreen"></a> <a href="https://pypi.org/project/connexion"><img alt="PyPI version" src="https://img.shields.io/pypi/v/connexion?color=brightgreen&style=flat-square"></a> <a href="https://pypistats.org/packages/connexion"><img alt="PyPI" src="https://img.shields.io/pypi/dm/connexion?style=flat-square&color=brightgreen"></a> <a href="https://github.com/spec-first/connexion/blob/main/LICENSE"><img alt="License" src="https://img.shields.io/pypi/l/connexion?style=flat-square&color=brightgreen"></a> <a href="https://github.com/spec-first/connexion/actions/workflows/pipeline.yml"><img alt="GitHub Workflow Status" src="https://img.shields.io/github/actions/workflow/status/spec-first/connexion/pipeline.yml?style=flat-square"></a> <a href="https://coveralls.io/github/spec-first/connexion?branch=main"><img alt="Coveralls" src="https://img.shields.io/coverallsCoverage/github/spec-first/connexion?style=flat-square"></a> <a href="https://gurubase.io/g/connexion"><img alt="Gurubase" src="https://img.shields.io/badge/Gurubase-Ask%20Connexion%20Guru-brightgreen?style=flat-square"></a> <br> <br> <a href="https://connexion.readthedocs.io/en/stable/"><strong>Explore the docs ยป</strong></a> </p>

Connexion is a modern Python web framework that makes spec-first and api-first development easy. You describe your API in an OpenAPI (or Swagger) specification with as much detail as you want and Connexion will guarantee that it works as you specified.

It works either standalone, or in combination with any ASGI or WSGI-compatible framework!

<p align="center"> <br> <a href="https://connexion.readthedocs.io/en/latest/v3.html"><strong>๐Ÿ“ข Connexion 3 was recently released! Read about the changes here ยป</strong></a> <br> <br> </p>

โœจ Features

Connexion provides the following functionality based on your specification:

Connexion also helps you write your OpenAPI specification and develop against it by providing a command line interface which lets you test and mock your specification.

   connexion run openapi.yaml
<p align="right">(<a href="#top">back to top</a>)</p>

๐Ÿซถ Sponsors

<a href="https://www.ml6.eu"><img src="https://raw.githubusercontent.com/spec-first/connexion/main/docs/images/sponsors/ML6.png" title=ML6 height="100"></a> <a href="https://www.devmark.ai/fern/?utm_source=connexion&utm_loc=readme&utm_type=logo"><img src="https://raw.githubusercontent.com/spec-first/connexion/main/docs/images/sponsors/Fern.png" title=Fern height="100"></a>

Sponsors help us dedicate time to maintain Connexion. Want to help?

<a href="https://github.com/sponsors/spec-first"><strong>Explore the options ยป</strong></a>

<p align="right">(<a href="#top">back to top</a>)</p>

๐Ÿชค Why Connexion

With Connexion, you write the spec first. Connexion then calls your Python code, handling the mapping from the specification to the code. This incentivizes you to write the specification so that all of your developers can understand what your API does, even before you write a single line of code.

If multiple teams depend on your APIs, you can use Connexion to easily send them the documentation of your API. This guarantees that your API will follow the specification that you wrote. This is a different process from the one offered by most frameworks, which generate a specification after you've written the code. Some disadvantages of generating specifications based on code is that they often end up lacking details or mix your documentation with the implementation logic of your application.

<p align="right">(<a href="#top">back to top</a>)</p>

โš’๏ธ How to Use

Installation

You can install connexion using pip:

    $ pip install connexion

Connexion provides 'extras' with optional dependencies to unlock additional features:

You can install them as follows:

    $ pip install connexion[swagger-ui]
    $ pip install connexion[swagger-ui,uvicorn]
<p align="right">(<a href="#top">back to top</a>)</p>

Creating your application

Connexion can be used either as a standalone application or as a middleware wrapping an existing ASGI (or WSGI) application written using a different framework. The standalone application can be built using either the AsyncApp or FlaskApp.

<p align="right">(<a href="#top">back to top</a>)</p>

Registering an API

While you can register individual routes on your application, Connexion really shines when you register an API defined by an OpenAPI (or Swagger) specification. The operation described in your specification is automatically linked to your Python view function via the operationId

run.py

   def post_greeting(name: str, greeting: str):  # Paramaeters are automatically unpacked
       return f"{greeting} {name}", 200          # Responses are automatically serialized

   app.add_api("openapi.yaml")

openapi.yaml

   ...
   paths:
     /greeting/{name}:
       post:
         operationId: run.post_greeting
         responses:
           '200':
             content:
               text/plain:
                 schema:
                   type: string
         parameters:
           - name: name
             in: path
             required: true
             schema:
               type: string
           - name: greeting
             in: query
             required: true
             schema:
               type: string
<p align="right">(<a href="#top">back to top</a>)</p>

Running your application

If you installed connexion using connexion[uvicorn], you can run it using the run method. This is only recommended for development:

    app.run()

In production, run your application using an ASGI server such as uvicorn. If you defined your app in a python module called run.py, you can run it as follows:

    $ uvicorn run:app

Or with gunicorn:

    $ gunicorn -k uvicorn.workers.UvicornWorker run:app

Now you're able to run and use Connexion!

See the examples folder for more examples.

<p align="right">(<a href="#top">back to top</a>)</p>

๐Ÿ“œ Changes

A full changelog is maintained on the GitHub releases page.

<p align="right">(<a href="#top">back to top</a>)</p>

๐Ÿคฒ Contributing

We welcome your ideas, issues, and pull requests. Just follow the usual/standard GitHub practices.

For easy development, install connexion using poetry with all extras, and install the pre-commit hooks to automatically run black formatting and static analysis checks.

    pip install poetry
    poetry install --all-extras
    pre-commit install

You can find out more about how Connexion works and where to apply your changes by having a look at our architecture.

Unless you explicitly state otherwise in advance, any non trivial contribution intentionally submitted for inclusion in this project by you to the steward of this repository shall be under the terms and conditions of Apache License 2.0 written below, without any additional copyright information, terms or conditions.

<p align="right">(<a href="#top">back to top</a>)</p>

๐Ÿ™ Thanks

We'd like to thank all of Connexion's contributors for working on this project, Swagger/OpenAPI for their support, and Zalando for originally developing and releasing Connexion.

๐Ÿ“š Recommended Resources

About the advantages of working spec-first:

Tools to help you work spec-first: