skillfed

django-hashids

Non-intrusive hashids library for Django

django-hashids v0.7.1 75.4K downloads/30d#14,712 on PyPI46
Permissive license MIT AGING released

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-hashids

uv

uv add django-hashids

poetry

poetry add django-hashids

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

django hashid fieldobfuscate primary keys djangohashids model fieldnon-sequential id urlsdjango slug alternativeencode decode pk django
django-ormurl-obfuscationid-encoding

More Dynamic Content packages