websauna.utils.slug module

Utilities to encode and decode UUID objects as URL parameters.

We provide UUID to Base64 encoded string and back coding.

More information what term slug means.

exception websauna.utils.slug.SlugDecodeError[source]

Bases: Exception

Raised when you pass invalid b64 slug data.

websauna.utils.slug.slug_to_uuid(slug)[source]

Convert UUID URL slug string to UUID object.

This method raises ValueError if slug cannot be converted to UUID:

try:
    # Is like 'I0p4RyoIQe-EQ1GU_QicoQ'
    delivery_uuid = slug_to_uuid(art_data["cartID"])
except SlugDecodeError as e:
    return HTTPNotFound("UUID was not a well-formed base64 encoded slug") from e
Parameters:slug (str) – Base64 string presentation of UUID
Raise:SlugDecodeError if the is an issue to decode slug
Return type:UUID
websauna.utils.slug.uuid_to_slug(uuid_)[source]

Convert UUID object to a compact base64 string presentation.

Note

Slugs are supposed to be human readable. We are stretching that definition here a bit.

Parameters:uuid (UUID) – UUID object
Return type:str
Returns:String like ‘’I0p4RyoIQe-EQ1GU_QicoQ’