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
Metadata
Release files for django-psycopg-infinity 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_psycopg_infinity-0.1.1.tar.gz | 13.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_psycopg_infinity-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / django_psycopg_infinity-0.1.1.tar.gz
| Download URL | django_psycopg_infinity-0.1.1.tar.gz |
|---|---|
| Size | 13.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee65f12a77fd61f5c1a250454775e8b447fdb90cf6c532c363d1320500548f1b
|
|
BLAKE2b-256 checksum How to use checksums |
44da4ea88bf5d277e470ec537273b4d6fde28a262c67333020b4f9e93e33c172
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|
Release files / django_psycopg_infinity-0.1.1-py3-none-any.whl
| Download URL | django_psycopg_infinity-0.1.1-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78687460c6052cf0bccf74a0118be9817d2ee5445cfabb3ddb4b2fc4ba5fd1dd
|
|
BLAKE2b-256 checksum How to use checksums |
1bf4efa5d65e3d2b58b511b85c4aa4386bad403d5716b3e5e748e3f3392a7d79
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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}
|