Skip to content

Request, WebhookRequest and Response protocols

openapi_core.protocols

OpenAPI core protocols

Attributes

HeadersType module-attribute

HeadersType = Union[Mapping[str, Any], Headers]

Classes

BaseRequest

Bases: Protocol

Source code in openapi_core/protocols.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@runtime_checkable
class BaseRequest(Protocol):
    parameters: RequestParameters

    @property
    def method(self) -> str:
        """The request method, as lowercase string."""

    @property
    def body(self) -> Optional[bytes]:
        """The request body, as bytes (None if not provided)."""

    @property
    def content_type(self) -> str:
        """The content type with parameters (e.g., charset, boundary, etc.) and always lowercase."""
Attributes
parameters instance-attribute
parameters: RequestParameters
method property
method: str

The request method, as lowercase string.

body property
body: Optional[bytes]

The request body, as bytes (None if not provided).

content_type property
content_type: str

The content type with parameters (e.g., charset, boundary, etc.) and always lowercase.

Request

Bases: BaseRequest, Protocol

Request protocol.

ATTRIBUTE DESCRIPTION
host_url

Url with scheme and host. For example: https://localhost:8000

TYPE: str

path

Request path.

TYPE: str

full_url_pattern

The matched url with scheme, host and path pattern. For example: https://localhost:8000/api/v1/pets https://localhost:8000/api/v1/pets/{pet_id}

TYPE: str

method

The request method, as lowercase string.

TYPE: str

parameters

A RequestParameters object. Needs to support path attribute setter to write resolved path parameters.

TYPE: RequestParameters

content_type

The content type with parameters (e.g., charset, boundary, etc.) and always lowercase.

TYPE: str

body

The request body, as bytes (None if not provided).

TYPE: Optional[bytes]

Source code in openapi_core/protocols.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
@runtime_checkable
class Request(BaseRequest, Protocol):
    """Request protocol.

    Attributes:
        host_url: Url with scheme and host.
            For example: https://localhost:8000
        path: Request path.
        full_url_pattern: The matched url with scheme, host and path pattern.
            For example: https://localhost:8000/api/v1/pets
                         https://localhost:8000/api/v1/pets/{pet_id}
        method: The request method, as lowercase string.
        parameters: A RequestParameters object. Needs to support path attribute setter
            to write resolved path parameters.
        content_type: The content type with parameters (e.g., charset, boundary, etc.)
            and always lowercase.
        body: The request body, as bytes (None if not provided).
    """

    @property
    def host_url(self) -> str:
        """Url with scheme and host. For example: https://localhost:8000"""

    @property
    def path(self) -> str:
        """Request path."""
Attributes
host_url property
host_url: str

Url with scheme and host. For example: https://localhost:8000

path property
path: str

Request path.

parameters instance-attribute
parameters: RequestParameters
method property
method: str

The request method, as lowercase string.

body property
body: Optional[bytes]

The request body, as bytes (None if not provided).

content_type property
content_type: str

The content type with parameters (e.g., charset, boundary, etc.) and always lowercase.

WebhookRequest

Bases: BaseRequest, Protocol

Webhook request protocol.

ATTRIBUTE DESCRIPTION
name

Webhook name.

TYPE: str

method

The request method, as lowercase string.

TYPE: str

parameters

A RequestParameters object. Needs to support path attribute setter to write resolved path parameters.

TYPE: RequestParameters

content_type

The content type with parameters (e.g., charset, boundary, etc.) and always lowercase.

TYPE: str

body

The request body, as bytes (None if not provided).

TYPE: Optional[bytes]

Source code in openapi_core/protocols.py
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
@runtime_checkable
class WebhookRequest(BaseRequest, Protocol):
    """Webhook request protocol.

    Attributes:
        name: Webhook name.
        method: The request method, as lowercase string.
        parameters: A RequestParameters object. Needs to support path attribute setter
            to write resolved path parameters.
        content_type: The content type with parameters (e.g., charset, boundary, etc.)
            and always lowercase.
        body: The request body, as bytes (None if not provided).
    """

    @property
    def name(self) -> str:
        """Webhook name."""
Attributes
name property
name: str

Webhook name.

parameters instance-attribute
parameters: RequestParameters
method property
method: str

The request method, as lowercase string.

body property
body: Optional[bytes]

The request body, as bytes (None if not provided).

content_type property
content_type: str

The content type with parameters (e.g., charset, boundary, etc.) and always lowercase.

SupportsPathPattern

Bases: Protocol

Supports path_pattern protocol.

You also need to provide path variables in RequestParameters.

ATTRIBUTE DESCRIPTION
path_pattern

The matched path pattern. For example: /api/v1/pets/{pet_id}

TYPE: str

Source code in openapi_core/protocols.py
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@runtime_checkable
class SupportsPathPattern(Protocol):
    """Supports path_pattern protocol.

    You also need to provide path variables in RequestParameters.

    Attributes:
        path_pattern: The matched path pattern.
            For example: /api/v1/pets/{pet_id}
    """

    @property
    def path_pattern(self) -> str:
        """The matched path pattern. For example: /api/v1/pets/{pet_id}"""
Attributes
path_pattern property
path_pattern: str

The matched path pattern. For example: /api/v1/pets/{pet_id}

Response

Bases: Protocol

Response protocol.

ATTRIBUTE DESCRIPTION
status_code

The status code as integer.

TYPE: int

headers

Response headers as Headers.

TYPE: HeadersType

content_type

The content type with parameters and always lowercase.

TYPE: str

data

The response body, as bytes (None if not provided).

TYPE: Optional[bytes]

Source code in openapi_core/protocols.py
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
@runtime_checkable
class Response(Protocol):
    """Response protocol.

    Attributes:
        status_code: The status code as integer.
        headers: Response headers as Headers.
        content_type: The content type with parameters and always lowercase.
        data: The response body, as bytes (None if not provided).
    """

    @property
    def status_code(self) -> int:
        """The status code as integer."""

    @property
    def content_type(self) -> str:
        """The content type with parameters and always lowercase."""

    @property
    def headers(self) -> HeadersType:
        """Response headers as Headers."""

    @property
    def data(self) -> Optional[bytes]:
        """The response body, as bytes (None if not provided)."""
Attributes
status_code property
status_code: int

The status code as integer.

content_type property
content_type: str

The content type with parameters and always lowercase.

headers property
headers: HeadersType

Response headers as Headers.

data property
data: Optional[bytes]

The response body, as bytes (None if not provided).