or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

applications.mdcli.mdexceptions.mdindex.mdoperation-resolution.mdrequest-response.mdsecurity.mdvalidation.md
tile.json

tessl/pypi-connexion

OpenAPI/Swagger spec-first web framework for Python with automatic request validation and response serialization

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/connexion@3.2.x

To install, run

npx @tessl/cli install tessl/pypi-connexion@3.2.0

index.mddocs/

Connexion

Connexion is a Python framework that automagically handles HTTP requests based on OpenAPI Specification (formerly known as Swagger Spec) of your API described in YAML/JSON format. Connexion allows you to write an OpenAPI specification first, then maps the endpoints to your Python functions, making it unique as many tools generate the specification based on your Python code. You can describe your REST API in as much detail as you want; then Connexion guarantees that it will work as you specified.

Package Information

  • Package Name: connexion
  • Language: Python
  • Installation: pip install connexion
  • Extras: pip install connexion[flask] for Flask support, pip install connexion[swagger-ui] for Swagger UI, pip install connexion[uvicorn] for production ASGI server

Core Imports

import connexion

For AsyncApp (recommended for new projects):

from connexion import AsyncApp

For Flask compatibility:

from connexion import FlaskApp

For middleware integration:

from connexion import ConnexionMiddleware

Basic Usage

AsyncApp (Native ASGI)

from connexion import AsyncApp

# Create async application
app = AsyncApp(__name__)

# Add OpenAPI specification
app.add_api('openapi.yaml')

# Run with uvicorn
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)

FlaskApp (WSGI Compatibility)

from connexion import FlaskApp

# Create Flask-based application
app = FlaskApp(__name__)

# Add OpenAPI specification  
app.add_api('openapi.yaml')

# Access underlying Flask app if needed
flask_app = app.app

# Run development server
if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)

ASGI Middleware Integration

from connexion import ConnexionMiddleware
from starlette.applications import Starlette

# Add Connexion to existing ASGI app
asgi_app = Starlette()
app = ConnexionMiddleware(asgi_app)
app.add_api('openapi.yaml')

Architecture

Connexion implements a layered architecture that separates OpenAPI specification handling from the underlying web framework:

  • Application Layer: AsyncApp, FlaskApp provide framework-specific implementations
  • Middleware Layer: Request/response processing, validation, security, routing
  • Operation Layer: Maps OpenAPI operations to Python functions via resolvers
  • Validation Layer: Automatic request/response validation based on OpenAPI schema
  • Security Layer: Built-in authentication/authorization handlers

This design enables spec-first development where the OpenAPI specification serves as the single source of truth for API behavior, with automatic generation of route handlers, parameter validation, response serialization, and interactive documentation.

Capabilities

Application Classes

Core application classes for creating Connexion-based web services with different underlying frameworks and deployment models.

class AsyncApp:
    def __init__(self, import_name: str, **kwargs): ...
    def add_api(self, specification: str, **kwargs): ...
    def run(self, host: str = None, port: int = None, **options): ...

class FlaskApp:
    def __init__(self, import_name: str, **kwargs): ...
    def add_api(self, specification: str, **kwargs): ...
    def run(self, host: str = None, port: int = None, **options): ...

class ConnexionMiddleware:
    def __init__(self, app, **kwargs): ...
    def add_api(self, specification: str, **kwargs): ...

Application Classes

Request/Response Handling

Comprehensive middleware system for processing HTTP requests and responses with automatic validation, serialization, and error handling based on OpenAPI specifications.

class ConnexionRequest:
    async def get_body(self): ...
    async def json(self): ...
    async def form(self) -> dict: ...
    async def files(self) -> dict: ...
    @property
    def query_params(self) -> dict: ...
    @property
    def path_params(self) -> dict: ...

class ConnexionResponse:
    def __init__(self, body, status_code: int = 200, headers: dict = None): ...

def problem(status: int, title: str, detail: str = None, **kwargs): ...

Request Response

Operation Resolution

System for mapping OpenAPI operations to Python functions using various resolution strategies for flexible endpoint handling.

class Resolver:
    def __init__(self, function_resolver=None): ...
    def resolve(self, operation): ...

class RestyResolver:
    def __init__(self, default_module_name: str, **kwargs): ...

class MethodResolver:
    def __init__(self, api_name: str, **kwargs): ...

Operation Resolution

Validation System

Automatic request and response validation based on OpenAPI schema definitions with support for various content types and validation strategies.

VALIDATOR_MAP: dict
class AbstractRequestBodyValidator: ...
class AbstractParameterValidator: ...
class AbstractResponseBodyValidator: ...

Validation

Security & Authentication

Built-in security handlers for common authentication methods with support for Bearer tokens, Basic auth, API keys, and OAuth2.

def bearer_auth(token: str): ...
def basic_auth(username: str, password: str): ...
def api_key_auth(api_key: str, required_scopes: list): ...

Security

Exception Handling

Comprehensive exception system following RFC 7807 Problem Details standard for consistent error responses and debugging.

class ProblemException(Exception):
    def __init__(self, status: int, title: str, detail: str = None, **kwargs): ...

class BadRequestProblem(ProblemException): ...
class UnauthorizedProblem(ProblemException): ...
class ForbiddenProblem(ProblemException): ...

Exceptions

CLI Tools

Command-line interface for running development servers and managing Connexion applications.

# Command: connexion run <spec_file>
def main(): ...

CLI

Types

# Request/Response Types
MaybeAwaitable = Union[T, Awaitable[T]]
WSGIApp = Callable[[dict, Callable], Iterable[bytes]]
ASGIApp = Callable[[dict, Callable, Callable], Awaitable[None]]

# Data Structures
class NoContent:
    """Represents empty HTTP response body"""
    pass

class MediaTypeDict(dict):
    """Media type mapping utilities"""
    pass