Skip to main content

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.

https://travis-ci.org/peopledoc/django-chunkator.svg

Tested with all the combinations of:

  • Python: 2.7, 3.4, 3.5.

  • Django: 1.8 (LTS), 1.9, 1.10, 1.11.

Also, tested the following:

  • Python 3.6 + Django 1.11

  • Python 3.4, 3.5, 3.6 + Django “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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-chunkator-1.3.1.tar.gz (3.7 kB view details)

Uploaded Source

File details

Details for the file django-chunkator-1.3.1.tar.gz.

File metadata

File hashes

Hashes for django-chunkator-1.3.1.tar.gz
Algorithm Hash digest
SHA256 9a8341b7bb55080ed062dd5d8ffad6b3fd45e20dc4268899744d4e64132fa27b
MD5 fd1637e3b50849287f6eee2bc3c15fd5
BLAKE2b-256 58641c160be8fc63713feec276c794c48e379da5c90778c426e431e224b5070f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page