Skip to main content

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

Project description

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

Django views:

from django.views.generic import DetailView
from django_display_ids import DisplayIDMixin

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

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"
    display_id_prefix = "inv"

Now your views accept:

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

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.

Related Projects

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.

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_display_ids-0.6.2.tar.gz (19.8 kB view details)

Uploaded Source

Built Distribution

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

django_display_ids-0.6.2-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file django_display_ids-0.6.2.tar.gz.

File metadata

  • Download URL: django_display_ids-0.6.2.tar.gz
  • Upload date:
  • Size: 19.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_display_ids-0.6.2.tar.gz
Algorithm Hash digest
SHA256 3a6d456df7df0e146d8eb2fa52ef3ed0753307dca6e752cfc4c7e447525e6cda
MD5 4eb573c80b73239225a9183b33bc2feb
BLAKE2b-256 0e3f523a48a3ba92f6c98b6e8032d4077caf9142ec4d7fc534f372b18e0d5972

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_display_ids-0.6.2.tar.gz:

Publisher: ci.yml on josephabrahams/django-display-ids

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_display_ids-0.6.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_display_ids-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 db1c8a8955f74785fdb9430a93c5f116aeee825c8eadb8e01d1dcd9b21af82ee
MD5 2c5ead98095403d4e23dc6eb68211266
BLAKE2b-256 52e7f126b1e10ea46477ec62965225f06da98e238be45371ce3f3e1632e2d603

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_display_ids-0.6.2-py3-none-any.whl:

Publisher: ci.yml on josephabrahams/django-display-ids

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