django-hashids
Non-intrusive hashids library for Django
What it is and what it does
django-hashids is a Django model field that encodes and decodes primary keys as hashids—short, obfuscated strings like '1Z' or '4x'—without modifying the database schema or the underlying id field. It acts as a transparent proxy: your model's id continues to work normally, but the hashid field lets you expose non-sequential, non-guessable identifiers in URLs, APIs, and user-facing contexts. Queries and filtering work on the hashid string, and the library handles the encode/decode automatically.
The field supports Django ORM lookups (exact, iexact, contains, icontains, gt, gte, lt, lte, isnull, and __in), works with Django REST Framework serializers, integrates with Django Admin search, and can be configured globally via settings (DJANGO_HASHIDS_SALT, DJANGO_HASHIDS_MIN_LENGTH, DJANGO_HASHIDS_ALPHABET) or per-field with custom salt, length, and alphabet. It depends only on the hashids library and is designed to be non-intrusive—you add the field to your model and use it; no migrations or database changes required.
Use it for:
- Expose non-sequential, non-guessable IDs in public URLs (e.g., /item/1Z/ instead of /item/1/) to avoid leaking data patterns.
- Use hashids as slug-like identifiers in REST APIs to obscure the actual database primary key from clients.
- Filter and query Django ORM by hashid string in views and querysets without manual encode/decode logic.
- Integrate hashid fields into Django Admin search_fields for exact ID lookups by the encoded string.
- Configure global or per-field hashid encoding rules (salt, minimum length, custom alphabet) for different security or readability needs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a Django model field that proxies primary keys as hashids—short, unique, non-sequential strings—without storing them in the database or altering the model structure.
Yes, if you need to expose non-sequential IDs in URLs or APIs without database changes. The low install friction, permissive license, and transparent ORM integration make it straightforward to adopt. Caveat: maintenance is aging (last release 275 days ago) and testing is documented only through Django 4.0; verify compatibility with your Django version before committing to production.
Install
django-hashids on PyPI
pip
pip install django-hashidsuv
uv add django-hashidspoetry
poetry add django-hashidsInstalling django-hashids
Before you install
Low friction: single runtime dependency (hashids), pure Python wheel, tested across Django 1.11 through 4.0 and Python 3.6–3.10. Maintenance is aging—last release 275 days ago, repository active but not frequently updated.
License in practice
MIT license (permissive): you may use, modify, and distribute freely in commercial and private projects with minimal restrictions; include a copy of the license.
Quickstart
pip install django-hashids
from django_hashids import HashidsField
from django.db import models
class Item(models.Model):
hashid = HashidsField(real_field_name="id")
item = Item.objects.create()
print(item.hashid) # e.g., '1Z'
Item.objects.get(hashid="1Z")
Verify before relying
- Whether the package works with Django versions newer than 4.0 (tested through 4.0 only; latest release is recent but changelog not provided).
- Performance characteristics when filtering or querying on hashid fields with large datasets.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.6.2) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — hashids |
| Maintenance | aging — 275 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 75,445/month — #14,712 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_hashids-0.7.1-py3-none-any.whl
Keywords: django, hashids, hashid
Tags
More Dynamic Content packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
soupsieveSoupsieve is a CSS selector library designed to…
permissive · top 100 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
FlaskFlask is a lightweight WSGI web application…
permissive · top 1,000 on PyPI
MakoMako compiles Python-embedded templates into…
permissive · top 1,000 on PyPI
django-sqidsAdds a Django model field that encodes primary…
permissive · top 15,000 on PyPI
hashidsGenerates short, unique, non-sequential hashes…
permissive · top 5,000 on PyPI
sqidsSqids encodes numbers into short, unique,…
permissive · top 15,000 on PyPI
shortuuidGenerates concise, URL-safe unique identifiers…
permissive · top 1,000 on PyPI
django-picklefieldProvides a Django model field that stores and…
permissive · top 5,000 on PyPI
django-crumDjango-CRUM stores the current request and user…
permissive · top 15,000 on PyPI
django-cryptographyWraps Python's cryptography library to add…
permissive · top 15,000 on PyPI
nanoidGenerates cryptographically secure,…
permissive · top 5,000 on PyPI
drf-writable-nestedExtends Django REST Framework serializers to…
permissive · top 15,000 on PyPI