百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

connexion-example

> 编程语言
开源

使用 Connexion Swagger-first Python 库的 REST 服务示例: 包括模式验证和 OAuth 2

200 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

使用 Connexion Swagger-first Python 库的 REST 服务示例: 包括模式验证和 OAuth 2

============================== Connexion Example REST Service

This example application implements a very basic "pet shop" REST service using the Connexion_ Python library.

Connexion is a framework on top of Flask_ to automagically handle your REST API requests based on Swagger 2.0 Specification_ files in YAML.

Please also have a look at the Connexion Example with Redis database and Kubernetes deployment manifests_.

Features

This example application shows various features supported by the Connexion library:

  • mapping of REST operations to Python functions (using the operationId in swagger.yaml)

    • maps path, query and body parameters to keyword arguments
  • bundled Swagger UI (served on /ui/_ path)

  • automatic JSON serialization for application/json content type

  • schema validation for the HTTP request body and query parameters:

    • required object properties
    • primitive JSON types (string, integers, etc)
    • date/time values
    • string lengths
    • minimum/maximum values
    • regular expression patterns
  • gevent WSGI server

  • OAuth2 protection

Files

The example application only needs very few files:

  • swagger.yaml: the pet shop REST API Swagger definition
  • app.py: implementation of the pet shop operations with in-memory storage
  • Pipfile: list of required Python libraries (used by Pipenv)
  • Dockerfile: to build the example as a runnable Docker image
  • test.sh: shell script to execute example HTTP requests against the pet shop API

Running Locally

You can run the Python application directly on your local operating system (this requires Python 3 and Pipenv _):

.. code-block:: bash

$ pipenv install --dev && pipenv shell
$ ./app.py # start the HTTP server
$ xdg-open http://localhost:8080/ui/
$ ./test.sh # do some test HTTP requests

Running with Docker

You can build the example application as a Docker image and run it:

.. code-block:: bash

$ docker build -t connexion-example .
$ docker run -d -p 8080:8080 connexion-example
$ ./test.sh # do some test HTTP requests

Using OAuth2 Security

To enable OAuth2 security (token verification), you need to pass the URL to the "tokeninfo" endpoint:

.. code-block:: bash

$ docker run -d -p 8080:8080 -e HTTP_TOKENINFO_URL=https://auth.example.org/tokeninfo connexion-example

Using Connexion with a WSGI container

You can use the Flask WSGI app with any WSGI container, e.g. using Flask with uWSGI_:

.. code-block:: bash

$ sudo pip3 install uwsgi
$ uwsgi --http :8080 -w app

You can run uwsgi with a large number of worker processes to get high concurrency. This obviously makes no sense for the in-memory pet store example (every worker would have its own pet store dictionary):

.. code-block:: bash

$ uwsgi --http :8080 -w app -p 16  # use 16 worker processes

See the uWSGI documentation_ for more information.

.. _Connexion: https://pypi.python.org/pypi/connexion .. _Flask: http://flask.pocoo.org/ .. _Swagger 2.0 Specification: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md .. _/ui/: http://localhost:8080/ui/ .. _using Flask with uWSGI: http://flask.pocoo.org/docs/latest/deploying/uwsgi/ .. _uWSGI documentation: https://uwsgi-docs.readthedocs.org/ .. _Connexion Example with Redis database and Kubernetes deployment manifests: https://github.com/hjacobs/connexion-example-redis-kubernetes

Issues· 4 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Python

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言