semvec/pypi-packages huggingface dataset:
django-pgbulk 3.3.0
Native Postgres update, upsert, and copy operations.
License: BSD-3-Clause
Requires Python: <4,>=3.10.0

# 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)), bulk updates, and [COPY FROM](https://www.postgresql.org/docs/current/sql-copy.html).

Bulk upserts can distinguish between updated/created rows and ignore unchanged 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.

Bulk copies can significantly speed-up bulk inserts, sometimes by an order of magnitude over Django's `bulk_create`.

## Quick Start

### Examples

#### Update or insert rows

```python
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"]
)
```

#### Bulk update rows

```python
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']
)
```

#### Copy rows into a table

```python
import pgbulk

pgbulk.copy(
    MyModel,
    # Insert these rows using COPY FROM
    [
        MyModel(id=1, some_attr='some_val1'),
        MyModel(id=2, some_attr='some_val2')
    ],
)
```

### Advanced Features

Here are some advanced features at a glance:

- `pgbulk.upsert` can categorize which rows were inserted or updated.
- `pgbulk.upsert` and `pgbulk.update` can ignore updating unchanged fields.
- `pgbulk.upsert` and `pgbulk.update` can use expressions in updates.

## Documentation

[View the django-pgbulk docs here](https://django-pgbulk.readthedocs.io/) for more examples.

## Compatibility

`django-pgbulk` is compatible with Python 3.10 - 3.14, Django 4.2 - 6.0, Psycopg 2 - 3, and Postgres 14 - 18.

## Installation

Install `django-pgbulk` with:

    pip3 install django-pgbulk

## 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
django-pgmigrate 1.6.0
Avoid costly downtime during Postgres migrations.
License: BSD-3-Clause
Requires Python: <4,>=3.10.0

# django-pgmigrate

`django-pgmigrate` helps you avoid costly downtime with Postgres migrations.

Imagine the following happens:

1. A long-running task queries a model in a transaction and keeps the transaction open.
2. `python manage.py migrate` tries to change a field on the model.

Because of how Postgres queues locks, this common scenario causes **every** subsequent query on the model to block until the query from 1) has finished.

`django-pgmigrate` provides the following features to alleviate problematic locking scenarios when running migrations:

* Detect blocking queries and terminate them automatically (the default behavior).
* Print blocking queries so that you can inspect and terminate them manually.
* Set the lock timeout so that migrations are terminated if they block too long.

## Installation

Install `django-pgmigrate` with:

    pip3 install django-pgmigrate

After this, add `pgactivity`, `pglock`, and `pgmigrate` to the `INSTALLED_APPS` setting of your Django project.

## Quick Start

After following the installation instructions, running `python manage.py migrate` will automatically terminate any blocking queries. Here's an example of what it looks like:

![Terminate Blocking](docs/static/terminate_blocking.png)

There are two additional outputs in the `migrate` command versus the original:

1. The first output line shows the Postgres process ID. This is useful for querying activity that's blocking the process.
2. The yellow text shows when a blocking query was detected and terminated. In our case, it was blocking auth migration 12.

You can configure `django-pgmigrate` to show blocked queries instead of automatically killing them, and you can also set the lock timeout to automatically cancel migrations if they block for too long. See the documentation section below for more details.

## Compatibility

`django-pgmigrate` is compatible with Python 3.10 - 3.14, Django 4.2 - 6.0, Psycopg 2 - 3, and Postgres 14 - 18.

## Documentation

[View the django-pgmigrate docs here](https://django-pgmigrate.readthedocs.io) to learn more about:

* How blocking queries are automatically terminated.
* Configuring the command to show blocking activity instead of terminating it, along with instructions on how to manually view and terminate activity.
* Configuring lock timeouts to automatically stop migrations if they block for too long.
* Advanced usage such as creating custom actions to run when queries are blocked.

## Contributing Guide

For information on setting up django-pgmigrate for development and contributing changes, view [CONTRIBUTING.md](CONTRIBUTING.md).

## Creators

- [Wes Kendall](https://github.com/wesleykendall)
- [Paul Gilmartin](https://github.com/PaulGilmartin)
django-pgstats 1.6.0
Commands and models for tracking internal postgres stats.
License: BSD-3-Clause
Requires Python: <4,>=3.10.0

# django-pgstats

`django-pgstats` provides commands and models for tracking internal postgres stats. Specifically, the `IndexStats` model stores stats about postgres indices and the `TableStats` model stores stats about postgres tables.

Postgres stat tables contain global statistical information. `django-pgstats` is meant to be executed periodically so that one can later analyze table and index usage. This is done by periodically calling `python manage.py snapshot_pgstats` using a task runner such as [Celery](http://www.celeryproject.org/).

Stats are stored as JSON fields in the respective `IndexStats` and `TableStats` models. Each key in the JSON field is in the format of `{schema}.{table}` for table stats or `{schema}.{table}.{index}` for index stats.

## Compatibility

`django-pgstats` is compatible with Python 3.10 - 3.14, Django 4.2 - 6.0, Psycopg 2 - 3, and Postgres 14 - 18.

## Documentation

[View the django-pgstats docs here](https://django-pgstats.readthedocs.io/)

## Installation

Install `django-pgstats` with:

    pip3 install django-pgstats
After this, add `pgstats` to the `INSTALLED_APPS` setting of your Django project.

## Contributing Guide

For information on setting up django-pgstats for development and contributing changes, view [CONTRIBUTING.md](CONTRIBUTING.md).

## Creators

- @wesleykendall (Wes Kendall)
- @tomage (Tómas Árni Jónasson)