skillfed

django-sqids

Non-intrusive sqids library for Django

django-sqids v0.2.2 88.6K downloads/30d#13,717 on PyPI90
Permissive license MIT AGING released

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

uv

uv add django-sqids

poetry

poetry add django-sqids

Installing 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

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.9

Tags

django model field sqidsencode primary key sqidobfuscate database ids djangosqid proxy fielddjango url slug sqidshide internal ids django
django-fieldid-obfuscationurl-slug

More Application Frameworks packages