HTTP Status for Humans
A very simple Python library providing human-understandable HTTP status codes and helper methods to improve code readability. Originally forked from Django Rest Framework, it reached version 1.0.1 in October 2015 and has not seen further updates since, making it an effectively abandoned project.
Common errors
-
ModuleNotFoundError: No module named 'status'
cause The `python-status` library is not installed in the current environment.fixRun `pip install python-status` to install the library. -
AttributeError: module 'status' has no attribute 'HTTP_XXX_YYY' (e.g., HTTP_422_UNPROCESSABLE_ENTITY)
cause The `python-status` library might not have all newer HTTP status codes or you are using it in a context where a newer status code is expected that wasn't defined in its 2015 release.fixUpgrade to `http.HTTPStatus` from the standard library. Newer Python versions' `HTTPStatus` enum will include more recently defined codes. If using an old Python and stuck with `python-status`, you might need to use the raw integer value for less common or newer status codes. -
TypeError: 'module' object is not callable (e.g., `status(200)` is called)
cause The `status` import provides a module with attributes (like `status.HTTP_200_OK`) and functions (like `status.is_success`), but the `status` module itself is not a callable class or function to instantiate.fixAccess status codes as attributes (e.g., `status.HTTP_200_OK`) or call helper functions with arguments (e.g., `status.is_success(code=200)`). Do not attempt to call `status()` directly.
Warnings
- breaking The `python-status` library is effectively abandoned. Its last release was in October 2015, with official compatibility listed only up to Python 3.5. It is highly unlikely to function correctly or be maintained on modern Python versions (3.6+).
- deprecated This library has been superseded by the `http.HTTPStatus` enum in the Python standard library, introduced in Python 3.5.
- gotcha The library's `requires_python` metadata on PyPI is `None`, which might suggest broad compatibility. However, the project classifiers and last commit date indicate support explicitly for Python 2.7, 3.3, 3.4, and 3.5. Using it on newer Python versions is not officially supported and may lead to unexpected behavior or `ImportError`.
Install
-
pip install python-status
Imports
- status
import status
- HTTP_200_OK
status.HTTP_200_OK
- is_success
status.is_success(response.status_code)
status.is_success(code)
Quickstart
import requests
import status
import os
# Example usage with a requests response
response = requests.get(os.environ.get('TEST_URL', 'https://httpbin.org/status/200'))
if status.is_success(code=response.status_code):
print(f"Request successful: {response.status_code} {status.phrase(response.status_code)}")
elif status.is_client_error(code=response.status_code):
print(f"Client error: {response.status_code} {status.phrase(response.status_code)}")
elif status.is_server_error(code=response.status_code):
print(f"Server error: {response.status_code} {status.phrase(response.status_code)}")
# Direct access to status codes
print(f"HTTP OK: {status.HTTP_200_OK}")
print(f"HTTP Not Found: {status.HTTP_404_NOT_FOUND}")