All Projects → aykut → Django Bulk Update

aykut / Django Bulk Update

Licence: mit
Bulk update using one query over Django ORM

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Django Bulk Update

Westore
更好的小程序项目架构
Stars: ✭ 3,897 (+864.6%)
Mutual labels:  update
Pipupgrade
🗽 Like yarn outdated/upgrade, but for pip. Upgrade all your pip packages and automate your Python Dependency Management.
Stars: ✭ 391 (-3.22%)
Mutual labels:  update
Django Multiple User Types Example
Django Quiz Application
Stars: ✭ 395 (-2.23%)
Mutual labels:  django
React Query
⚛️ Hooks for fetching, caching and updating asynchronous data in React
Stars: ✭ 24,427 (+5946.29%)
Mutual labels:  update
Coderedcms
A content management system for marketing websites based on Django and Wagtail.
Stars: ✭ 386 (-4.46%)
Mutual labels:  django
Githubupdates
Cocoa framework to install application updates from GitHub releases.
Stars: ✭ 393 (-2.72%)
Mutual labels:  update
Docker Django
A complete docker package for deploying django which is easy to understand and deploy anywhere.
Stars: ✭ 378 (-6.44%)
Mutual labels:  django
Mayan Edms
Repository mirror of GtLab: https://gitlab.com/mayan-edms/mayan-edms Please use the upstream repository for issues and pull requests.
Stars: ✭ 398 (-1.49%)
Mutual labels:  django
Django React Boilerplate
DIY Django + React Boilerplate for starting your SaaS
Stars: ✭ 385 (-4.7%)
Mutual labels:  django
Nupdate
A comfortable update solution for .NET-applications.
Stars: ✭ 394 (-2.48%)
Mutual labels:  update
Openwisp Controller
Network and WiFi controller: provisioning, configuration management and updates, (pull via openwisp-config or push via SSH), x509 PKI management and more. Mainly OpenWRT, but designed to work also on other systems.
Stars: ✭ 377 (-6.68%)
Mutual labels:  django
Onlinejudge
open source online judge based on Vue, Django and Docker. | 青岛大学开源 Online Judge | QQ群 496710125 | [email protected]
Stars: ✭ 4,458 (+1003.47%)
Mutual labels:  django
Self update
Self updates for rust executables
Stars: ✭ 394 (-2.48%)
Mutual labels:  update
Awesome Django
A curated list of awesome things related to Django
Stars: ✭ 4,770 (+1080.69%)
Mutual labels:  django
Django Shorturls
A URL shortening app for Django
Stars: ✭ 397 (-1.73%)
Mutual labels:  django
Djangoblog
🍺基于Django的博客系统
Stars: ✭ 4,256 (+953.47%)
Mutual labels:  django
Siren
Siren checks a user's currently installed version of your iOS app against the version that is currently available in the App Store.
Stars: ✭ 3,892 (+863.37%)
Mutual labels:  update
Ring
Python cache interface with clean API and built-in memcache & redis + asyncio support.
Stars: ✭ 404 (+0%)
Mutual labels:  django
Django With Vuejs
Fast and clear in DevOps.
Stars: ✭ 398 (-1.49%)
Mutual labels:  django
Qikqiak.com
关注容器、kubernetes、devops、python、golang、微服务等技术 🎉🎉🎉
Stars: ✭ 394 (-2.48%)
Mutual labels:  django

django-bulk-update

Build Status Coverage Status

Simple bulk update over Django ORM or with helper function.

This project aims to bulk update given objects using one query over Django ORM.

Installation

pip install django-bulk-update

Usage

With manager:

import random
from django_bulk_update.manager import BulkUpdateManager
from tests.models import Person

class Person(models.Model):
    ...
    objects = BulkUpdateManager()

random_names = ['Walter', 'The Dude', 'Donny', 'Jesus']
people = Person.objects.all()
for person in people:
  person.name = random.choice(random_names)

Person.objects.bulk_update(people, update_fields=['name'])  # updates only name column
Person.objects.bulk_update(people, exclude_fields=['username'])  # updates all columns except username
Person.objects.bulk_update(people)  # updates all columns
Person.objects.bulk_update(people, batch_size=50000)  # updates all columns by 50000 sized chunks

With helper:

import random
from django_bulk_update.helper import bulk_update
from tests.models import Person

random_names = ['Walter', 'The Dude', 'Donny', 'Jesus']
people = Person.objects.all()
for person in people:
  person.name = random.choice(random_names)

bulk_update(people, update_fields=['name'])  # updates only name column
bulk_update(people, exclude_fields=['username'])  # updates all columns except username
bulk_update(people, using='someotherdb')  # updates all columns using the given db
bulk_update(people)  # updates all columns using the default db
bulk_update(people, batch_size=50000)  # updates all columns by 50000 sized chunks using the default db

Note: You can consider to use .only('name') when you only want to update name, so that Django will only retrieve name data from db.

And consider to use .defer('username') when you don't want to update username, so Django won't retrieve username from db. These optimization can improve the performance even more.

Performance Tests:

Here we test the performance of the bulk_update function vs. simply calling .save() on every object update (dmmy_update). The interesting metric is the speedup using the bulk_update function more than the actual raw times.

# Note: SQlite is unable to run the `timeit` tests
# due to the max number of sql variables
In [1]: import os
In [2]: import timeit
In [3]: import django

In [4]: os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
In [5]: django.setup()

In [6]: from tests.fixtures import create_fixtures

In [7]: django.db.connection.creation.create_test_db()
In [8]: create_fixtures(1000)

In [9]: setup='''
import random
from django_bulk_update import helper
from tests.models import Person
random_names = ['Walter', 'The Dude', 'Donny', 'Jesus']
ids = list(Person.objects.values_list('id', flat=True)[:1000])
people = Person.objects.filter(id__in=ids)
for p in people:
    name = random.choice(random_names)
    p.name = name
    p.email = '%[email protected]' % name
bu_update = lambda: helper.bulk_update(people, update_fields=['name', 'email'])
'''

In [10]: bu_perf = min(timeit.Timer('bu_update()', setup=setup).repeat(7, 100))

In [11]: setup='''
import random
from tests.models import Person
from django.db.models import F
random_names = ['Walter', 'The Dude', 'Donny', 'Jesus']
ids = list(Person.objects.values_list('id', flat=True)[:1000])
people = Person.objects.filter(id__in=ids)
def dmmy_update():
    for p in people:
        name = random.choice(random_names)
        p.name = name
        p.email = '%[email protected]' % name
        p.save(update_fields=['name', 'email'])
'''

In [12]: dmmy_perf = min(timeit.Timer('dmmy_update()', setup=setup).repeat(7, 100))
In [13]: print 'Bulk update performance: %.2f. Dummy update performance: %.2f. Speedup: %.2f.' % (bu_perf, dmmy_perf, dmmy_perf / bu_perf)
Bulk update performance: 7.05. Dummy update performance: 373.12. Speedup: 52.90.

Requirements

  • Django 1.8+

Contributors

TODO

  • Geometry Fields support

License

django-bulk-update is released under the MIT License. See the LICENSE file for more details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].