Registry / serialization / slugid

slugid

JSON →
library2.0.0pypypi✓ verified 23d ago

slugid is a Python library (version 2.0.0, released 2019) for generating URL-safe Base64 encoded UUID v4 slugs. These 22-character slugs are compact and can be easily embedded in URLs, command-line parameters, or used as identifiers in various systems. It provides methods for generating standard v4 slugs and 'nice' slugs which always start with an alphanumeric character. The library is currently in maintenance mode with its GitHub repository archived, meaning it's no longer actively developed but remains functional.

pip install slugid
INSTALL
IMPORT
SIG · SLUGID
S
slugid
serializationpythonv2.0.0
Install
1.7s avg
Import
14ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

v4
import slugid; slugid.v4()
Generates a standard URL-safe v4 UUID slug.
nice
import slugid; slugid.nice()
Generates a 'nice' v4 UUID slug that is guaranteed not to start with '-', suitable for command-line arguments.

Generate both standard and 'nice' URL-safe slugs. The example also briefly touches on the conceptual decoding back to a UUID, though the library primarily focuses on slug generation from UUIDs.

import slugid # Generate a standard v4 slug standard_slug = slugid.v4() print(f"Standard Slug: {standard_slug}") # Generate a 'nice' slug (guaranteed not to start with '-') nice_slug = slugid.nice() print(f"Nice Slug: {nice_slug}") # Decode a slug back to a UUID string (requires converting to a full UUID object first) # For full round-trip, you might need to use the `uuid` library directly or a helper function import uuid def decode_slugid(slug): # slugid's internal decode function isn't directly exposed for all use cases # This demonstrates the principle of converting to UUID # Note: slugid itself primarily focuses on *generating* slugs from UUIDs # To decode, you'd typically base64url decode the 22-char string and then reconstruct UUID # The underlying Python `uuid` library handles the canonical UUID representation. # A direct decode function for the slugid string to uuid.UUID object is not directly exposed for Python slugid library itself, # but the concept relies on standard base64url decoding. # For simplicity, if you have a UUID string, you can convert it to a slugid. # Let's show how to convert a UUID string to slugid, and then conceptually, it could be reversed if a direct method was exposed. return uuid.UUID(bytes=uuid.b64decode(slug + '==')) #Conceptual decoding, might need adjustments based on exact implementation # Example of encoding a UUID to a slug some_uuid = uuid.uuid4() encoded_slug = slugid.encode(some_uuid) print(f"UUID {some_uuid} encoded to slug: {encoded_slug}") # While slugid.py doesn't expose a direct `decode` for the slug string to uuid.UUID # the underlying principle is base64url decoding, which can be done with `uuid` module's helper functions.
slugid --version
Debug
Known issues
gotchaChoosing between `slugid.v4()` and `slugid.nice()`: `nice()` slugs are guaranteed not to start with a hyphen (`-`), making them safer for use in command-line arguments. However, this comes at a slight cost of entropy (121 bits for `nice()` vs. 122 bits for `v4()`). Consider your specific use case to decide which method is appropriate.
fix
Use `slugid.nice()` if the slug will be used in contexts sensitive to leading hyphens (e.g., command-line arguments). Use `slugid.v4()` for maximum entropy where leading hyphens are not an issue.
affects: All versions
gotchaThis `slugid` library (for encoding UUIDs) is distinct from `python-slugify` (for slugifying arbitrary text strings). Do not confuse their purposes; `slugid` focuses specifically on compact, URL-safe UUID representations.
fix
Ensure you are using the correct library for your task: `slugid` for UUID encoding, or `python-slugify` for general text slugification.
affects: All versions
deprecatedThe GitHub repository for the Python `slugid` library (`taskcluster/slugid.py`) has been archived. This indicates that the project is no longer under active development and is in maintenance mode. While it remains functional, new features or significant bug fixes are unlikely.
fix
Be aware that active development has ceased. Consider stability and lack of new features when integrating or relying heavily on this library. The core functionality remains solid, but no future updates are expected.
affects: 2.0.0 and potentially future versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'slugid'
The 'slugid' package is not installed in the current Python environment.
fix
pip install slugid
ImportError: cannot import name 'slugid' from 'slugid'
You are attempting to import an object named 'slugid' from the 'slugid' module, but the module itself is the 'slugid' object and does not expose a submodule or class with the same name.
fix
import slugid
AttributeError: module 'slugid' has no attribute 'generate'
You are attempting to call a non-existent method like 'generate' on the 'slugid' module; the library's primary slug generation functions are `v4()` and `nice()`.
fix
slugid.v4()
TypeError: 'module' object is not callable
You are attempting to call the 'slugid' module directly as if it were a function or a class constructor.
fix
slugid.v4()
Upgrade
Version history
2.0.0latest on PyPI · released Feb 15, 2019
Audit
Dependencies
uuidrequiredUsed internally by slugid for UUID generation; part of Python's standard library.
Agent activity
7 hits · last 30 days
node
6
Resources