{"id":2838,"library":"ulid-py","title":"ULID Python Implementation (ahawker/ulid)","description":"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.","status":"maintenance","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/ahawker/ulid","tags":["ULID","identifier","UUID","sortable ID"],"install":[{"cmd":"pip install ulid-py","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The `ahawker/ulid` library primarily uses `ulid.new()` for generating new ULIDs, unlike other ULID implementations that might use `ULID()` directly.","wrong":"from ulid import ULID; ULID()","symbol":"new","correct":"import ulid\nulid.new()"},{"note":"Used to create a ULID from a datetime or timestamp value.","symbol":"from_timestamp","correct":"import ulid\nulid.from_timestamp(some_datetime_obj)"},{"note":"Used to create a ULID from a UUID object.","symbol":"from_uuid","correct":"import ulid\nulid.from_uuid(some_uuid_obj)"}],"quickstart":{"code":"import ulid\nimport datetime\n\n# Create a brand new ULID\nu = ulid.new()\nprint(f\"New ULID: {u}\")\nprint(f\"String representation: {str(u)}\")\n\n# Create a new ULID from an existing datetime object\ndt = datetime.datetime(1999, 1, 1, tzinfo=datetime.timezone.utc)\nu_from_dt = ulid.from_timestamp(dt)\nprint(f\"ULID from datetime: {u_from_dt}\")\n\n# Access timestamp and randomness parts\nprint(f\"Timestamp part: {u.timestamp()}\")\nprint(f\"Randomness part: {u.randomness()}\")\n\n# Convert to UUID\nimport uuid\nuuid_val = u.to_uuid()\nprint(f\"As UUID: {uuid_val}\")","lang":"python","description":"Demonstrates generating new ULIDs, creating them from existing timestamps, and accessing their components and other representations."},"warnings":[{"fix":"Ensure your project runs on Python 3.5+.","message":"Python 2 support was dropped in version 1.0.0. This library (v1.1.0) requires Python 3.5 or newer.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"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.","message":"Potential confusion with other Python ULID libraries. While this entry is for `ulid-py` (ahawker's implementation), there are other popular and more actively maintained libraries like `python-ulid` (mdomke's implementation) with different APIs (e.g., `ULID()` constructor vs. `ulid.new()`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use `ulid_instance.timestamp()` and `ulid_instance.randomness()` to access these components in `ulid-py`.","message":"API differences for accessing ULID components. In `ulid-py` (ahawker), `timestamp()` and `randomness()` are methods. In some other ULID libraries, these might be properties (e.g., `ulid.timestamp`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Security considerations when using ULIDs. Although `ulid-py` does not explicitly implement monotonic incrementing of the random component for same-millisecond generation by default (based on available documentation for this specific library), the timestamp component of ULIDs can still expose creation times. For applications requiring strong unpredictability (e.g., password reset tokens), a cryptographically secure random identifier might be more appropriate.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}