Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hussein-awala/async-batcher
A service to batch the http requests.
https://github.com/hussein-awala/async-batcher
asyncio batch-processing fastapi grpc http-requests python
Last synced: about 2 months ago
JSON representation
A service to batch the http requests.
- Host: GitHub
- URL: https://github.com/hussein-awala/async-batcher
- Owner: hussein-awala
- License: apache-2.0
- Created: 2024-02-15T23:50:01.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-09-02T20:56:15.000Z (5 months ago)
- Last Synced: 2024-12-10T03:40:24.213Z (2 months ago)
- Topics: asyncio, batch-processing, fastapi, grpc, http-requests, python
- Language: Python
- Homepage:
- Size: 3.9 MB
- Stars: 22
- Watchers: 1
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
README
# Async Batcher
This project provides a Python library to batch the asynchronous requests and handle them in batches.
## How to use
To use the library, you need to install the package in your environment. You can install the package using pip:
```bash
pip install async-batcher
```Then, you can create a new `AsyncBatcher` class by implementing the `process_batch` method:
```python
from async_batcher.batcher import AsyncBatcherclass MyAsyncBatcher(AsyncBatcher):
async def process_batch(self, batch):
# Process the batch
print(batch)# Create a new instance of the `MyAsyncBatcher` class
async_batcher = MyAsyncBatcher(max_batch_size=20)
async_batcher.start()
```## Benchmark
The benchmark is available in the [BENCHMARK.md](https://github.com/hussein-awala/async-batcher/blob/main/BENCHMARK.md)
file.## Use cases
The `AsyncBatcher` library can be used in any application that needs to handle asynchronous requests in batches,
such as:
- Serving machine learning models that optimize the batch processing (e.g. TensorFlow, PyTorch, Scikit-learn, etc.)
- Storing multiple records in a database in a single query to optimize the I/O operations (or to reduce the cost of the
database operations, e.g. AWS DynamoDB)
- Sending multiple messages in a single request to optimize the network operations (or to reduce the cost of the network
operations, e.g. Kafka, RabbitMQ, AWS SQS, AWS SNS, etc.)