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 the contributing guide.

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.5.1.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.5.1-py3-none-any.whl (30.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_display_ids-0.5.1.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.5.1.tar.gz
Algorithm Hash digest
SHA256 4e3f796d3c0fe440e7323f2dfecd50da7ca253dc94440425d94050d8bbc4bf55
MD5 9b34ba0ef7a73e6cee153d9bbb7577fd
BLAKE2b-256 cc79243fd354890138a900ff595f90a6105986ebbbf45b93c1a30f7bce105bd0

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_display_ids-0.5.1.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.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_display_ids-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 75e1a0fbcbf083b1f4abad77684a4308466fe1fe63d0de2144098209353b2937
MD5 80b5889546b6022e9bb1d8e3688d9a3c
BLAKE2b-256 107339fec8d71a84081cfcf209090494fe3deef77598bd1dcd1ca5e009cbb8a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_display_ids-0.5.1-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