--- id: django-hashids version: "0.7.1" license: MIT license_treatment: permissive maintenance: aging --- # django-hashids — Non-intrusive hashids library for Django License: permissive · Maintenance: aging · Downloads: 75.4K/mo ## 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 above — 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 pip install django-hashids uv add django-hashids 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_current - Install friction: low - Maintenance: aging - Downloads: 75.4K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django hashid field, obfuscate primary keys django, hashids model field, non-sequential id urls, django slug alternative, encode decode pk django, django-orm, url-obfuscation, id-encoding [View on SkillFed](https://skillfed.io/packages/django-hashids) · [View on PyPI](https://pypi.org/project/django-hashids/)