Skip to main content

Prefixed unique ID field for Django models

Project description

django-puid

A Django field that generates human-friendly prefixed unique IDs — a readable alternative to UUIDs.

usr_lrjk8xq2a3b9f
order_lrjk8xr7z91mk

IDs are time-sortable (timestamp in base36) with a cryptographically random suffix, so they're both friendly and collision-resistant.

Installation

pip install django-puid

Usage

from django_puid.fields import PrefixedUIDField

class Order(models.Model):
    uid = PrefixedUIDField(prefix="order")

This adds a uid field that auto-generates on save and does not replace Django's default integer primary key.

Options

Parameter Default Description
prefix required String prepended to the ID
separator "_" Character between prefix and ID body
random_length 6 Number of random characters in the suffix
# Custom separator and length
uid = PrefixedUIDField(prefix="usr", separator="-", random_length=8)
# → usr-lrjk8xq2a3b9f1z

Django admin

The field is non-editable by default. To display it in the admin as read-only:

from django.contrib import admin

@admin.register(Order)
class OrderAdmin(admin.ModelAdmin):
    readonly_fields = ["uid"]

ID format

{prefix}{separator}{timestamp_base36}{random_suffix}
      usr _ lrjk8xq 2a3b9f
  • Timestamp — milliseconds since epoch encoded in base36 (~8 chars, grows slowly)
  • Random suffix — cryptographically random base36 characters (secrets module)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_puid-0.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_puid-0.1.1-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file django_puid-0.1.1.tar.gz.

File metadata

  • Download URL: django_puid-0.1.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_puid-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ac1db18a8ae8d35abab3f8b4f2953eb5357c9b59108b70ee668d2c76a2a7a84f
MD5 18d7047b5be39983b554629d9622a68b
BLAKE2b-256 ebe45cf0bacfe6050c2f74c92df8905a32e5796c18b9c5553578f54af82f2474

See more details on using hashes here.

File details

Details for the file django_puid-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_puid-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for django_puid-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f5b8c3a66e72abe71b57f0778f2ed810e4829a83f1e9daca63415bc2458eb670
MD5 172a702472e7934f3c6774a1d36aafdd
BLAKE2b-256 9aa67714c634a81cc4689c16ba94ebc53f47d73c529fe7b7472d97a0e1d20287

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page