Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
Project description
Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
Tested with all the combinations of:
Python: 2.7, 3.5, 3.6, 3.7
Django: 1.11, 2, 2.1, master
Usage
from chunkator import chunkator
for item in chunkator(LargeModel.objects.all(), 200):
do_something(item)
This tool is intended to work on Django querysets.
Your model must define a pk field (this is done by default, but sometimes it can be overridden) and this pk has to be unique. django- chunkator has been tested with PostgreSQL and SQLite, using regular PKs and UUIDs as primary keys.
You can also use values():
from chunkator import chunkator
for item in chunkator(LargeModel.objects.values('pk', 'name'), 200):
do_something(item)
If you want to manipulate the pages directly, you can use chunkator_page:
from chunkator import chunkator_page
queryset = LargeModel.objects.all().values('pk')
for page in chunkator_page(queryset, 200):
launch_some_task([item['pk'] for item in page])
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-chunkator-1.4.0.tar.gz
.
File metadata
- Download URL: django-chunkator-1.4.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0fe33917589816a695e202e00bd3fd1a926d0e376ff977b118e28d0a6548a0a |
|
MD5 | 95a0e6d4733cea0af9c0350bd731aa59 |
|
BLAKE2b-256 | 6dcdc67979aa809b3b46402c421646ef49eb49ff51b29eecfc709a7eb106577a |