Skip to main content

HTTP status code responses with predefined or custom messages for easy integration into web applications and APIs.

Project description

Status Codes Package

A Python package that provides functions for HTTP status codes, allowing you to easily generate responses with predefined or custom messages. This package is useful for handling API responses in web development.

Features

Predefined HTTP Status Codes: Functions for common HTTP status codes like 200 (OK), 404 (Not Found), 500 (Internal Server Error), and more. Custom Message Support: Optionally provide a custom message for any status code response. Easy Integration: Simple functions that return dictionaries with the status code and message.

Installation

You can install the package using pip: pip install status-codes

Usage

You can use the functions from the status_codes package to get HTTP responses with status codes and messages.

Example:

from status_codes import StatusCodes

  1. Using default messages
response = StatusCodes.ok_200()
print(response)  # Outputs: {'status': 200, 'message': 'Request succeeded.'}
  1. Using custom messages
response = StatusCodes.ok_200("Custom success message")
print(response)  # Outputs: {'status': 200, 'message': 'Custom success message'}

Available Functions

Here is a list of the available status code functions, each with an optional custom_message parameter:

Informational 1xx

  • continue_100
  • switching_protocols_101
  • processing_102
  • early_hints_103

Successful 2xx

  • ok_200
  • created_201
  • accepted_202
  • non_authoritative_information_203
  • no_content_204
  • reset_content_205
  • partial_content_206
  • multi_status_207
  • already_reported_208
  • im_used_226

Redirection 3xx

  • multiple_choices_300
  • moved_permanently_301
  • found_302
  • see_other_303
  • not_modified_304
  • use_proxy_305
  • use_proxy_306
  • temporary_redirect_307
  • permanent_redirect_308

Client Error 4xx

  • bad_request_400
  • unauthorized_401
  • payment_required_402
  • forbidden_403
  • not_found_404
  • method_not_allowed_405
  • not_acceptable_406
  • proxy_authentication_required_407
  • request_timeout_408
  • conflict_409
  • gone_410
  • length_required_411
  • precondition_failed_412
  • payload_too_large_413
  • uri_too_long_414
  • unsupported_media_type_415
  • range_not_satisfiable_416
  • expectation_failed_417
  • im_a_teapot_418
  • misdirected_request_421
  • unprocessable_content_422
  • locked_423
  • failed_dependency_424
  • too_early_425
  • upgrade_required_426
  • precondition_required_428
  • too_many_requests_429
  • request_header_fields_too_large_431
  • unavailable_for_legal_reasons_451

Server Error 5xx

  • internal_server_error_500
  • not_implemented_501
  • bad_gateway_502
  • service_unavailable_503
  • gateway_timeout_504
  • http_version_not_supported_505
  • variant_also_negotiates_506
  • insufficient_storage_507
  • loop_detected_508
  • not_extended_510
  • network_authentication_required_511

Customization

Each function in the StatusCodes class allows you to pass an optional custom_message parameter. If no message is provided, the function uses a default message associated with the status code.

Using custom message

response = StatusCodes.bad_request_400("Custom bad request message")
Outputs: {'status': 400, 'message': 'Custom bad request message'}

If no custom message is passed, it will use the default message:

Without using custom message(ie., default)

response = StatusCodes.bad_request_400()
Outputs: {'status': 400, 'message': 'Bad request syntax.'}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

status_codes-1.3.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

status_codes-1.3.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file status_codes-1.3.0.tar.gz.

File metadata

  • Download URL: status_codes-1.3.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for status_codes-1.3.0.tar.gz
Algorithm Hash digest
SHA256 c18b985f35f3aaee7d39e86e3b58b6f8f6f094e585f6b409f175d9f9c7780be6
MD5 3784d5fad7f1b404e083b4575e2dd21f
BLAKE2b-256 a5004161ecbdd802ff711c28301113d89de011ee3c9a67efc432816ed4a833b1

See more details on using hashes here.

File details

Details for the file status_codes-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: status_codes-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for status_codes-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 117fa61024700b948a055a60af81939f072a6f0fcd266c454576fe138d8773c5
MD5 780f056049244cdfefa15ea113c14178
BLAKE2b-256 0146918c7944c7ef78dc37709bd24509092232f72e55e323468b4cbd15da7400

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page