Skip to main content

No project description provided

Project description

Batch HTTP Request

Overview

The Batch HTTP Request is a Python package designed to handle multiple HTTP requests efficiently. It allows users to send a batch of requests and receive the corresponding responses in a structured format. The library also provides error handling capabilities, returning errors alongside successful responses if desired.

Features

  • Send multiple HTTP requests in a single batch.
  • Supports various HTTP methods (GET, POST, etc.).
  • Handles headers and request bodies.
  • Optionally returns errors encountered during request processing.

Installation

To install the library, you can use pip:

pip install batch-http-request

Usage

Classes

Request

The Request class is used to define individual HTTP requests.

  • Attributes:

    • url (str): The URL for the request.
    • method (str): The HTTP method (e.g., "GET", "POST").
    • headers (List[Tuple[str, str]]): Optional list of headers.
    • body (Optional[bytes]): Optional request body.
  • Constructor:

    Request(url: str, method: str, headers: Optional[List[Tuple[str, str]]] = [], body: Optional[bytes] = None)
    

Response

The Response class represents the HTTP response.

  • Attributes:

    • status_code (int): The HTTP status code.
    • headers (List[Tuple[str, str]]): List of response headers.
    • body (bytes): Response body.
  • Constructor:

    Response(status_code: int, headers: List[Tuple[str, str]], body: bytes)
    

Function

batch_request

The batch_request function processes a list of Request objects and returns their corresponding Response objects or errors.

  • Parameters:

    • requests (List[Request]): A list of Request objects to be processed.
    • return_panic (bool): If set to True, the function returns errors encountered during the request processing as RuntimeError objects. Defaults to False.
  • Returns:

    • List[Union[Response, RuntimeError]]: A list containing Response objects for successful requests and RuntimeError objects for failed requests if return_panic is True.
  • Example:

    from batch_http_request import Request, batch_request
    
    requests = [
        Request(url="https://api.example.com/data", method="GET"),
        Request(url="https://api.example.com/submit", method="POST", body=b'{"key": "value"}')
    ]
    
    responses = batch_request(requests, return_panic=True)
    
    for response in responses:
        if isinstance(response, Response):
            print(f"Status: {response.status_code}, Body: {response.body}")
        else:
            print(f"Error: {response}")
    

Contributing

Contributions are welcome! Please fork the repository and submit a pull request with your changes.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contact

For any questions or issues, please open an issue on the GitHub repository or contact the maintainers directly.

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

batch_http_request-0.1.2.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

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

batch_http_request-0.1.2-cp311-none-win_amd64.whl (1.2 MB view details)

Uploaded CPython 3.11Windows x86-64

File details

Details for the file batch_http_request-0.1.2.tar.gz.

File metadata

  • Download URL: batch_http_request-0.1.2.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.7.4

File hashes

Hashes for batch_http_request-0.1.2.tar.gz
Algorithm Hash digest
SHA256 04a220bb273f25269b3cf38aa1d5973495b58ffbe7bdfa8a51a24c8167ce2a56
MD5 683e21ce0689843c1a53fa918626626c
BLAKE2b-256 81845aedfb8e7ed4571469a5731253a9ad331077e65794978eb81a90a1547e63

See more details on using hashes here.

File details

Details for the file batch_http_request-0.1.2-cp311-none-win_amd64.whl.

File metadata

File hashes

Hashes for batch_http_request-0.1.2-cp311-none-win_amd64.whl
Algorithm Hash digest
SHA256 3b66a723c1b88a0901209b22e222393a5c07bb91e6e3217fe7289d571a155c71
MD5 ee8b82165a6fd941aa608621aa4c6647
BLAKE2b-256 1d304a5816207b5caa318364f724822af7f4bd760dc88750c91777112aa6813b

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