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 - 4.2, 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.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

django_pgbulk-2.1.1-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for django_pgbulk-2.1.1.tar.gz
Algorithm Hash digest
SHA256 e5dd8f819b26ae6730ef9642cee35f22cc15a6950465b1f0efa6243c461894c8
MD5 95aad55aef0661c91bc6f73104cfd0ad
BLAKE2b-256 e21af6f3fc6f9d766f5b2315c801504baef041636b9ec376ea9d53ae5525306a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for django_pgbulk-2.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e630b44febbc91a98a7a1ef5695039a44ba899c0b74cb30f11346d753fa6039c
MD5 5b374d45d2ad60952d70f05b65482a42
BLAKE2b-256 911e7a921893e7f72f5a0c98dc7cc7c7755bde5e0a534470115a304aa12a4203

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