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 ofRequestobjects to be processed.return_panic(bool): If set toTrue, the function returns errors encountered during the request processing asRuntimeErrorobjects. Defaults toFalse.
-
Returns:
- List[Union[Response, RuntimeError]]: A list containing
Responseobjects for successful requests andRuntimeErrorobjects for failed requests ifreturn_panicisTrue.
- List[Union[Response, RuntimeError]]: A list containing
-
Example:
from batch_request_library 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file batch_http_request-0.1.1.tar.gz.
File metadata
- Download URL: batch_http_request-0.1.1.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3cd4c387ab523345c0c2302d440b679352cb2e57cd2405bde3b77cc3a011c934
|
|
| MD5 |
7b18d5b6ade867f6629193aa90068ac8
|
|
| BLAKE2b-256 |
b427dc0f990a945149c2d55b45def8874cb283b889148f31630dcb054c563882
|
File details
Details for the file batch_http_request-0.1.1-cp311-none-win_amd64.whl.
File metadata
- Download URL: batch_http_request-0.1.1-cp311-none-win_amd64.whl
- Upload date:
- Size: 1.2 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.7.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
673ed1d9859a1edba838f18d8866fc598e94b81fd68c6ddd6521def1cdee51cf
|
|
| MD5 |
312229c19700daaa6d7a7826a0025c2d
|
|
| BLAKE2b-256 |
72ff1a8212bb22f26d6b9f2506f8553cdb15b5cb9b6ae3be42d167bb27082e5b
|