Skip to main content

django-display-ids

PyPI Python Django CI codecov Docs License: MIT

Stripe-like prefixed IDs for Django. Works with existing UUIDs — no schema changes.

Why?

UUIDv7 (native in Python 3.14+) offers excellent database performance with time-ordered indexing. But they lack context — seeing 550e8400-e29b-41d4-a716-446655440000 in a URL or log doesn't tell you what kind of object it refers to.

Display IDs like inv_2aUyqjCzEIiEcYMKj7TZtw are more useful: the prefix identifies the object type at a glance, and they're compact and URL-safe. But storing display IDs in the database is far less efficient than native UUIDs.

Different consumers have different needs:

  • Humans prefer slugs (my-invoice) or display IDs (inv_xxx)
  • APIs and integrations work well with UUIDs

This library gives you the best of both worlds: accept any format in your URLs and API endpoints, then translate to an efficient UUID lookup in the database. Store UUIDs, expose whatever format your users need.

Installation

pip install django-display-ids

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    "django_display_ids",
]

Quick Start

Add the mixin to your model:

# models.py

import uuid
from django.db import models
from django_display_ids import DisplayIDModel

class Invoice(DisplayIDModel, models.Model):
    display_id_prefix = "inv"
    uuid_field = "uuid"
    uuid = models.UUIDField(default=uuid.uuid7, unique=True)
    slug = models.SlugField(unique=True)

Update your URLconf:

# urls.py

from django.urls import path, register_converter
from django_display_ids import DisplayIDOrUUIDOrSlugConverter

register_converter(DisplayIDOrUUIDOrSlugConverter, "identifier")

urlpatterns = [
    path("invoices/<identifier:id>/", InvoiceDetailView.as_view()),
]

Add the mixin to your view:

# views.py

# Django CBV
from django.views.generic import DetailView
from django_display_ids import DisplayIDMixin

class InvoiceDetailView(DisplayIDMixin, DetailView):
    model = Invoice
    lookup_param = "id"

# Django REST Framework
from rest_framework.viewsets import ModelViewSet
from django_display_ids.contrib.rest_framework import DisplayIDMixin

class InvoiceViewSet(DisplayIDMixin, ModelViewSet):
    queryset = Invoice.objects.all()
    serializer_class = InvoiceSerializer
    lookup_url_kwarg = "id"

Your views now accept:

  • inv_2aUyqjCzEIiEcYMKj7TZtw (display ID)
  • 550e8400-e29b-41d4-a716-446655440000 (UUID)
  • my-invoice (slug)

Update your templates:

{% load display_ids %}

{{ invoice.display_id }}                       {# inv_2aUyqjCzEIiEcYMKj7TZtw #}
{{ order.customer_id|display_id:"cust" }}      {# encode any UUID #}

Features

  • Multiple identifier formats: display ID (prefix_base62uuid), UUID (v4/v7), slug
  • Framework support: Django CBVs and Django REST Framework
  • Template filter: Encode UUIDs as display IDs in templates
  • Zero model changes required: Works with any existing UUID field
  • OpenAPI integration: Automatic schema generation with drf-spectacular

Documentation

Full documentation at django-display-ids.readthedocs.io.

Contributing

See CONTRIBUTING.md.

If you need ID generation and storage (custom model fields), consider:

django-display-ids works with existing UUID fields and handles resolution only — no migrations required.

Metadata

Release files for django-display-ids 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-display-ids 0.7.1
File Size Uploaded Provenance Actions
django_display_ids-0.7.1.tar.gz 21.0 kB With provenance Details for django_display_ids-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-display-ids 0.7.1
File Interpreter ABI Platform Actions
django_display_ids-0.7.1-py3-none-any.whl Python 3 none any Details for django_display_ids-0.7.1-py3-none-any.whl

Total release size: 52.0 kB

Release files / django_display_ids-0.7.1.tar.gz

Download URL django_display_ids-0.7.1.tar.gz
Size 21.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c9026623de310f6ea2f07e3031860ca78ea0c184fe36629fd0f69dcdf4ef31f6
BLAKE2b-256 checksum
How to use checksums
e836383c85174daac3747b4b07afb102803f45c5af0c47b67dd155e4bc8ff92b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / django_display_ids-0.7.1-py3-none-any.whl

Download URL django_display_ids-0.7.1-py3-none-any.whl
Size 31.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77c463b1fcc12d09ad283ba6a957c6a367e6404d0f2bcc8f6f11035639cee9fa
BLAKE2b-256 checksum
How to use checksums
59c6daa6926da82de259d386b5981c0da28251de081f01ec8f2f8ea148ccd8f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Security for django-display-ids 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_display_ids-0.7.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page