Connexion is a modern Python web framework that facilitates API-first development using OpenAPI (formerly Swagger) specifications. It automatically handles routing, request validation, authentication, parameter parsing, and response serialization based on your specification. Version 3.3.0 is the latest stable release, offering a modular, ASGI-compatible architecture with support for both Flask (WSGI) and Starlette (ASGI) backends. The library maintains an active release cadence, frequently publishing updates and new features.
pip install connexionVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple 'Hello World' API using Connexion's `AsyncApp` (ASGI backend). It defines an API using an `openapi.yaml` specification file and links an operation to a Python function. The application can be run using `uvicorn` (e.g., `uvicorn app:app --reload` from the command line, assuming the Python file is named `app.py`). Ensure `openapi.yaml` is in the same directory as `app.py`.
For new projects, use `connexion.AsyncApp` and `pip install connexion[starlette]`. For migrating from 2.x, consider switching to `AsyncApp` or explicitly use `connexion.FlaskApp` and `pip install connexion[flask]`. Review the official migration guide for detailed steps.
Adjust code that directly accesses `connexion.request` attributes to be compatible with Starlette's `Request` object if using `AsyncApp`. If relying on Flask-specific request features, ensure you are using `FlaskApp`.
Upgrade your Python environment to 3.9 or higher. The current PyPI metadata indicates `>=3.9, <4.0`.
Update your application initialization to pass `uri_parser_class` and `jsonifier` directly as keyword arguments: `app = AsyncApp(__name__, uri_parser_class=MyParser, jsonifier=MyJsonifier)` or `app.add_api('spec.yaml', uri_parser_class=MyParser)`.Ensure your API implementation explicitly returns data in the format matching one of the declared content types in your OpenAPI specification, especially for endpoints with multiple `produces` entries.
Ensure that the OpenAPI specification file exists at the path provided to `app.add_api()` and is accessible by the application. Verify the file path is correct relative to the application's working directory or use an absolute path.
Update your import statements to reflect the new Connexion 3.x structure, for example, use `from connexion import FlaskApp` instead of `from connexion.apps.flask_app import FlaskApp`. Ensure `connexion` is installed with the `flask` extra: `pip install 'connexion[flask]'`.
For request bodies, add the `x-body-name: <parameter_name>` extension to your OpenAPI `requestBody` schema to explicitly name the parameter that Connexion should pass to your handler function. Ensure parameter names in your Python function signature exactly match those defined in the OpenAPI spec.
Carefully check the `operationId` in your OpenAPI specification for typos and ensure it exactly matches the Python function name. Verify that the Python module path (specified in `x-swagger-router-controller` or derived from `operationId`) is correct and resolvable from your application's execution context, and that the function is indeed defined and importable within that module.
Ensure your `connexion.FlaskApp` instance is assigned to a top-level variable named `app` or `application` in your main application module (e.g., `app = connexion.FlaskApp(__name__)`). Alternatively, set the `FLASK_APP` environment variable to point to your specific application instance (e.g., `export FLASK_APP=your_module:your_app_instance_name`).