Skip to main content

Provides ShortUUID which extends Python's builtin UUID class

Project description


Installation using pip:

pip install smalluuid

Basic Usage

A drop-in replacement for Python’s UUID class which – by default – represents UUIDs as 22 character base64-encoded values.

>>> from smalluuid import SmallUUID
>>> uuid = SmallUUID()

# Displays as short UUID by default
>>> uuid
>>> print(uuid)

# Hex output still available
>>> SmallUUID().hex
>>> uuid.hex_grouped

# Will initialise from short UUID
>>> SmallUUID('IBNApQOzTHGzdjkSt6t-Jg')

# Will load as a hex value
>>> SmallUUID(hex='201340a5-03b3-4c71-b376-3912b7ab7e26')

Notable differences from Python’s UUID implementation:

  • Short-form UUIDs accepted as first parameter to __init__
  • Instantiating without a value will assign a random value of the given version (default: 4) rather than raise an exception.
  • Addition of hex_grouped property to provide access to grouped hex style UUIDs, formally provided by __str__.

Typed UUID Usage

An extension of SmallUUID is available in the form of TypedSmallUUID:

>>> from smalluuid import TypedSmallUUID

# Takes a type during instantiation
>>> uuid = TypedSmallUUID(type=42)
>>> uuid

# Type is stored within the UUID
>>> uuid.type

# Type determined from provided UUID value
>>> TypedSmallUUID('qHHvXuUwT6y7t7dnsiksvg').type

The use case here is that of having UUIDs from which one can determine both an object’s ID and the object’s type/table/model.


Any credits here

This project borrowed a little code and inspiration from shortuuid.

smalluuid is packaged using seed.

Project details

Download files

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

Files for smalluuid, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size smalluuid-0.1.3.tar.gz (204.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page