Skip to main content

python-ulid-django

ULID (Universally Unique Lexicographically Sortable Identifier) support for Django.

This package uses the ULID type implemented by python-ulid.

This package is heavily inspired by django-ulid. The reason I'm reinventing the wheel is that I want to use python-ulid's ULID implementation.

Requirements

Python 3.12+ and Django 5.2+.

Usage

Installation

pip install python-ulid-django

Model Field

You can then add ULIDField to your Django model just like other fields.

Example:

from django.contrib.auth.models import AbstractUser
from ulid import ULID
from ulid_django.models import ULIDField


class User(AbstractUser):
    id = ULIDField(primary_key=True, default=ULID, editable=False)

Form Field

ULIDField supplies a matching form field automatically, so a ModelForm needs no extra wiring. Use it directly when building a plain form:

from django import forms
from ulid_django.forms import ULIDField


class LookupForm(forms.Form):
    item_id = ULIDField()

It cleans to a ULID and accepts three input widths: the 26-character canonical representation, a 32-character hex string, and a 36-character UUID string.

URL Converter

A URL converter is also provided.

from django.urls import path, register_converter
from ulid import ULID
from ulid_django.converters import ULIDConverter


def user_detail_view(request, user_id):
    assert isinstance(user_id, ULID)
    ...


register_converter(ULIDConverter, "ulid")

urlpatterns = [
    path("user/<ulid:user_id>/", user_detail_view),
    ...,
]

Development

Prerequisite: uv and just

Environment setup: just dev-setup

Run linters: just lint

Test: just test

Test against every supported Python version: just test-all

Download files

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

Source Distribution

python_ulid_django-1.6.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

python_ulid_django-1.6.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file python_ulid_django-1.6.0.tar.gz.

File metadata

  • Download URL: python_ulid_django-1.6.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for python_ulid_django-1.6.0.tar.gz
Algorithm Hash digest
SHA256 a07efbda370703ed12500593acc3cb76df067f824297866f6dc808c755a718ac
MD5 d3221c708d9ed0ef3e88ec7c9b18a301
BLAKE2b-256 47297ad88c102e26063b8651bff6fa87eb422be95177bf7502134c1515cc7cae

See more details on using hashes here.

File details

Details for the file python_ulid_django-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: python_ulid_django-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.2 {"installer":{"name":"uv","version":"0.12.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for python_ulid_django-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0070887ca482992e2045280910e161ae7cfc604334ba634d9abc20014b0a9677
MD5 a304b7f959697723033ada871f8c19d7
BLAKE2b-256 3cc4b5a83655d6ab478f1d36d5583c83910f6dbe86963385765592e2f1d416dd

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.6.0 This release

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

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