METADATA 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. Metadata-Version: 2.1
  2. Name: connexion
  3. Version: 2.14.2
  4. Summary: Connexion - API first applications with OpenAPI/Swagger and Flask
  5. Home-page: https://github.com/zalando/connexion
  6. Author: Zalando SE
  7. License: Apache License Version 2.0
  8. Keywords: openapi oai swagger rest api oauth flask microservice framework
  9. Platform: UNKNOWN
  10. Classifier: Programming Language :: Python
  11. Classifier: Programming Language :: Python :: 3.6
  12. Classifier: Programming Language :: Python :: 3.7
  13. Classifier: Programming Language :: Python :: 3.8
  14. Classifier: Programming Language :: Python :: 3.9
  15. Classifier: Development Status :: 5 - Production/Stable
  16. Classifier: Intended Audience :: Developers
  17. Classifier: Operating System :: OS Independent
  18. Classifier: Topic :: Internet :: WWW/HTTP :: WSGI :: Application
  19. Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
  20. Requires-Python: >=3.6
  21. License-File: LICENSE.txt
  22. Requires-Dist: clickclick (<21,>=1.2)
  23. Requires-Dist: jsonschema (<5,>=2.5.1)
  24. Requires-Dist: PyYAML (<7,>=5.1)
  25. Requires-Dist: requests (<3,>=2.9.1)
  26. Requires-Dist: inflection (<0.6,>=0.3.1)
  27. Requires-Dist: werkzeug (<2.3,>=1.0)
  28. Requires-Dist: packaging (>=20)
  29. Requires-Dist: flask (<2.3,>=1.0.4)
  30. Requires-Dist: itsdangerous (>=0.24)
  31. Requires-Dist: importlib-metadata (>=1) ; python_version < "3.8"
  32. Provides-Extra: aiohttp
  33. Requires-Dist: aiohttp (<4,>=2.3.10) ; extra == 'aiohttp'
  34. Requires-Dist: aiohttp-jinja2 (<2,>=0.14.0) ; extra == 'aiohttp'
  35. Requires-Dist: MarkupSafe (>=0.23) ; extra == 'aiohttp'
  36. Provides-Extra: docs
  37. Requires-Dist: sphinx-autoapi (==1.8.1) ; extra == 'docs'
  38. Provides-Extra: flask
  39. Requires-Dist: flask (<2.3,>=1.0.4) ; extra == 'flask'
  40. Requires-Dist: itsdangerous (>=0.24) ; extra == 'flask'
  41. Provides-Extra: swagger-ui
  42. Requires-Dist: swagger-ui-bundle (<0.1,>=0.0.2) ; extra == 'swagger-ui'
  43. Provides-Extra: tests
  44. Requires-Dist: decorator (<6,>=5) ; extra == 'tests'
  45. Requires-Dist: pytest (<7,>=6) ; extra == 'tests'
  46. Requires-Dist: pytest-cov (<3,>=2) ; extra == 'tests'
  47. Requires-Dist: testfixtures (<7,>=6) ; extra == 'tests'
  48. Requires-Dist: flask (<2.3,>=1.0.4) ; extra == 'tests'
  49. Requires-Dist: itsdangerous (>=0.24) ; extra == 'tests'
  50. Requires-Dist: swagger-ui-bundle (<0.1,>=0.0.2) ; extra == 'tests'
  51. Requires-Dist: aiohttp (<4,>=2.3.10) ; extra == 'tests'
  52. Requires-Dist: aiohttp-jinja2 (<2,>=0.14.0) ; extra == 'tests'
  53. Requires-Dist: MarkupSafe (>=0.23) ; extra == 'tests'
  54. Requires-Dist: pytest-aiohttp ; extra == 'tests'
  55. Requires-Dist: aiohttp-remotes ; extra == 'tests'
  56. Connexion
  57. =========
  58. .. image:: https://badges.gitter.im/zalando/connexion.svg
  59. :alt: Join the chat at https://gitter.im/zalando/connexion
  60. :target: https://gitter.im/zalando/connexion?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge
  61. .. image:: https://github.com/zalando/connexion/actions/workflows/pipeline.yml/badge.svg
  62. :alt: Build status
  63. :target: https://github.com/zalando/connexion/actions/workflows/pipeline.yml
  64. .. image:: https://coveralls.io/repos/github/zalando/connexion/badge.svg?branch=main
  65. :target: https://coveralls.io/github/zalando/connexion?branch=main
  66. :alt: Coveralls status
  67. .. image:: https://img.shields.io/pypi/v/connexion.svg
  68. :target: https://pypi.python.org/pypi/connexion
  69. :alt: Latest Version
  70. .. image:: https://img.shields.io/pypi/status/connexion.svg
  71. :target: https://pypi.python.org/pypi/connexion
  72. :alt: Development Status
  73. .. image:: https://img.shields.io/pypi/pyversions/connexion.svg
  74. :target: https://pypi.python.org/pypi/connexion
  75. :alt: Python Versions
  76. .. image:: https://img.shields.io/pypi/l/connexion.svg
  77. :target: https://github.com/zalando/connexion/blob/main/LICENSE.txt
  78. :alt: License
  79. Connexion is a framework that automagically handles HTTP requests based on `OpenAPI Specification`_
  80. (formerly known as Swagger Spec) of your API described in `YAML format`_. Connexion allows you to
  81. write an OpenAPI specification, then maps the endpoints to your Python functions; this makes it
  82. unique, as many tools generate the specification based on your Python code. You can describe your
  83. REST API in as much detail as you want; then Connexion guarantees that it will work as you
  84. specified.
  85. We built Connexion this way in order to:
  86. - simplify the development process
  87. - confirm expectations about what your API will look like
  88. Connexion Features:
  89. -------------------
  90. - Validates requests and endpoint parameters automatically, based on
  91. your specification
  92. - Provides a Web Swagger Console UI so that the users of your API can
  93. have live documentation and even call your API's endpoints
  94. through it
  95. - Handles OAuth 2 token-based authentication
  96. - Supports API versioning
  97. - Supports automatic serialization of payloads. If your
  98. specification defines that an endpoint returns JSON, Connexion will
  99. automatically serialize the return value for you and set the right
  100. content type in the HTTP header.
  101. Why Connexion
  102. -------------
  103. With Connexion, you write the spec first. Connexion then calls your Python
  104. code, handling the mapping from the specification to the code. This
  105. incentivizes you to write the specification so that all of your
  106. developers can understand what your API does, even before you write a
  107. single line of code.
  108. 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 that offered by frameworks such as Hug_, which generates 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 code logic of your application.
  109. Other Sources/Mentions
  110. ----------------------
  111. - Zalando RESTful API guidelines with `API First`_
  112. - Connexion listed on Swagger_'s website
  113. - Blog post: `Crafting effective Microservices in Python`_
  114. New in Connexion 2.0:
  115. ---------------------
  116. - App and Api options must be provided through the "options" argument (``old_style_options`` have been removed).
  117. - You must specify a form content-type in 'consumes' in order to consume form data.
  118. - The `Operation` interface has been formalized in the `AbstractOperation` class.
  119. - The `Operation` class has been renamed to `Swagger2Operation`.
  120. - Array parameter deserialization now follows the Swagger 2.0 spec more closely.
  121. In situations when a query parameter is passed multiple times, and the collectionFormat is either csv or pipes, the right-most value will be used.
  122. For example, `?q=1,2,3&q=4,5,6` will result in `q = [4, 5, 6]`.
  123. The old behavior is available by setting the collectionFormat to `multi`, or by importing `decorators.uri_parsing.AlwaysMultiURIParser` and passing `parser_class=AlwaysMultiURIParser` to your Api.
  124. - The spec validator library has changed from `swagger-spec-validator` to `openapi-spec-validator`.
  125. - Errors that previously raised `SwaggerValidationError` now raise the `InvalidSpecification` exception.
  126. All spec validation errors should be wrapped with `InvalidSpecification`.
  127. - Support for nullable/x-nullable, readOnly and writeOnly/x-writeOnly has been added to the standard json schema validator.
  128. - Custom validators can now be specified on api level (instead of app level).
  129. - Added support for basic authentication and apikey authentication
  130. - If unsupported security requirements are defined or ``x-tokenInfoFunc``/``x-tokenInfoUrl`` is missing, connexion now denies requests instead of allowing access without security-check.
  131. - Accessing ``connexion.request.user`` / ``flask.request.user`` is no longer supported, use ``connexion.context['user']`` instead
  132. How to Use
  133. ==========
  134. Prerequisites
  135. -------------
  136. Python 3.6+
  137. Installing It
  138. -------------
  139. In your command line, type:
  140. .. code-block:: bash
  141. $ pip install connexion
  142. Running It
  143. ----------
  144. Place your API YAML inside a folder in the root
  145. path of your application (e.g ``swagger/``). Then run:
  146. .. code-block:: python
  147. import connexion
  148. app = connexion.App(__name__, specification_dir='swagger/')
  149. app.add_api('my_api.yaml')
  150. app.run(port=8080)
  151. See the `Connexion Pet Store Example Application`_ for a sample
  152. specification.
  153. Now you're able to run and use Connexion!
  154. OAuth 2 Authentication and Authorization
  155. ----------------------------------------
  156. Connexion supports one of the three OAuth 2 handling methods. (See
  157. "TODO" below.) With Connexion, the API security definition **must**
  158. include a 'x-tokenInfoUrl' or 'x-tokenInfoFunc (or set ``TOKENINFO_URL``
  159. or ``TOKENINFO_FUNC`` env var respectively). 'x-tokenInfoUrl' must contain an
  160. URL to validate and get the `token information`_ and 'x-tokenInfoFunc must
  161. contain a reference to a function used to obtain the token info. When both 'x-tokenInfoUrl'
  162. and 'x-tokenInfoFunc' are used, Connexion will prioritize the function method. Connexion expects to
  163. receive the OAuth token in the ``Authorization`` header field in the
  164. format described in `RFC 6750 <rfc6750_>`_ section 2.1. This aspect
  165. represents a significant difference from the usual OAuth flow.
  166. Dynamic Rendering of Your Specification
  167. ---------------------------------------
  168. Connexion uses Jinja2_ to allow specification parameterization through the ``arguments`` parameter. You can define specification arguments for the application either globally (via the ``connexion.App`` constructor) or for each specific API (via the ``connexion.App#add_api`` method):
  169. .. code-block:: python
  170. app = connexion.App(__name__, specification_dir='swagger/',
  171. arguments={'global': 'global_value'})
  172. app.add_api('my_api.yaml', arguments={'api_local': 'local_value'})
  173. app.run(port=8080)
  174. When a value is provided both globally and on the API, the API value will take precedence.
  175. Endpoint Routing to Your Python Views
  176. -------------------------------------
  177. Connexion uses the ``operationId`` from each `Operation Object`_ to
  178. identify which Python function should handle each URL.
  179. **Explicit Routing**:
  180. .. code-block:: yaml
  181. paths:
  182. /hello_world:
  183. post:
  184. operationId: myapp.api.hello_world
  185. If you provide this path in your specification POST requests to
  186. ``http://MYHOST/hello_world``, it will be handled by the function
  187. ``hello_world`` in the ``myapp.api`` module. Optionally, you can include
  188. ``x-swagger-router-controller`` (or ``x-openapi-router-controller``) in your
  189. operation definition, making ``operationId`` relative:
  190. .. code-block:: yaml
  191. paths:
  192. /hello_world:
  193. post:
  194. x-swagger-router-controller: myapp.api
  195. operationId: hello_world
  196. Keep in mind that Connexion follows how `HTTP methods work in Flask`_ and therefore HEAD requests will be handled by the ``operationId`` specified under GET in the specification. If both methods are supported, ``connexion.request.method`` can be used to determine which request was made.
  197. Automatic Routing
  198. -----------------
  199. To customize this behavior, Connexion can use alternative
  200. ``Resolvers``--for example, ``RestyResolver``. The ``RestyResolver``
  201. will compose an ``operationId`` based on the path and HTTP method of
  202. the endpoints in your specification:
  203. .. code-block:: python
  204. from connexion.resolver import RestyResolver
  205. app = connexion.App(__name__)
  206. app.add_api('swagger.yaml', resolver=RestyResolver('api'))
  207. .. code-block:: yaml
  208. paths:
  209. /:
  210. get:
  211. # Implied operationId: api.get
  212. /foo:
  213. get:
  214. # Implied operationId: api.foo.search
  215. post:
  216. # Implied operationId: api.foo.post
  217. '/foo/{id}':
  218. get:
  219. # Implied operationId: api.foo.get
  220. put:
  221. # Implied operationId: api.foo.put
  222. copy:
  223. # Implied operationId: api.foo.copy
  224. delete:
  225. # Implied operationId: api.foo.delete
  226. ``RestyResolver`` will give precedence to any ``operationId`` encountered in the specification. It will also respect
  227. ``x-router-controller``. You can import and extend ``connexion.resolver.Resolver`` to implement your own ``operationId``
  228. (and function) resolution algorithm.
  229. Automatic Parameter Handling
  230. ----------------------------
  231. Connexion automatically maps the parameters defined in your endpoint specification to arguments of your Python views as named parameters, and, whenever possible, with value casting. Simply define the endpoint's parameters with the same names as your views arguments.
  232. As an example, say you have an endpoint specified as:
  233. .. code-block:: yaml
  234. paths:
  235. /foo:
  236. get:
  237. operationId: api.foo_get
  238. parameters:
  239. - name: message
  240. description: Some message.
  241. in: query
  242. type: string
  243. required: true
  244. And the view function:
  245. .. code-block:: python
  246. # api.py file
  247. def foo_get(message):
  248. # do something
  249. return 'You send the message: {}'.format(message), 200
  250. In this example, Connexion automatically recognizes that your view
  251. function expects an argument named ``message`` and assigns the value
  252. of the endpoint parameter ``message`` to your view function.
  253. .. note:: In the OpenAPI 3.x.x spec, the requestBody does not have a name.
  254. By default it will be passed in as 'body'. You can optionally
  255. provide the x-body-name parameter in your requestBody
  256. (or legacy position within the requestBody schema)
  257. to override the name of the parameter that will be passed to your
  258. handler function.
  259. .. code-block:: yaml
  260. /path
  261. post:
  262. requestBody:
  263. x-body-name: body
  264. content:
  265. application/json:
  266. schema:
  267. # legacy location here should be ignored because the preferred location for x-body-name is at the requestBody level above
  268. x-body-name: this_should_be_ignored
  269. $ref: '#/components/schemas/someComponent'
  270. .. warning:: When you define a parameter at your endpoint as *not* required, and
  271. this argument does not have default value in your Python view, you will get
  272. a "missing positional argument" exception whenever you call this endpoint
  273. WITHOUT the parameter. Provide a default value for a named argument or use
  274. ``**kwargs`` dict.
  275. Type casting
  276. ^^^^^^^^^^^^
  277. Whenever possible, Connexion will try to parse your argument values and
  278. do type casting to related Python native values. The current
  279. available type castings are:
  280. +--------------+-------------+
  281. | OpenAPI Type | Python Type |
  282. +==============+=============+
  283. | integer | int |
  284. +--------------+-------------+
  285. | string | str |
  286. +--------------+-------------+
  287. | number | float |
  288. +--------------+-------------+
  289. | boolean | bool |
  290. +--------------+-------------+
  291. | array | list |
  292. +--------------+-------------+
  293. | null | None |
  294. +--------------+-------------+
  295. | object | dict |
  296. +--------------+-------------+
  297. If you use the ``array`` type In the Swagger definition, you can define the
  298. ``collectionFormat`` so that it won't be recognized. Connexion currently
  299. supports collection formats "pipes" and "csv". The default format is "csv".
  300. Connexion is opinionated about how the URI is parsed for ``array`` types.
  301. The default behavior for query parameters that have been defined multiple
  302. times is to use the right-most value. For example, if you provide a URI with
  303. the the query string ``?letters=a,b,c&letters=d,e,f``, connexion will set
  304. ``letters = ['d', 'e', 'f']``.
  305. You can override this behavior by specifying the URI parser in the app or
  306. api options.
  307. .. code-block:: python
  308. from connexion.decorators.uri_parsing import AlwaysMultiURIParser
  309. options = {'uri_parser_class': AlwaysMultiURIParser}
  310. app = connexion.App(__name__, specification_dir='swagger/', options=options)
  311. You can implement your own URI parsing behavior by inheriting from
  312. ``connexion.decorators.uri_parsing.AbstractURIParser``.
  313. There are a handful of URI parsers included with connection.
  314. +----------------------+---------------------------------------------------------------------------+
  315. | OpenAPIURIParser | This parser adheres to the OpenAPI 3.x.x spec, and uses the ``style`` |
  316. | default: OpenAPI 3.0 | parameter. Query parameters are parsed from left to right, so if a query |
  317. | | parameter is defined twice, then the right-most definition will take |
  318. | | precedence. For example, if you provided a URI with the query string |
  319. | | ``?letters=a,b,c&letters=d,e,f``, and ``style: simple``, then connexion |
  320. | | will set ``letters = ['d', 'e', 'f']``. For additional information see |
  321. | | `OpenAPI 3.0 Style Values`_. |
  322. +----------------------+---------------------------------------------------------------------------+
  323. | Swagger2URIParser | This parser adheres to the Swagger 2.0 spec, and will only join together |
  324. | default: OpenAPI 2.0 | multiple instance of the same query parameter if the ``collectionFormat`` |
  325. | | is set to ``multi``. Query parameters are parsed from left to right, so |
  326. | | if a query parameter is defined twice, then the right-most definition |
  327. | | wins. For example, if you provided a URI with the query string |
  328. | | ``?letters=a,b,c&letters=d,e,f``, and ``collectionFormat: csv``, then |
  329. | | connexion will set ``letters = ['d', 'e', 'f']`` |
  330. +----------------------+---------------------------------------------------------------------------+
  331. | FirstValueURIParser | This parser behaves like the Swagger2URIParser, except that it prefers |
  332. | | the first defined value. For example, if you provided a URI with the query|
  333. | | string ``?letters=a,b,c&letters=d,e,f`` and ``collectionFormat: csv`` |
  334. | | hen connexion will set ``letters = ['a', 'b', 'c']`` |
  335. +----------------------+---------------------------------------------------------------------------+
  336. | AlwaysMultiURIParser | This parser is backwards compatible with Connexion 1.x. It joins together |
  337. | | multiple instances of the same query parameter. |
  338. +----------------------+---------------------------------------------------------------------------+
  339. Parameter validation
  340. ^^^^^^^^^^^^^^^^^^^^
  341. Connexion can apply strict parameter validation for query and form data
  342. parameters. When this is enabled, requests that include parameters not defined
  343. in the swagger spec return a 400 error. You can enable it when adding the API
  344. to your application:
  345. .. code-block:: python
  346. app.add_api('my_apy.yaml', strict_validation=True)
  347. API Versioning and basePath
  348. ---------------------------
  349. Setting a base path is useful for versioned APIs. An example of
  350. a base path would be the ``1.0`` in ``http://MYHOST/1.0/hello_world``.
  351. If you are using OpenAPI 3.x.x, you set your base URL path in the
  352. servers block of the specification. You can either specify a full
  353. URL, or just a relative path.
  354. .. code-block:: yaml
  355. servers:
  356. - url: https://MYHOST/1.0
  357. description: full url example
  358. - url: /1.0
  359. description: relative path example
  360. paths:
  361. ...
  362. If you are using OpenAPI 2.0, you can define a ``basePath`` on the top level
  363. of your OpenAPI 2.0 specification.
  364. .. code-block:: yaml
  365. basePath: /1.0
  366. paths:
  367. ...
  368. If you don't want to include the base path in your specification, you
  369. can provide it when adding the API to your application:
  370. .. code-block:: python
  371. app.add_api('my_api.yaml', base_path='/1.0')
  372. Swagger JSON
  373. ------------
  374. Connexion makes the OpenAPI/Swagger specification in JSON format
  375. available from either ``swagger.json`` (for OpenAPI 2.0) or
  376. ``openapi.json`` (for OpenAPI 3.x.x) at the base path of the API.
  377. For example, if your base path was ``1.0``, then your spec would be
  378. available at ``/1.0/openapi.json``.
  379. You can disable serving the spec JSON at the application level:
  380. .. code-block:: python
  381. options = {"serve_spec": False}
  382. app = connexion.App(__name__, specification_dir='openapi/',
  383. options=options)
  384. app.add_api('my_api.yaml')
  385. You can also disable it at the API level:
  386. .. code-block:: python
  387. options = {"serve_spec": False}
  388. app = connexion.App(__name__, specification_dir='openapi/')
  389. app.add_api('my_api.yaml', options=options)
  390. HTTPS Support
  391. -------------
  392. When specifying HTTPS as the scheme in the API YAML file, all the URIs
  393. in the served Swagger UI are HTTPS endpoints. The problem: The default
  394. server that runs is a "normal" HTTP server. This means that the
  395. Swagger UI cannot be used to play with the API. What is the correct
  396. way to start a HTTPS server when using Connexion?
  397. One way, `described by Flask`_, looks like this:
  398. .. code-block:: python
  399. from OpenSSL import SSL
  400. context = SSL.Context(SSL.SSLv23_METHOD)
  401. context.use_privatekey_file('yourserver.key')
  402. context.use_certificate_file('yourserver.crt')
  403. app.run(host='127.0.0.1', port='12344',
  404. debug=False/True, ssl_context=context)
  405. However, Connexion doesn't provide an ssl_context parameter. This is
  406. because Flask doesn't, either--but it uses ``**kwargs`` to send the
  407. parameters to the underlying `werkzeug`_ server.
  408. The Swagger UI Console
  409. ----------------------
  410. The Swagger UI for an API is available through pip extras.
  411. You can install it with ``pip install connexion[swagger-ui]``.
  412. It will be served up at ``{base_path}/ui/`` where ``base_path`` is the
  413. base path of the API.
  414. You can disable the Swagger UI at the application level:
  415. .. code-block:: python
  416. app = connexion.App(__name__, specification_dir='openapi/',
  417. options={"swagger_ui": False})
  418. app.add_api('my_api.yaml')
  419. You can also disable it at the API level:
  420. .. code-block:: python
  421. app = connexion.App(__name__, specification_dir='openapi/')
  422. app.add_api('my_api.yaml', options={"swagger_ui": False})
  423. If necessary, you can explicitly specify the path to the directory with
  424. swagger-ui to not use the connexion[swagger-ui] distro.
  425. In order to do this, you should specify the following option:
  426. .. code-block:: python
  427. options = {'swagger_path': '/path/to/swagger_ui/'}
  428. app = connexion.App(__name__, specification_dir='openapi/', options=options)
  429. If you wish to provide your own swagger-ui distro, note that connexion
  430. expects a jinja2 file called ``swagger_ui/index.j2`` in order to load the
  431. correct ``swagger.json`` by default. Your ``index.j2`` file can use the
  432. ``openapi_spec_url`` jinja variable for this purpose:
  433. .. code-block::
  434. const ui = SwaggerUIBundle({ url: "{{ openapi_spec_url }}"})
  435. Additionally, if you wish to use swagger-ui-3.x.x, it is also provided by
  436. installing connexion[swagger-ui], and can be enabled like this:
  437. .. code-block:: python
  438. from swagger_ui_bundle import swagger_ui_3_path
  439. options = {'swagger_path': swagger_ui_3_path}
  440. app = connexion.App(__name__, specification_dir='swagger/', options=options)
  441. Server Backend
  442. --------------
  443. By default Connexion uses the Flask_ server. For asynchronous
  444. applications, you can also use Tornado_ as the HTTP server. To do
  445. this, set your server to ``tornado``:
  446. .. code-block:: python
  447. import connexion
  448. app = connexion.App(__name__, specification_dir='swagger/')
  449. app.run(server='tornado', port=8080)
  450. You can use the Flask WSGI app with any WSGI container, e.g. `using
  451. Flask with uWSGI`_ (this is common):
  452. .. code-block:: python
  453. app = connexion.App(__name__, specification_dir='swagger/')
  454. application = app.app # expose global WSGI application object
  455. You can use the ``aiohttp`` framework as server backend as well:
  456. .. code-block:: python
  457. import connexion
  458. app = connexion.AioHttpApp(__name__, specification_dir='swagger/')
  459. app.run(port=8080)
  460. .. note:: Also check aiohttp handler examples_.
  461. Set up and run the installation code:
  462. .. code-block:: bash
  463. $ sudo pip3 install uwsgi
  464. $ uwsgi --http :8080 -w app -p 16 # use 16 worker processes
  465. See the `uWSGI documentation`_ for more information.
  466. .. _using Flask with uWSGI: http://flask.pocoo.org/docs/latest/deploying/uwsgi/
  467. .. _uWSGI documentation: https://uwsgi-docs.readthedocs.org/
  468. .. _examples: https://docs.aiohttp.org/en/stable/web.html#handler
  469. Documentation
  470. =============
  471. Additional information is available at `Connexion's Documentation Page`_.
  472. Changes
  473. =======
  474. A full changelog is maintained on the `GitHub releases page`_.
  475. .. _GitHub releases page: https://github.com/zalando/connexion/releases
  476. Contributing to Connexion/TODOs
  477. ===============================
  478. We welcome your ideas, issues, and pull requests. Just follow the
  479. usual/standard GitHub practices.
  480. You can find out more about how Connexion works and where to apply your changes by having a look
  481. at our `ARCHITECTURE.rst <ARCHITECTURE.rst>`_.
  482. Unless you explicitly state otherwise in advance, any non trivial
  483. contribution intentionally submitted for inclusion in this project by you
  484. to the steward of this repository (Zalando SE, Berlin) shall be under the
  485. terms and conditions of Apache License 2.0 written below, without any
  486. additional copyright information, terms or conditions.
  487. TODOs
  488. -----
  489. If you'd like to become a more consistent contributor to Connexion, we'd love your help working on
  490. these we have a list of `issues where we are looking for contributions`_.
  491. Thanks
  492. ===================
  493. We'd like to thank all of Connexion's contributors for working on this
  494. project, and to Swagger/OpenAPI for their support.
  495. License
  496. ===================
  497. Copyright 2015 Zalando SE
  498. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
  499. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  500. .. _Flask: http://flask.pocoo.org/
  501. .. _issues waffle board: https://waffle.io/zalando/connexion
  502. .. _API First: https://opensource.zalando.com/restful-api-guidelines/#api-first
  503. .. _Hug: https://github.com/timothycrosley/hug
  504. .. _Swagger: http://swagger.io/open-source-integrations/
  505. .. _Jinja2: http://jinja.pocoo.org/
  506. .. _rfc6750: https://tools.ietf.org/html/rfc6750
  507. .. _OpenAPI Specification: https://www.openapis.org/
  508. .. _OpenAPI 3.0 Style Values: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#style-values
  509. .. _Operation Object: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#operation-object
  510. .. _swager.spec.security_definition: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-definitions-object
  511. .. _swager.spec.security_requirement: https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#security-requirement-object
  512. .. _YAML format: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#format
  513. .. _token information: https://tools.ietf.org/html/rfc6749
  514. .. _Tornado: http://www.tornadoweb.org/en/stable/
  515. .. _Connexion Pet Store Example Application: https://github.com/hjacobs/connexion-example
  516. .. _described by Flask: http://flask.pocoo.org/snippets/111/
  517. .. _werkzeug: http://werkzeug.pocoo.org/
  518. .. _Connexion's Documentation Page: http://connexion.readthedocs.org/en/latest/
  519. .. _Crafting effective Microservices in Python: https://jobs.zalando.com/tech/blog/crafting-effective-microservices-in-python/
  520. .. _issues where we are looking for contributions: https://github.com/zalando/connexion/issues?q=is%3Aissue+is%3Aopen+label%3A%22help+wanted%22
  521. .. _HTTP Methods work in Flask: http://flask.pocoo.org/docs/1.0/quickstart/#http-methods