The `ulid-py` library (version 1.1.0) provides a minimal, self-contained Python 3 implementation of the Universally Unique Lexicographically Sortable Identifier (ULID) specification. It aims for a lightweight implementation without external dependencies. The project is currently in maintenance mode, with its last release in March 2022.
pip install ulid-pyVerified import paths — ran on the pinned version, not inferred.
Demonstrates generating new ULIDs, creating them from existing timestamps, and accessing their components and other representations.
Ensure your project runs on Python 3.5+.
Always check the specific documentation for the `ulid` package you have installed and verify the GitHub repository or PyPI page to ensure you are using the intended library.
Use `ulid_instance.timestamp()` and `ulid_instance.randomness()` to access these components in `ulid-py`.
Do not use ULIDs where cryptographic randomness is a strict requirement for security. Consider adding an additional layer of cryptographic randomness or using a UUIDv4/other cryptographically secure identifier.
Import the `new` function explicitly from `ulid.api` or use the `ULID()` constructor from the main `ulid` package. ```python # Fix 1: Import new function directly from ulid.api import new ulid_obj = new() # Fix 2: Use the ULID constructor from ulid import ULID ulid_obj = ULID() ```
To parse a ULID string into a `ULID` object, use the `ULID.from_str()` class method instead of the constructor. ```python from ulid import ULID # Correct way to parse a ULID string ulid_string = "01ARZ3RCK538M5064X1J0YSBPK" ulid_obj = ULID.from_str(ulid_string) print(ulid_obj) ```
Ensure the input string is a valid 26-character ULID string in Crockford Base32 encoding. Validate the source of the ULID string. ```python from ulid import ULID # Correct: A valid ULID string valid_ulid_string = "01GS81E0F1T2Q3M4N5P6R7S8T9" parsed_ulid = ULID.from_str(valid_ulid_string) print(parsed_ulid) # Incorrect example (would raise the ValueError) # invalid_ulid_string = "not-a-ulid" # parsed_ulid = ULID.from_str(invalid_ulid_string) ```
Install the `ulid-py` package using pip. ```bash pip install ulid-py ``` After installation, you should be able to import the module: ```python import ulid from ulid import ULID ```
No dependency data recorded yet.