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.

Creators

Other Contributors

  • @max-muoto
  • @dalberto

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.5.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

django_pgbulk-2.5.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_pgbulk-2.5.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/5.15.0-1057-aws

File hashes

Hashes for django_pgbulk-2.5.0.tar.gz
Algorithm Hash digest
SHA256 53adcb049d7cfd224d91f704f31a531f42a0e14658cf1e68b3627a7a35b6d928
MD5 928e3ca753a210614401da1c607ce0c9
BLAKE2b-256 c3557b11d9305345bf9d9d0291b8fa90f7f2bdab73f50a198be16049ac872171

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_pgbulk-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/5.15.0-1057-aws

File hashes

Hashes for django_pgbulk-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 07a44014cbd801f0cc10a6d1e302a4727ae5233b3005951907f11fea1084c643
MD5 4508acdc54a9199d0ff394753b54b871
BLAKE2b-256 d02b2fd0509548461bad9c6e65ef08485da1223e42d987473594a9fe04cb59a7

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