Stripe-like prefixed IDs for Django. Works with existing UUIDs — no schema changes.
Project description
django-display-ids
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-prefix-id — PrefixIDField that generates and stores base62-encoded UUIDs
- django-spicy-id — Drop-in AutoField replacement
- django-charid-field — CharField wrapper supporting cuid, ksuid, ulid
django-display-ids works with existing UUID fields and handles resolution only — no migrations required.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18030a6949149d17657ca2f33013e75d68cab01b36608788d65f6159757cd9c5
|
|
| MD5 |
9c4e00c62bf964a725a4d3d935ea204f
|
|
| BLAKE2b-256 |
8d664562db77fe207831c53e769a1ef07c0f28e80c59c1bb260439f79093d542
|
Provenance
The following attestation bundles were made for django_display_ids-0.5.4.tar.gz:
Publisher:
ci.yml on josephabrahams/django-display-ids
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_display_ids-0.5.4.tar.gz -
Subject digest:
18030a6949149d17657ca2f33013e75d68cab01b36608788d65f6159757cd9c5 - Sigstore transparency entry: 1045453998
- Sigstore integration time:
-
Permalink:
josephabrahams/django-display-ids@0a9e39ed61ad83c69e3bb49606d5a1dfc7df4e94 -
Branch / Tag:
refs/tags/0.5.4 - Owner: https://github.com/josephabrahams
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0a9e39ed61ad83c69e3bb49606d5a1dfc7df4e94 -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_display_ids-0.5.4-py3-none-any.whl.
File metadata
- Download URL: django_display_ids-0.5.4-py3-none-any.whl
- Upload date:
- Size: 30.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55d41e21753f46e943e098e89fac9b27c96e97bd0f77cb1eb8dd9292b2b0c9f3
|
|
| MD5 |
1ebf1ad492f2d962f36a3816a8a318ba
|
|
| BLAKE2b-256 |
7de09f0c23051bf51575c4fbfe171d8b74b31017004eeeec84588a618a3e7af1
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_display_ids-0.5.4-py3-none-any.whl -
Subject digest:
55d41e21753f46e943e098e89fac9b27c96e97bd0f77cb1eb8dd9292b2b0c9f3 - Sigstore transparency entry: 1045453999
- Sigstore integration time:
-
Permalink:
josephabrahams/django-display-ids@0a9e39ed61ad83c69e3bb49606d5a1dfc7df4e94 -
Branch / Tag:
refs/tags/0.5.4 - Owner: https://github.com/josephabrahams
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0a9e39ed61ad83c69e3bb49606d5a1dfc7df4e94 -
Trigger Event:
push
-
Statement type: