Skip to main content

Native postgres bulk update and upsert operations.

Project description

django-pgbulk

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

pgbulk.upsert(
    MyModel,
    [
        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.
    ["int_field"],
    # These are the fields that will be updated if the row already
    # exists. If not provided, all fields will be updated
    ["some_attr"]
)

Do a bulk update on a model:

import pgbulk

pgbulk.update(
    MyModel,
    [
        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
    ['some_attr']
)

View the django-pgbulk docs for more information.

Compatibility

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

Documentation

View the django-pgbulk docs here

Installation

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 CONTRIBUTING.md.

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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file django_pgbulk-2.3.1.tar.gz.

File metadata

  • Download URL: django_pgbulk-2.3.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/5.15.0-1056-aws

File hashes

Hashes for django_pgbulk-2.3.1.tar.gz
Algorithm Hash digest
SHA256 26e6af314926862593e915d5420c0f45ebe9a79beb4541b7b1c714bb1a08b17c
MD5 ca8366ef764cc2db403248e160355d93
BLAKE2b-256 7dd4f4bb75647750c6992f51cd32bdd4de373fade4cce0a89e4f8b2375d0d254

See more details on using hashes here.

File details

Details for the file django_pgbulk-2.3.1-py3-none-any.whl.

File metadata

  • Download URL: django_pgbulk-2.3.1-py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/5.15.0-1056-aws

File hashes

Hashes for django_pgbulk-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da166a6f8c183c2d03e91870158ccc129297ecd03b7a5c52036d08c3943ff293
MD5 3fec00834a75eb1ba4d7c2de78e7af33
BLAKE2b-256 70db811509ca1c656665e6682c386935683a18a13e2d259f23370f4cfcf74bb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page