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.4.tar.gz (20.1 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.4-py3-none-any.whl (30.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_display_ids-0.5.4.tar.gz
  • Upload date:
  • Size: 20.1 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.4.tar.gz
Algorithm Hash digest
SHA256 18030a6949149d17657ca2f33013e75d68cab01b36608788d65f6159757cd9c5
MD5 9c4e00c62bf964a725a4d3d935ea204f
BLAKE2b-256 8d664562db77fe207831c53e769a1ef07c0f28e80c59c1bb260439f79093d542

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for django_display_ids-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 55d41e21753f46e943e098e89fac9b27c96e97bd0f77cb1eb8dd9292b2b0c9f3
MD5 1ebf1ad492f2d962f36a3816a8a318ba
BLAKE2b-256 7de09f0c23051bf51575c4fbfe171d8b74b31017004eeeec84588a618a3e7af1

See more details on using hashes here.

Provenance

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