3.7. Enum Built-in

3.7.1. http.HTTPStatus

>>> from http import HTTPStatus
>>> HTTPStatus(200).name
'OK'
>>>
>>> HTTPStatus(404).name
'NOT_FOUND'
>>>
>>> HTTPStatus(500).name
'INTERNAL_SERVER_ERROR'
>>>
>>> HTTPStatus(418).name
'IM_A_TEAPOT'

3.7.2. http.HTTPMethod

  • Since 3.11:

>>> from http import HTTPMethod
>>> HTTPMethod.GET
<HTTPMethod.GET>
>>>
>>> HTTPMethod.GET == 'GET'
True
>>>
>>> HTTPMethod.GET.value
'GET'
>>>
>>> HTTPMethod.GET.description
'Retrieve the target.'
>>>
>>> list(HTTPMethod)  
[<HTTPMethod.CONNECT>,
 <HTTPMethod.DELETE>,
 <HTTPMethod.GET>,
 <HTTPMethod.HEAD>,
 <HTTPMethod.OPTIONS>,
 <HTTPMethod.PATCH>,
 <HTTPMethod.POST>,
 <HTTPMethod.PUT>,
 <HTTPMethod.TRACE>]