django-sqids
Non-intrusive sqids library for Django
What it is and what it does
django-sqids is a Django model field that transparently encodes your model's primary key as a sqid—a short, URL-safe, obfuscated string—without storing anything extra in the database or altering your model schema. It acts as a proxy over the real `id` field, so queries and filtering work seamlessly: you can filter by sqid string, use it in URLs as a slug, and even search by sqid in Django Admin. The underlying integer ID remains unchanged; the sqid is computed on the fly.
The package is built on the sqids library and supports customization per field (min_length, alphabet, prefix) or globally via Django settings. It integrates with Django REST Framework serializers and supports standard ORM lookups like `in`, `gt`, `gte`, `lt`, `lte`, and `isnull`. The project was forked from django-hashids to adopt the newer Sqids library, which removed the "salt" parameter; django-sqids provides a `shuffle_alphabet` helper to achieve similar per-field uniqueness.
Use it for:
- Expose model IDs in URLs and APIs as short, non-sequential sqid strings instead of raw integers.
- Hide internal database IDs from external users while keeping queries simple and database-native.
- Search and filter records by sqid in Django Admin without writing custom code.
- Generate unique, obfuscated identifiers for each model or field using per-instance alphabet shuffling.
- Build REST APIs that accept sqid strings in place of numeric IDs without custom serializer logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds a Django model field that encodes primary keys as short, obfuscated sqid strings without modifying the database or model structure.
Yes, if you need to expose model IDs as obfuscated strings in URLs or APIs without database changes. The package is low-friction, well-tested across modern Django and Python versions, and has no known vulnerabilities. The aging status (401 days since last release) is not a blocker—the last commit is recent and the codebase is stable—but verify that the documented Django and Python versions match your project before committing.
Install
django-sqids on PyPI
pip
pip install django-sqidsuv
uv add django-sqidspoetry
poetry add django-sqidsInstalling django-sqids
Before you install
Low friction—single runtime dependency (sqids) and a pure-Python wheel. Actively maintained with a recent commit (2025-07-09) and tested against Django 3.2, 4.2, 5.0 and Python 3.8–3.12, though the project is aging (401 days since last release).
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely in commercial and private projects without restriction.
Quickstart
pip install django-sqids
from django_sqids import SqidsField
from django.db import models
class Item(models.Model):
sqid = SqidsField(real_field_name="id")
item = Item.objects.create()
item.sqid # e.g., '1Z'
Item.objects.get(sqid="1Z")
Requires Django 3.2 or later and Python 3.8.1 or later.
Verify before relying
- Performance impact of sqid encoding/decoding on large querysets or high-throughput applications.
- Compatibility with Django ORM features beyond the documented lookups (in, isnull, gt, gte, lt, lte).
- Behavior when used with Django's prefetch_related or select_related optimizations.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.8.1) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — sqids |
| Maintenance | aging — 401 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 88,554/month — #13,717 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_sqids-0.2.2-py3-none-any.whl
Keywords: django, sqids, sqid, hashids, hashid
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
django-hashidsProvides a Django model field that proxies…
permissive · top 15,000 on PyPI
sqidsSqids encodes numbers into short, unique,…
permissive · top 15,000 on PyPI
hashidsGenerates short, unique, non-sequential hashes…
permissive · top 5,000 on PyPI
shortuuidGenerates concise, URL-safe unique identifiers…
permissive · top 1,000 on PyPI
django-bitfieldProvides a BitField model field for Django that…
unclear · top 15,000 on PyPI
django-picklefieldProvides a Django model field that stores and…
permissive · top 5,000 on PyPI
django-netfieldsProvides Django model fields for PostgreSQL…
permissive · top 15,000 on PyPI
djangoqlDjangoQL provides an advanced search query…
permissive · top 15,000 on PyPI
django-deprecate-fieldsProvides a decorator to mark Django model…
permissive · top 5,000 on PyPI