Skip to main content

A modern, Django model field for generating short, unique, URL-safe UUIDs using the shortuuid lib.

Project description

django-shortuuid

PyPI PyPI - Implementation GitHub License Build

A drop-in Django model field for generating short, URL-safe, and unique IDs using shortuuid.
Customizable, migration-friendly, with optional collision detection and Django admin integration.

Features

  • Short, URL-safe unique IDs for Django models (default 22 characters, configurable)
  • Customizable alphabet, prefix, and length
  • Optional database collision detection and retry logic
  • Django admin: field is read-only but visible
  • Compatible with Django migrations
  • Python type hints

Installation

pip install django-shortuuid

Usage

from django.db import models
from django_shortuuid.fields import ShortUUIDField

class MyModel(models.Model):
    id = ShortUUIDField(primary_key=True, prefix="id-")
    # ... other fields ...

By default, auto=True generates a unique short UUID when each instance is saved, and makes the field read-only in forms/admin.

Example

See django_example/ for a full Django setup and admin usage.

Configuration

  • auto: Generate and set value automatically (True by default)
  • length: Length of the generated unique string (default 22)
  • prefix: Optional string prefix for the field value
  • alphabet: Custom alphabet for uuid generation (default: shortuuid’s default)
  • collision_check: Enables collision checking in the database (True by default)
  • max_retries: Max attempts to generate unique value before error (10 by default)

License

MIT Copyright (c) stabldev

Credits

This project was inspired by benrobster/django-shortuuidfield
and builds on ideas from the original implementation.

Special thanks to shortuuid for the short, URL-safe UUID generation.

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_shortuuid-0.1.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

django_shortuuid-0.1.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_shortuuid-0.1.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for django_shortuuid-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8038af51e614dfd8f870343787a274fe4570897bb64261efba6f751e173c629c
MD5 12d01c2de1cf689af57bf155af556f04
BLAKE2b-256 742224c4e9f64a1255cdd132c51e604894ee99295cda3231a0b269dc81b08142

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_shortuuid-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 623e7607133d3fbf1031af0944f2cdf3a62af723fb0f5250c508876205be0aaf
MD5 e5ef396ef17c9c5d1a267409cc34097d
BLAKE2b-256 c06159af2881cab219437b3913fbf77f11d299cbdf1a05faeb7b71cf86a86236

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