A Python library providing RFC 9457-compliant problem detail exceptions for HCLI applications and beyond.
This package delivers a complete set of HTTP problem detail exceptions adhering to RFC 9457 (Problem Details for HTTP APIs). Built as part of the HCLI ecosystem, it offers reusable exception classes for HTTP 4xx and 5xx status codes, simplifying standardized error handling in HCLI applications and other Python projects. Each exception can be transformed into an RFC 9457-compliant problem detail object for consistent API error responses.
Learn more about HCLI at hcli.io [1].
Help shape this library and the HCLI ecosystem by raising issues on GitHub!
[1] http://hcli.io
- huckle: A generic HCLI client for interacting with HCLI applications. [2]
- hcli_core: An HCLI Connector exposing a REST API as a CLI via HCLI semantics. [3]
[2] https://github.com/cometaj2/huckle
[3] https://github.com/cometaj2/hcli_core
hcli_problem_details requires a supported version of Python and pip.
pip install hcli-problem-detailsImport and raise exceptions in your Python application as needed. Each exception generates an RFC 9457-compliant problem detail representation.
from hcli_problem_details import NotFoundError, BadRequestError
# Raise a 404 Not Found error
raise NotFoundError(detail="Resource not found")
# Output: {"type": "about:blank", "title": "Not Found", "status": 404, "detail": "Resource not found"}
# Raise a 400 Bad Request error with custom extensions
raise BadRequestError(detail="Invalid input", extensions={"field": "username"})
# Output: {"type": "about:blank", "title": "Bad Request", "status": 400, "detail": "Invalid input", "field": "username"}HCLI Core utilizes this package to automatically recognize and relay its raised exceptions to HCLI clients (e.g., huckle) as problem details.
The following exception classes are available, each corresponding to an HTTP status code and RFC 9457 problem detail:
4xx Client Errors:
BadRequestError(400) - Bad RequestAuthenticationError(401) - UnauthorizedPaymentRequiredError(402) - Payment RequiredAuthorizationError(403) - ForbiddenNotFoundError(404) - Not FoundMethodNotAllowedError(405) - Method Not AllowedNotAcceptableError(406) - Not AcceptableProxyAuthenticationError(407) - Proxy Authentication RequiredRequestTimeoutError(408) - Request TimeoutConflictError(409) - ConflictGoneError(410) - GoneLengthRequiredError(411) - Length RequiredPreconditionFailedError(412) - Precondition FailedPayloadTooLargeError(413) - Payload Too LargeURITooLongError(414) - URI Too LongUnsupportedMediaTypeError(415) - Unsupported Media TypeRangeNotSatisfiableError(416) - Range Not SatisfiableExpectationFailedError(417) - Expectation FailedTeapotError(418) - I'm a teapotMisdirectedRequestError(421) - Misdirected RequestUnprocessableEntityError(422) - Unprocessable EntityLockedError(423) - LockedFailedDependencyError(424) - Failed DependencyTooEarlyError(425) - Too EarlyUpgradeRequiredError(426) - Upgrade RequiredPreconditionRequiredError(428) - Precondition RequiredTooManyRequestsError(429) - Too Many RequestsRequestHeaderFieldsTooLargeError(431) - Request Header Fields Too LargeUnavailableForLegalReasonsError(451) - Unavailable For Legal Reasons
5xx Server Errors:
InternalServerError(500) - Internal Server ErrorNotImplementedError(501) - Not ImplementedBadGatewayError(502) - Bad GatewayServiceUnavailableError(503) - Service UnavailableGatewayTimeoutError(504) - Gateway TimeoutHTTPVersionNotSupportedError(505) - HTTP Version Not SupportedVariantAlsoNegotiatesError(506) - Variant Also NegotiatesInsufficientStorageError(507) - Insufficient StorageLoopDetectedError(508) - Loop DetectedNotExtendedError(510) - Not ExtendedNetworkAuthenticationRequiredError(511) - Network Authentication Required
All exceptions inherit from ProblemDetail and support optional detail, instance, type_uri, and extensions parameters.
This project follows semantic versioning (http://semver.org). Development releases may use "devx", "prealphax", "alphax", "betax", or "rcx" extensions (e.g., 0.1.0-prealpha1) on GitHub. Only full major.minor.patch releases are published to PyPI.
- Full coverage of HTTP 4xx client errors and 5xx server errors as exception classes.
- RFC 9457 problem detail structure with
type,title,status,detail,instance,type_uri, and extensibleextensions. - Compatibility with HCLI Core and any Python project requiring standardized HTTP error handling.
- Add automated tests for all exception classes.
- Provide integration examples for common web frameworks (e.g., Flask, FastAPI, Falcon).
- Document advanced usage of extensions for custom problem details.
- No known issues.