Skip to main content

Django field and PostgreSQL backend for infinity timestamp support with psycopg3

Project description

Django field and PostgreSQL backend for infinity timestamp support with psycopg >=3.

Maps PostgreSQL’s infinity / -infinity timestamp values to datetime.max / datetime.min in Python, making them usable as regular DateTimeField values in Django models.

Currently only DateTimeField is supported. DateField and TimeField infinity values are not yet handled. Contributions welcome!

Installation

pip install django-psycopg-infinity

Configuration

Set the custom database backend in your Django settings:

DATABASES = {
    "default": {
        "ENGINE": "django_psycopg_infinity.backends.postgresql",
        # ... other settings
    },
}

Then use DateTimeInfinityField in your models:

from django.db import models
from django_psycopg_infinity.fields import DateTimeInfinityField

class MyModel(models.Model):
    valid_until = DateTimeInfinityField(null=True, blank=True)

Usage

from datetime import datetime

# Store positive infinity
obj.valid_until = datetime.max
obj.save()

# Or use the string representation
obj.valid_until = "infinity"
obj.save()

# Retrieve - the returned datetime matches the column type:
# aware (UTC) for `timestamp with time zone` columns,
# naive for `timestamp without time zone` columns.
obj.refresh_from_db()
assert obj.valid_until == datetime.max

Convenience constants

The package avoids calling timezone.get_default_timezone() at import time so it can be imported before Django is fully configured. If you need timezone-aware infinity sentinels (e.g. for model field defaults), derive them in your own module:

from django_psycopg_infinity.utils import INFINITY, NEGATIVE_INFINITY, make_aware

LOCAL_INFINITY = make_aware(INFINITY)
LOCAL_NEGATIVE_INFINITY = make_aware(NEGATIVE_INFINITY)

Then use them as defaults:

class MyModel(models.Model):
    end_time = DateTimeInfinityField(default=LOCAL_INFINITY)

For fields backed by timestamp without time zone columns, use the bare INFINITY / NEGATIVE_INFINITY constants instead — a tz-aware default would mismatch the naive values that the loader returns from those columns.

Development

Tests require a running PostgreSQL instance:

cp .env.example .env   # edit as needed
uv run runtests.py

Releasing

Releases are published to PyPI automatically when a version tag is pushed. The CI runs the full test suite before publishing.

Create a new release on GitHub with a v-prefixed tag (e.g. v0.1.0) and the workflow handles the rest.

Versioning is derived from git tags via hatch-vcs, so there are no version strings to update manually.

License

Apache-2.0

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_psycopg_infinity-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_psycopg_infinity-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file django_psycopg_infinity-0.1.1.tar.gz.

File metadata

  • Download URL: django_psycopg_infinity-0.1.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_psycopg_infinity-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ee65f12a77fd61f5c1a250454775e8b447fdb90cf6c532c363d1320500548f1b
MD5 c2ef8d81bcddbf6bc002e38862fa861e
BLAKE2b-256 44da4ea88bf5d277e470ec537273b4d6fde28a262c67333020b4f9e93e33c172

See more details on using hashes here.

File details

Details for the file django_psycopg_infinity-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_psycopg_infinity-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.17 {"installer":{"name":"uv","version":"0.11.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"25.11","id":"xantusia","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for django_psycopg_infinity-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78687460c6052cf0bccf74a0118be9817d2ee5445cfabb3ddb4b2fc4ba5fd1dd
MD5 23ea8c677106d040d327f8d64fbed921
BLAKE2b-256 1bf4efa5d65e3d2b58b511b85c4aa4386bad403d5716b3e5e748e3f3392a7d79

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page