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.5, 3.6, 3.7, 3.8

  • Django: 1.11, 2, 2.1, 2.2, 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.5.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

django_chunkator-1.5.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django-chunkator-1.5.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.8

File hashes

Hashes for django-chunkator-1.5.0.tar.gz
Algorithm Hash digest
SHA256 27b29f782cb2cff0af4ff7419b51f9e3e5a82e08c42231360bc98a538603353d
MD5 7fd9a6e7a5d53cb2dadf4d40b10ca2fb
BLAKE2b-256 2f8d0229d4947ce0b45104d8b4343b82644c5f7808e453bcd6247bdd8621490b

See more details on using hashes here.

File details

Details for the file django_chunkator-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: django_chunkator-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.6.8

File hashes

Hashes for django_chunkator-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ded57d95dbd49a36371e02f25714e89b3a9bcbb68a4c11dcf5b364c04fee2f66
MD5 ffda93d8db8230a5b1dcd0c1d155627d
BLAKE2b-256 3a692cab3d8411da8cd703ea7cd6b2a0a7ae105cadf7aa8d8fc9abc0d843a92b

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