{"id":13849432,"url":"https://github.com/aykut/django-bulk-update","last_synced_at":"2025-07-12T16:32:19.395Z","repository":{"id":16431507,"uuid":"19182914","full_name":"aykut/django-bulk-update","owner":"aykut","description":"Bulk update using one query over Django ORM","archived":false,"fork":false,"pushed_at":"2023-10-03T21:00:04.000Z","size":136,"stargazers_count":433,"open_issues_count":17,"forks_count":59,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-11-06T17:26:36.429Z","etag":null,"topics":["bulk","django","django-bulk","django-orm","update"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"mbland/slack-github-issues","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aykut.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-04-26T16:58:43.000Z","updated_at":"2024-11-06T09:53:31.000Z","dependencies_parsed_at":"2024-01-18T09:04:51.356Z","dependency_job_id":"252c3daa-bae9-4ced-8903-d20727fffe75","html_url":"https://github.com/aykut/django-bulk-update","commit_stats":{"total_commits":146,"total_committers":21,"mean_commits":"6.9523809523809526","dds":0.636986301369863,"last_synced_commit":"399e64d820133a79f910682c1cf247938c5c4784"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykut%2Fdjango-bulk-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykut%2Fdjango-bulk-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykut%2Fdjango-bulk-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aykut%2Fdjango-bulk-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aykut","download_url":"https://codeload.github.com/aykut/django-bulk-update/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225829364,"owners_count":17530663,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bulk","django","django-bulk","django-orm","update"],"created_at":"2024-08-04T19:01:17.984Z","updated_at":"2024-11-22T01:30:54.674Z","avatar_url":"https://github.com/aykut.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"django-bulk-update\n==================================\n[![Build Status](https://travis-ci.org/aykut/django-bulk-update.svg?branch=master)](https://travis-ci.org/aykut/django-bulk-update)\n[![Coverage Status](https://coveralls.io/repos/aykut/django-bulk-update/badge.svg?branch=master)](https://coveralls.io/r/aykut/django-bulk-update?branch=master)\n\nSimple bulk update over Django ORM or with helper function.\n\nThis project aims to bulk update given objects using **one query** over\n**Django ORM**.\n\nInstallation\n==================================\n    pip install django-bulk-update\n\nUsage\n==================================\nWith manager:\n\n```python\nimport random\nfrom django_bulk_update.manager import BulkUpdateManager\nfrom tests.models import Person\n\nclass Person(models.Model):\n    ...\n    objects = BulkUpdateManager()\n\nrandom_names = ['Walter', 'The Dude', 'Donny', 'Jesus']\npeople = Person.objects.all()\nfor person in people:\n  person.name = random.choice(random_names)\n\nPerson.objects.bulk_update(people, update_fields=['name'])  # updates only name column\nPerson.objects.bulk_update(people, exclude_fields=['username'])  # updates all columns except username\nPerson.objects.bulk_update(people)  # updates all columns\nPerson.objects.bulk_update(people, batch_size=50000)  # updates all columns by 50000 sized chunks\n```\n\n\nWith helper:\n\n```python\nimport random\nfrom django_bulk_update.helper import bulk_update\nfrom tests.models import Person\n\nrandom_names = ['Walter', 'The Dude', 'Donny', 'Jesus']\npeople = Person.objects.all()\nfor person in people:\n  person.name = random.choice(random_names)\n\nbulk_update(people, update_fields=['name'])  # updates only name column\nbulk_update(people, exclude_fields=['username'])  # updates all columns except username\nbulk_update(people, using='someotherdb')  # updates all columns using the given db\nbulk_update(people)  # updates all columns using the default db\nbulk_update(people, batch_size=50000)  # updates all columns by 50000 sized chunks using the default db\n```\n\nNote: You can consider to use `.only('name')` when you only want to update `name`, so that Django will only retrieve name data from db.\n\nAnd consider to use `.defer('username')` when you don't want to update `username`, so Django won't retrieve username from db.\nThese optimization can improve the performance even more.\n\nPerformance Tests:\n==================================\nHere we test the performance of the `bulk_update` function vs. simply calling\n`.save()` on every object update (`dmmy_update`). The interesting metric is the speedup using\nthe `bulk_update` function more than the actual raw times.\n\n\n```python\n# Note: SQlite is unable to run the `timeit` tests\n# due to the max number of sql variables\nIn [1]: import os\nIn [2]: import timeit\nIn [3]: import django\n\nIn [4]: os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'\nIn [5]: django.setup()\n\nIn [6]: from tests.fixtures import create_fixtures\n\nIn [7]: django.db.connection.creation.create_test_db()\nIn [8]: create_fixtures(1000)\n\nIn [9]: setup='''\nimport random\nfrom django_bulk_update import helper\nfrom tests.models import Person\nrandom_names = ['Walter', 'The Dude', 'Donny', 'Jesus']\nids = list(Person.objects.values_list('id', flat=True)[:1000])\npeople = Person.objects.filter(id__in=ids)\nfor p in people:\n    name = random.choice(random_names)\n    p.name = name\n    p.email = '%s@example.com' % name\nbu_update = lambda: helper.bulk_update(people, update_fields=['name', 'email'])\n'''\n\nIn [10]: bu_perf = min(timeit.Timer('bu_update()', setup=setup).repeat(7, 100))\n\nIn [11]: setup='''\nimport random\nfrom tests.models import Person\nfrom django.db.models import F\nrandom_names = ['Walter', 'The Dude', 'Donny', 'Jesus']\nids = list(Person.objects.values_list('id', flat=True)[:1000])\npeople = Person.objects.filter(id__in=ids)\ndef dmmy_update():\n    for p in people:\n        name = random.choice(random_names)\n        p.name = name\n        p.email = '%s@example.com' % name\n        p.save(update_fields=['name', 'email'])\n'''\n\nIn [12]: dmmy_perf = min(timeit.Timer('dmmy_update()', setup=setup).repeat(7, 100))\nIn [13]: print 'Bulk update performance: %.2f. Dummy update performance: %.2f. Speedup: %.2f.' % (bu_perf, dmmy_perf, dmmy_perf / bu_perf)\nBulk update performance: 7.05. Dummy update performance: 373.12. Speedup: 52.90.\n```\n\nRequirements\n==================================\n- Django 1.8+\n\nContributors\n==================================\n- [aykut](https://github.com/aykut)\n- [daleobrien](https://github.com/daleobrien)\n- [sruon](https://github.com/sruon)\n- [HowerHell](https://github.com/HoverHell)\n- [c-nichols](https://github.com/c-nichols)\n- [towr](https://github.com/towr)\n- [joshblum](https://github.com/joshblum)\n- [luzfcb](https://github.com/luzfcb)\n- [torchingloom](https://github.com/torchingloom)\n- [cihann](https://github.com/cihann)\n- [wetneb](https://github.com/wetneb)\n- [tatterdemalion](https://github.com/tatterdemalion)\n- [gabriel-laet](https://github.com/gabriel-laet)\n- [arnau126](https://github.com/arnau126)\n\nTODO\n==================================\n- Geometry Fields support\n\nLicense\n==================================\ndjango-bulk-update is released under the MIT License. See the LICENSE file for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faykut%2Fdjango-bulk-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faykut%2Fdjango-bulk-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faykut%2Fdjango-bulk-update/lists"}