django-pgbulk


Namedjango-pgbulk JSON
Version 2.4.0 PyPI version JSON
download
home_pagehttps://github.com/Opus10/django-pgbulk
SummaryNative postgres bulk update and upsert operations.
upload_time2024-04-24 01:40:01
maintainerNone
docs_urlNone
authorWes Kendall
requires_python<4,>=3.8.0
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-pgbulk

`django-pgbulk` provides functions for doing native Postgres bulk upserts (i.e. [UPDATE ON CONFLICT](https://www.postgresql.org/docs/current/sql-insert.html)) 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](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#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](https://django-pgbulk.readthedocs.io/) 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](https://django-pgbulk.readthedocs.io/)

## 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](CONTRIBUTING.md).

## Creators

- [Wes Kendall](https://github.com/wesleykendall)

## Other Contributors

- @max-muoto
- @dalberto

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Opus10/django-pgbulk",
    "name": "django-pgbulk",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.8.0",
    "maintainer_email": null,
    "keywords": null,
    "author": "Wes Kendall",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/11/74/d9857a37d4ec6d635a0cca1e86568d0a154db2d8a9e1eb9540288e0279a2/django_pgbulk-2.4.0.tar.gz",
    "platform": null,
    "description": "# django-pgbulk\n\n`django-pgbulk` provides functions for doing native Postgres bulk upserts (i.e. [UPDATE ON CONFLICT](https://www.postgresql.org/docs/current/sql-insert.html)) and bulk updates.\n\nBulk upserts can distinguish between updated and created rows and optionally ignore redundant updates.\n\nBulk updates are true bulk updates, unlike Django's [bulk_update](https://docs.djangoproject.com/en/4.2/ref/models/querysets/#bulk-update) which can still suffer from *O(N)* queries and can create poor locking scenarios.\n\n## Quick Start\n\nDo a bulk upsert on a model:\n\n    import pgbulk\n\n    pgbulk.upsert(\n        MyModel,\n        [\n            MyModel(int_field=1, some_attr=\"some_val1\"),\n            MyModel(int_field=2, some_attr=\"some_val2\"),\n        ],\n        # These are the fields that identify the uniqueness constraint.\n        [\"int_field\"],\n        # These are the fields that will be updated if the row already\n        # exists. If not provided, all fields will be updated\n        [\"some_attr\"]\n    )\n\nDo a bulk update on a model:\n\n    import pgbulk\n\n    pgbulk.update(\n        MyModel,\n        [\n            MyModel(id=1, some_attr='some_val1'),\n            MyModel(id=2, some_attr='some_val2')\n        ],\n        # These are the fields that will be updated. If not provided,\n        # all fields will be updated\n        ['some_attr']\n    )\n\n[View the django-pgbulk docs](https://django-pgbulk.readthedocs.io/) for more information.\n\n## Compatibility\n\n`django-pgbulk` is compatible with Python 3.8 - 3.12, Django 3.2 - 5.0, Psycopg 2 - 3, and Postgres 12 - 16.\n\n## Documentation\n\n[View the django-pgbulk docs here](https://django-pgbulk.readthedocs.io/)\n\n## Installation\n\nInstall `django-pgbulk` with:\n\n    pip3 install django-pgbulk\n\nAfter this, add `pgbulk` to the `INSTALLED_APPS` setting of your Django project.\n\n## Contributing Guide\n\nFor information on setting up django-pgbulk for development and contributing changes, view [CONTRIBUTING.md](CONTRIBUTING.md).\n\n## Creators\n\n- [Wes Kendall](https://github.com/wesleykendall)\n\n## Other Contributors\n\n- @max-muoto\n- @dalberto\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "Native postgres bulk update and upsert operations.",
    "version": "2.4.0",
    "project_urls": {
        "Documentation": "https://django-pgbulk.readthedocs.io",
        "Homepage": "https://github.com/Opus10/django-pgbulk",
        "Repository": "https://github.com/Opus10/django-pgbulk"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "095fef08f2728ab3c638a63053566b6563b11d7c3c8add567c4fa2af006fb4d2",
                "md5": "b2f3abf17f95797d8a225e7a900f4181",
                "sha256": "045f137a6107d028340df547334060e6edaefd842f9be30ec3b9ea700c7e19dc"
            },
            "downloads": -1,
            "filename": "django_pgbulk-2.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b2f3abf17f95797d8a225e7a900f4181",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4,>=3.8.0",
            "size": 9758,
            "upload_time": "2024-04-24T01:39:59",
            "upload_time_iso_8601": "2024-04-24T01:39:59.623292Z",
            "url": "https://files.pythonhosted.org/packages/09/5f/ef08f2728ab3c638a63053566b6563b11d7c3c8add567c4fa2af006fb4d2/django_pgbulk-2.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1174d9857a37d4ec6d635a0cca1e86568d0a154db2d8a9e1eb9540288e0279a2",
                "md5": "242d4729790b6c94754d33d5c61b5515",
                "sha256": "e42b93d1b8b86e45c3f4731cc044a6cc58c8d0ee5c9697af028ac11484c9c200"
            },
            "downloads": -1,
            "filename": "django_pgbulk-2.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "242d4729790b6c94754d33d5c61b5515",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.8.0",
            "size": 9886,
            "upload_time": "2024-04-24T01:40:01",
            "upload_time_iso_8601": "2024-04-24T01:40:01.915482Z",
            "url": "https://files.pythonhosted.org/packages/11/74/d9857a37d4ec6d635a0cca1e86568d0a154db2d8a9e1eb9540288e0279a2/django_pgbulk-2.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-24 01:40:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Opus10",
    "github_project": "django-pgbulk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "tox": true,
    "lcname": "django-pgbulk"
}
        
Elapsed time: 0.24014s