Skip to main content

shopcloud-django-hashid

Tests PyPI version Coverage Python 3.12+ Django 5.0+

A drop-in replacement for django-hashid-field with Django 5.x and 6.x support.

Features

  • Drop-in compatible: Same import paths and API as django-hashid-field
  • Django 5.x/6.x support: Designed for modern Django versions
  • Zero migration effort: Existing migrations work without changes
  • Identical hashid output: Same salt produces same hashids
  • Full ORM support: Works with all Django ORM operations
  • Django REST Framework integration: Automatic serialization support
  • Thread-safe: Safe for concurrent use in production

Installation

pip install shopcloud-django-hashid

Migration from django-hashid-field

pip uninstall django-hashid-field
pip install shopcloud-django-hashid

No code changes required. Your existing imports continue to work:

from hashid_field import HashidField, HashidAutoField
from hashid_field import BigHashidField, BigHashidAutoField
from hashid_field import Hashid

Verify no migrations are needed:

python manage.py makemigrations --dry-run
# Should output: "No changes detected"

Quick Start

Model Definition

from django.db import models
from hashid_field import HashidAutoField, HashidField

class Article(models.Model):
    id = HashidAutoField(primary_key=True)
    title = models.CharField(max_length=200)

class Comment(models.Model):
    id = HashidAutoField(primary_key=True)
    article = models.ForeignKey(Article, on_delete=models.CASCADE)
    reference_code = HashidField()  # Non-primary key hashid

Django Settings

# settings.py

# Required: Set your salt (keep secret!)
HASHID_FIELD_SALT = "your-secret-salt-here"

# Optional: Customize defaults
HASHID_FIELD_MIN_LENGTH = 7
HASHID_FIELD_ALLOW_INT_LOOKUP = False

Usage

# Create
article = Article.objects.create(title="Hello World")
print(article.id)        # Hashid('kRm4x7')
print(str(article.id))   # 'kRm4x7'
print(int(article.id))   # 1

# Query by hashid string
article = Article.objects.get(pk='kRm4x7')

Field Types

Field Base Use Case
HashidField IntegerField General hashid storage
BigHashidField BigIntegerField Large integer hashids
HashidAutoField AutoField Primary key with hashid
BigHashidAutoField BigAutoField Big auto primary key

Settings

Setting Default Description
HASHID_FIELD_SALT "" Global salt for encoding
HASHID_FIELD_MIN_LENGTH 7 Minimum hashid length
HASHID_FIELD_ALLOW_INT_LOOKUP False Allow integer-based queries
HASHID_FIELD_ENABLE_HASHID_OBJECT True Return Hashid objects vs strings

Django REST Framework

If DRF is installed, HashidFields serialize automatically:

from rest_framework import serializers
from .models import Article

class ArticleSerializer(serializers.ModelSerializer):
    class Meta:
        model = Article
        fields = ['id', 'title']
    # id will serialize as hashid string, e.g., "kRm4x7"

Performance

  • Fast encoding and decoding, suitable for production use
  • Thread-safe: Yes, suitable for production environments

Best Practices

  1. Set salt in production:

    # settings.py
    HASHID_FIELD_SALT = os.environ.get("HASHID_SALT", "your-secret-salt")
    
  2. Custom salts for sensitive fields:

    class Order(models.Model):
        id = HashidAutoField(primary_key=True, salt="order-specific-salt")
    
  3. Hashids are deterministic: Same salt + same ID = same hashid

Troubleshooting

Problem Cause Solution
"Invalid hashid" Error Inconsistent salt Set same salt in all environments
Performance issues N+1 Queries Use select_related and prefetch_related to eager-load related objects
Hashid changes Salt changed Never change salt in production

Settings Reference (Complete)

Setting Default Description
HASHID_FIELD_SALT "" Global salt for all fields
HASHID_FIELD_MIN_LENGTH 7 Minimum hashid length
HASHID_FIELD_ALPHABET hashids library default Allowed characters
HASHID_FIELD_LOOKUP_EXCEPTION False Raise exception on invalid lookups
HASHID_FIELD_ALLOW_INT_LOOKUP False Allow integer-based queries
HASHID_FIELD_ENABLE_HASHID_OBJECT True Return Hashid objects vs strings

Requirements

  • Python 3.12+
  • Django 5.0+
  • hashids >= 1.3.1

Publishing to PyPI (Maintainers)

This package uses PyPI Trusted Publishing for secure, token-free releases:

  1. Configure Trusted Publisher on PyPI:

    • Log in to pypi.org
    • Go to your account → Publishing → Add a new trusted publisher
    • Set repository owner, name, and workflow file (publish.yml)
  2. Create a Release:

    • Update version in pyproject.toml and hashid_field/__init__.py
    • Update CHANGELOG.md
    • Create a GitHub Release with a tag (e.g., v0.1.0)
    • The GitHub Action will automatically publish to PyPI

License

MIT License - see LICENSE for details.

Metadata

Release files for shopcloud-django-hashid 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shopcloud-django-hashid 0.10.0
File Size Uploaded Provenance Actions
shopcloud_django_hashid-0.10.0.tar.gz 38.4 kB With provenance Details for shopcloud_django_hashid-0.10.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for shopcloud-django-hashid 0.10.0
File Interpreter ABI Platform Actions
shopcloud_django_hashid-0.10.0-py3-none-any.whl Python 3 none any Details for shopcloud_django_hashid-0.10.0-py3-none-any.whl

Total release size: 62.1 kB

Release files / shopcloud_django_hashid-0.10.0.tar.gz

Download URL shopcloud_django_hashid-0.10.0.tar.gz
Size 38.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1ad2b85de7a0b22500c95d31b9c20f1ccab929d77e9b3f8b6e9d807fa1a4e9b9
BLAKE2b-256 checksum
How to use checksums
a938b0bbf5cafbaa9043277ee88bac3ad794eba3cfa894ace8c528072e675397
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Release files / shopcloud_django_hashid-0.10.0-py3-none-any.whl

Download URL shopcloud_django_hashid-0.10.0-py3-none-any.whl
Size 23.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7e26f712d4c8dd06fc7e8bccdf7290373ba7a52dfb5a244bb8d6978a8342a29
BLAKE2b-256 checksum
How to use checksums
dc0817fbedd03efdc23abffb1b7d8cca8ec571a55052fc2b7a557e2454b8f580
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

Security for shopcloud-django-hashid 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for shopcloud_django_hashid-0.10.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page