All Projects → ericls → django-hashids

ericls / django-hashids

Licence: MIT license
Non-intrusive hashids library for Django

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to django-hashids

Laravel Hashid
Obfuscate your data by generating reversible, non-sequential, URL-safe identifiers.
Stars: ✭ 354 (+1261.54%)
Mutual labels:  hashids
Acts as hashids
Use Youtube-Like ID in ActiveRecord seamlessly.
Stars: ✭ 76 (+192.31%)
Mutual labels:  hashids
Hashids.github.io
Hashids website
Stars: ✭ 163 (+526.92%)
Mutual labels:  hashids
Hashids
A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
Stars: ✭ 4,596 (+17576.92%)
Mutual labels:  hashids
Hashids.phpc
🐘 A php extension for Hashids: generate short unique ids from integers.
Stars: ✭ 43 (+65.38%)
Mutual labels:  hashids
Laravel Hashids
A Hashids bridge for Laravel
Stars: ✭ 1,714 (+6492.31%)
Mutual labels:  hashids
Django Hashid Field
Django Model Field that uses Hashids to obscure the value
Stars: ✭ 256 (+884.62%)
Mutual labels:  hashids
Hashid Rails
Use Hashids (http://hashids.org/ruby/) in your Rails app ActiveRecord models.
Stars: ✭ 225 (+765.38%)
Mutual labels:  hashids
Optimus
🤖 Id obfuscation based on Knuth's multiplicative hashing method for PHP.
Stars: ✭ 1,084 (+4069.23%)
Mutual labels:  hashids
Pg hashids
Short unique id generator for PostgreSQL, using hashids
Stars: ✭ 164 (+530.77%)
Mutual labels:  hashids
Go Hashids
Go (golang) implementation of http://www.hashids.org
Stars: ✭ 830 (+3092.31%)
Mutual labels:  hashids
Laravel Hashids
Integrate Hashids with Laravel. Automatic model binding and id resolving included!
Stars: ✭ 8 (-69.23%)
Mutual labels:  hashids
Laravel Hashslug
Package providing a trait to use Hashids on a model
Stars: ✭ 136 (+423.08%)
Mutual labels:  hashids
Hashids.net
A small .NET package to generate YouTube-like hashes from one or many numbers. Use hashids when you do not want to expose your database ids to the user.
Stars: ✭ 470 (+1707.69%)
Mutual labels:  hashids
Django Rest Framework Serializer Extensions
Extensions to help DRY up Django Rest Framework serializers
Stars: ✭ 180 (+592.31%)
Mutual labels:  hashids
Hashids.js
A small JavaScript library to generate YouTube-like ids from numbers.
Stars: ✭ 3,525 (+13457.69%)
Mutual labels:  hashids
Laravel Optimus
Transform your internal id's to obfuscated integers based on Knuth's integer hash. Laravel wrapper for the Optimus Library by Jens Segers with multiple connections support.
Stars: ✭ 119 (+357.69%)
Mutual labels:  hashids
laravel-hashids
Laravel package for Hashids
Stars: ✭ 52 (+100%)
Mutual labels:  hashids
Eloquent Hashids
On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚡ Fast)
Stars: ✭ 196 (+653.85%)
Mutual labels:  hashids
Laravel Fakeid
Automatic model ID obfuscation in routes for Laravel
Stars: ✭ 161 (+519.23%)
Mutual labels:  hashids

Django Hashids

Github Actions Code Coverage Python Version PyPI Package License

django-hashids is a simple and non-intrusive hashids library for Django. It acts as a model field, but it does not touch the database or change the model.

Features

  • Proxy the internal model pk field without storing the value in the database.
  • Allows lookups and filtering by hashid string.
  • Can be used as sort key
  • Allows specifying a salt, min_length and alphabet globally
  • Supports custom salt, min_length, and alphabet per field
  • Supports Django REST Framework Serializers
  • Supports exact ID searches in Django Admin when field is specified in search_fields.
  • Supports common filtering lookups, such as __iexact, __contains, __icontains, though matching is the same as __exact.
  • Supports other lookups: isnull, gt, gte, lt and lte.

Install

pip install django-hashids

django-hashids is tested with Django 1.11, 2.2, 3.0, 3.1, 3.2, 4.0 and python 3.6, 3.7, 3.8, 3.9, 3.10.

Usage

Add HashidsField to any model

from django_hashids import HashidsField

class TestModel(Model):
    hashid = HashidsField(real_field_name="id")

TestModel.hashid field will proxy TestModel.id field but all queries will return and receive hashids strings. TestModel.id will work as before.

Examples

instance = TestModel.objects.create()
instance2 = TestModel.objects.create()
instance.id  # 1
instance2.id  # 2

# Allows access to the field
instance.hashid  # '1Z'
instance2.hashid  # '4x'

# Allows querying by the field
TestModel.objects.get(hashid="1Z")
TestModel.objects.filter(hashid="1Z")
TestModel.objects.filter(hashid__in=["1Z", "4x"])
TestModel.objects.filter(hashid__gt="1Z")  # same as id__gt=1, would return instance 2

# Allows usage in queryset.values
TestModel.objects.values_list("hashid", flat=True) # ["1Z", "4x"]
TestModel.objects.filter(hashid__in=TestModel.objects.values("hashid"))

Config

The folloing attributes can be added in settings file to set default arguments of HashidsField:

  1. DJANGO_HASHIDS_SALT: default salt
  2. DJANGO_HASHIDS_MIN_LENGTH: default minimum length
  3. DJANGO_HASHIDS_ALPHABET: default alphabet

HashidsField does not reqiure any arguments but the followinig arguments can be supplied to modify its behavior.

Name Description
real_field_name The proxied field name
hashids_instance The hashids instance used to encode/decode for this field
salt The salt used for this field to generate hashids
min_length The minimum length of hashids generated for this field
alphabet The alphabet used by this field to generate hashids

The argument hashids_instance is mutually exclusive to salt, min_length and alphabet. See hashids-python for more info about the arguments.

Some common Model arguments such as verbose_name are also supported.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].