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.

acct_lrjk8xr7z91mk     # Stripe-style IDs
cus_lrjk8xq2a3b9f      # instantly self-describing
post_4kp2mzn8q1vx      # readable in logs, URLs, and support tickets

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

Quick Start

from django_puid.fields import PrefixedUIDField

class Customer(models.Model):
    uid = PrefixedUIDField(prefix="cus")

The uid field auto-generates on save. It sits alongside Django's default integer primary key — it doesn't replace it.

Why Not UUID?

UUID django-puid
Readable in logs
Self-describing in URLs
Easy to copy in support tickets
Time-sortable
Collision-resistant

UUIDs are collision-resistant but opaque. f47ac10b-58cc-4372-a567-0e02b2c3d479 tells you nothing at a glance. Prefixed IDs are just as safe — and immediately meaningful.

# UUID
customer_id = "f47ac10b-58cc-4372-a567-0e02b2c3d479"

# django-puid
customer_id = "cus_lrjk8xq2a3b9f"

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

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(Customer)
class CustomerAdmin(admin.ModelAdmin):
    readonly_fields = ["uid"]

License

MIT

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.2.tar.gz (4.6 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.2-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_puid-0.1.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","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.2.tar.gz
Algorithm Hash digest
SHA256 9e947c503c7e5ce5944ede720a241fa3819be0186b2e35c91e6c171b868ac0ad
MD5 866a2a4db09f0c51a35d017eb6c43ef2
BLAKE2b-256 410eda69a818b1878023d04e5d52244b1eb2fd67aca6643cdaecabe12171ff95

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_puid-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2ceab82fbc28878d707c8aa527e4c597e7f1ab769b9602ea79143c0d3d6697e5
MD5 fd04239aacdbe7e0747005080c58b4c5
BLAKE2b-256 9b4af4ecf35b19ffc9bf8e52ae61104b48b5f9cab6948409d02dd4693f2cd7e0

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