Skip to main content

No project description provided

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.2.0.tar.gz (3.8 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.2.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: status_codes-1.2.0.tar.gz
  • Upload date:
  • Size: 3.8 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.2.0.tar.gz
Algorithm Hash digest
SHA256 b0f29600d18dd5c17e4e6ca93ce85495a49344007abd545e80deb6d2cc25c801
MD5 6a1a0766529b8b04f0fe4d65090d517f
BLAKE2b-256 dd2c2589f8a6754fe1bee46232f2766cff786c66b5b808a1fda35441de62bb1c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: status_codes-1.2.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 90f1f1d8ae11b86d22eacb476f965719f2944203d40cfafc8f30d64f4cf45d1e
MD5 d92a1bc10a40a2432d60271d1a76a30a
BLAKE2b-256 371745b97ace85b64d672b8cb2cf4febaa17a2e8f88c6bacb66e76e05b042933

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