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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django_pgbulk-2.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96a60cda70ec5e0497efae5d1b665eedf65c59dc3e55aa10704c393792da6aae |
|
MD5 | a12287f76e1216d9797adb09e2b6d145 |
|
BLAKE2b-256 | e3c6ad84fc11db4ecc51aebb21b5d6a7d3aca150b746df5c19ff22763030b432 |