New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

status-codes

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

status-codes

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

  • 1.4.0
  • PyPI
  • Socket score

Maintainers
1

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.
  • Data Support: You can include additional data in the response along with the message.
  • Easy Integration: Simple functions that return dictionaries with the status code, message, and optional data.

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, messages, and data.

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_message="Custom success message")
print(response)  # Outputs: {'status': 200, 'message': 'Custom success message'}
  1. Using data:
response = StatusCodes.ok_200(data={"key": "value"})
print(response)  # Outputs: {'status': 200, 'message': 'Request succeeded.', 'data': {'key': 'value'}}
  1. Using both custom messages and data:
response = StatusCodes.ok_200(custom_message="Custom success message", data={"key": "value"})
print(response)  # Outputs: {'status': 200, 'message': 'Custom success message', 'data': {'key': 'value'}}

Available Functions

Here is a list of the available status code functions, each with optional custom_message and data parameters:

Informational 1xx

  • continue_100(custom_message=None, data=None)
  • switching_protocols_101(custom_message=None, data=None)
  • processing_102(custom_message=None, data=None)
  • early_hints_103(custom_message=None, data=None)

Successful 2xx

  • ok_200(custom_message=None, data=None)
  • created_201(custom_message=None, data=None)
  • accepted_202(custom_message=None, data=None)
  • non_authoritative_information_203(custom_message=None, data=None)
  • no_content_204(custom_message=None, data=None)
  • reset_content_205(custom_message=None, data=None)
  • partial_content_206(custom_message=None, data=None)
  • multi_status_207(custom_message=None, data=None)
  • already_reported_208(custom_message=None, data=None)
  • im_used_226(custom_message=None, data=None)

Redirection 3xx

  • multiple_choices_300(custom_message=None, data=None)
  • moved_permanently_301(custom_message=None, data=None)
  • found_302(custom_message=None, data=None)
  • see_other_303(custom_message=None, data=None)
  • not_modified_304(custom_message=None, data=None)
  • use_proxy_305(custom_message=None, data=None)
  • temporary_redirect_307(custom_message=None, data=None)
  • permanent_redirect_308(custom_message=None, data=None)

Client Error 4xx

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

Server Error 5xx

  • internal_server_error_500(custom_message=None, data=None)
  • not_implemented_501(custom_message=None, data=None)
  • bad_gateway_502(custom_message=None, data=None)
  • service_unavailable_503(custom_message=None, data=None)
  • gateway_timeout_504(custom_message=None, data=None)
  • http_version_not_supported_505(custom_message=None, data=None)
  • variant_also_negotiates_506(custom_message=None, data=None)
  • insufficient_storage_507(custom_message=None, data=None)
  • loop_detected_508(custom_message=None, data=None)
  • not_extended_510(custom_message=None, data=None)
  • network_authentication_required_511(custom_message=None, data=None)

Customization

Each function in the StatusCodes class allows you to pass optional custom_message and data parameters. If no custom_message is provided, the function uses the default message associated with the status code. If data is not provided, no additional data will be included in the response.

Using custom message

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

Using data

response = StatusCodes.bad_request_400(data={"key": "value"})
print(response)
# Outputs: {'status': 400, 'message': 'Bad request syntax.', 'data': {'key': 'value'}}

Using both custom message and data

response = StatusCodes.bad_request_400(custom_message="Custom bad request message", data={"key": "value"})
print(response)
# Outputs: {'status': 400, 'message': 'Custom bad request message', 'data': {'key': 'value'}}

Without using custom message (using the default message)

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

Important Notes:

  • Keyword-only arguments: Both custom_message and data must be passed as keyword arguments. Positional arguments are not supported for these parameters.

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc