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/novafloss/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.0.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

django_chunkator-1.3.0-py2-none-any.whl (5.2 kB view details)

Uploaded Python 2

File details

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

File metadata

File hashes

Hashes for django-chunkator-1.3.0.tar.gz
Algorithm Hash digest
SHA256 42f12a96a48acbc1590f1b55159df414fa8138ab0f82a99919f6ebe7f5f0cf86
MD5 e0f14641e1bcf8f17f84b288445ac973
BLAKE2b-256 8184698dde683053e2f431109dfa8756fb8a233d722f6f30e751b512cd9454e8

See more details on using hashes here.

File details

Details for the file django_chunkator-1.3.0-py2-none-any.whl.

File metadata

File hashes

Hashes for django_chunkator-1.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 6fe6816803b0acfc315061d681c5095ebea3a16e2bafde8b04b9ccc966986089
MD5 90b38028ee0835cdb989b2d7960c2061
BLAKE2b-256 3e8368a5a8b3600f65e8edf548e75d4de6a8b7342175bddee8ae9d586a961730

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