Skip to main content

Native postgres bulk update and upsert operations.

Project description


django-pgbulk provides functions for doing native Postgres bulk upserts (i.e. UPDATE ON CONFLICT) and bulk updates.

Bulk upserts can distinguish between updated and created rows and optionally ignore redundant updates.

Bulk updates are true bulk updates, unlike Django's bulk_update which can still suffer from O(N) queries and can create poor locking scenarios.

Quick Start

Do a bulk upsert on a model:

import pgbulk

        MyModel(int_field=1, some_attr="some_val1"),
        MyModel(int_field=2, some_attr="some_val2"),
    # These are the fields that identify the uniqueness constraint.
    # These are the fields that will be updated if the row already
    # exists. If not provided, all fields will be updated

Do a bulk update on a model:

import pgbulk

        MyModel(id=1, some_attr='some_val1'),
        MyModel(id=2, some_attr='some_val2')
    # These are the fields that will be updated. If not provided,
    # all fields will be updated

View the django-pgbulk docs for more information.


django-pgbulk is compatible with Python 3.8 - 3.12, Django 3.2 - 5.0, Psycopg 2 - 3, and Postgres 12 - 16.


View the django-pgbulk docs here


Install django-pgbulk with:

pip3 install django-pgbulk

After this, add pgbulk to the INSTALLED_APPS setting of your Django project.

Contributing Guide

For information on setting up django-pgbulk for development and contributing changes, view

Primary Authors

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_pgbulk-2.3.1.tar.gz (9.6 kB view hashes)

Uploaded Source

Built Distribution

django_pgbulk-2.3.1-py3-none-any.whl (9.6 kB view hashes)

Uploaded Python 3

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