Skip to main content

A simple package to generate structured HTTP responses with trace ID.

Project description

structured-response

A lightweight Python package to generate structured HTTP responses with optional trace IDs. Simplifies API response consistency in Flask-based microservices.

Installation

To install the package, run:

pip install structured-response

Alternatively, install directly from the source:

pip install git+https://github.com/rohaan2614/structured-response.git

Usage

Example 1: Basic Response

from structured_response import generate_response

response = generate_response(
    status_code=200,
    message="Hello, world!"
)
print(response.get_json())  # {"status": "Success", "message": "Hello, world!"}

Example 2: Custom Trace ID

from structured_response import generate_response

response = generate_response(
    status_code=404,
    trace_id="abc123",
    message="Resource not found",
    user="John Doe"
)
print(response.get_json())
# Output:
# {
#     "status": "Client Error",
#     "message": "Resource not found",
#     "user": "John Doe"
# }

Function Reference

generate_response(status_code: int = 200, trace_id: str None, message: str = None, **kwargs) -> Response

Generates a structured HTTP response.

Parameter Type Description
status_code int HTTP status code (default: 200)
trace_id str None
message str None
**kwargs dict Additional key-value pairs to include in the response body

Development

Clone the repository:

git clone https://github.com/rohaan2614/structured-response.git
cd structured-response

Install dependencies:

pip install -r requirements.txt

Changelog

v0.1.1

  • Updated package to use pyproject.toml for PEP 625 compliance.
  • No functional changes to the code.

v0.1.0

  • Initial release 🎉
  • Added generate_response function with optional trace_id support.
  • Categorizes status codes (Informational, Success, etc.).

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

structured_response-0.1.1.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

structured_response-0.1.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file structured_response-0.1.1.tar.gz.

File metadata

  • Download URL: structured_response-0.1.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for structured_response-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0bafd4f0a135da1e9a53a894b47bf7f7f0abe380bc277e4364b6bc7c09da698e
MD5 7648017e05da8cc1fc7ee2b096f6cd3b
BLAKE2b-256 e16b869267889da977c48a08e4f1f28f59c176437d7cc44d6c1bc9bd797db54e

See more details on using hashes here.

File details

Details for the file structured_response-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for structured_response-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e5376082500549772f90c3b30722aaf89670d4e919b26b375adb76d7f8e4f19d
MD5 4b4a975901db21a24095b8789a437988
BLAKE2b-256 e1d71000f4efde012cad583d8e4a1d7638a280d646f612a97eb57a2797d91b53

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