
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
.. image:: https://travis-ci.org/peopledoc/django-chunkator.svg
Tested with all the combinations of:
.. note::
Django 3.0 is incompatible with Python 3.5, see <https://docs.djangoproject.com/en/3.0/releases/3.0/#python-compatibility>
.. code:: python
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()
:
.. code:: python
from chunkator import chunkator
for item in chunkator(LargeModel.objects.values('pk', 'name'), 200):
do_something(item)
.. important::
If you're using ``values()`` you **have** to add at least your "pk" field
to the values, otherwise, the chunkator will throw a
``MissingPkFieldException``.
.. warning::
This will not **accelerate** your process. Instead of having one BIG query,
you'll have several small queries. This will save your RAM instead, because
you'll not load a huge queryset result before looping on it.
If you want to manipulate the pages directly, you can use chunkator_page
:
.. code:: python
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])
MIT License.
FAQs
Chunk large QuerySets into small chunks, and iterate over them without killing your RAM.
We found that django-chunkator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.