Skip to main content

Namespaced UUIDv7 identifiers for Django, stored as PostgreSQL UUIDs

Project description

django-niceid

Namespaced, Crockford base32-encoded UUIDv7 identifiers for Django. IDs look like user_1KGGWGM8FEABRJA533GJKYW0B in Python and APIs, while PostgreSQL stores them as native UUID values (sortable, compact, index-friendly).

Requirements

  • Python 3.14+ (uuid.uuid7 in the standard library)
  • Django 5.1+
  • PostgreSQL 18+ with native UUID support and a built-in uuidv7() function

Install

pip install django-niceid

Optional integrations:

pip install django-niceid[drf]      # Django REST Framework
pip install django-niceid[ninja]    # Django Ninja
pip install django-niceid[pydantic] # Pydantic v2 schemas
pip install django-niceid[tortoise] # django-tortoise ORM bridge

Quickstart

Add the app to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "niceid.apps.NiceIDConfig",
]

Define a model with a class-level namespace (2–16 lowercase letters or underscores):

from niceid.models import NiceIDModel


class User(NiceIDModel):
    namespace = "user"

    class Meta:
        # your options
        pass

Each row gets a primary key like user_1KGGWGM8FEABRJA533GJKYW0B. The value is generated by PostgreSQL via db_default=uuidv7() and exposed in Python as a NiceID instance.

PostgreSQL uuidv7()

On PostgreSQL 18+, uuidv7() is available without extra setup. Ensure your database supports it before running migrations:

SELECT uuidv7();

URL converter

The app config registers a path converter named niceid:

from django.urls import path

urlpatterns = [
    path("users/<niceid:user_id>/", user_detail),
]

user_id in the view is a NiceID instance.

Optional integrations

Django REST Framework

from niceid.drf import NiceIDSerializerField, NiceIDRelatedField

class UserSerializer(serializers.ModelSerializer):
    id = NiceIDSerializerField(read_only=True)
    team_id = NiceIDRelatedField(queryset=Team.objects.all(), source="team")

Django Ninja

Install django-niceid[ninja]. Field registration runs automatically in NiceIDConfig.ready().

Pydantic

Install django-niceid[pydantic]:

from pydantic import BaseModel
from niceid import NiceID

class Payload(BaseModel):
    user_id: NiceID

ID format

Part Rule
Namespace [a-z_]{2,16}
Separator _
Encoded UUID 25 Crockford base32 characters (UUIDv7)

Example: user_1KGGWGM8FEABRJA533GJKYW0B

Limitations (v0.1.0)

  • PostgreSQL only for database fields (native UUID column + uuidv7() default).
  • Python 3.14+ only.
  • Non-primary-key NiceIDField usage requires an explicit namespace= on the field.

Development

pip install -e ".[dev]"
pytest -m "not postgres"
docker compose up -d
POSTGRES_HOST=localhost POSTGRES_PORT=54329 pytest -m postgres

See CONTRIBUTING.md.

License

MIT — see LICENSE.

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_niceid-0.1.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

django_niceid-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file django_niceid-0.1.0.tar.gz.

File metadata

  • Download URL: django_niceid-0.1.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_niceid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f4a3cf5327b35235f868867a7fff790d61059f2493e97de527bd9871cb2b27b5
MD5 4e8b49c968b2dbbb8a0b4914c4ff334e
BLAKE2b-256 ceb1d66633739bec4c898e0fce5652770e8abb4d09c6beb649834759f5865be9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_niceid-0.1.0.tar.gz:

Publisher: release.yml on owais/django-niceid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_niceid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: django_niceid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_niceid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b966fc814f3c72549259fe206a2b4adcca921dd37617215db2aab2adc178dae9
MD5 78832891958f2afe6d1d4e67c41ad10d
BLAKE2b-256 63780e5484537fef3bc4c754d606d27f32fc7695b0d560d9b867333dae7066db

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_niceid-0.1.0-py3-none-any.whl:

Publisher: release.yml on owais/django-niceid

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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