DataLoader implementation for Python asyncio
Project description
dloader
A Python implementation of the DataLoader pattern for data fetching with automatic batching.
Features
- Automatically batches and deduplicates concurrent loads
- Caches results and allows custom in-memory caches
- Manages asyncio tasks and allows proper cleanup
- Small, focused and free of other dependencies
- Fully typed and fully tested
Installation
uv add dloader
# or
pip install dloader
Documentation
You can find documentation at: https://oinopion.github.io/dloader
Quick Start
import asyncio
from dloader import DataLoader
# Define a batch loading function
async def batch_load_users(user_ids):
# Fetch multiple users at once (e.g., from a database)
users = await db_client.get_many(User, user_ids)
return users
# Create a DataLoader instance
async with DataLoader(batch_load_users) as user_loader:
# These calls are automatically batched
user_1, user_2, other_users = await asyncio.gather(
user_loader.load(1),
user_loader.load(2),
user_loader.load_many([3, 4, 5]),
)
License
MIT License - see LICENSE file for details.
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
dloader-0.1.2.tar.gz
(23.9 kB
view details)
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 dloader-0.1.2.tar.gz.
File metadata
- Download URL: dloader-0.1.2.tar.gz
- Upload date:
- Size: 23.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1af67fc553e67c4cfef098b58d415189028f478e07aec2f76534861c2198901
|
|
| MD5 |
de287dfa8b88565f2749ac192187e792
|
|
| BLAKE2b-256 |
73f5c93b24ca5b9df0ae198dd1fb66d07811681697b0a072fbadbc1bcaef3060
|
File details
Details for the file dloader-0.1.2-py3-none-any.whl.
File metadata
- Download URL: dloader-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac502da4b27f17cebba9abc5f79694f6e439cd58309f06d8449c185591e830d9
|
|
| MD5 |
6b95e498726a4df66097f4b63aec935b
|
|
| BLAKE2b-256 |
c8a2250c0c30851b70c078d315c02ddf5623e98154c91990a23a80ff351290eb
|