{"id":2840,"library":"uuid","title":"UUID (PyPI Backport for Python 2.x)","description":"This PyPI package (version 1.30) provides a backport of the `uuid` module's functionality for older Python versions, specifically 2.3 through 2.5. For Python 2.6 and newer, the `uuid` module is included in the Python standard library and this PyPI package is generally not needed. It was last released in 2006 and is not actively maintained.","status":"deprecated","version":"1.30","language":"en","source_language":"en","source_url":"https://pypi.org/project/uuid/","tags":["uuid","guid","identifier","backport","python2"],"install":[{"cmd":"pip install uuid","lang":"bash","label":"Install PyPI package (for Python 2.3-2.5)"}],"dependencies":[],"imports":[{"note":"Imports the module. Functions like uuid.uuid4() are then accessible.","symbol":"uuid","correct":"import uuid"},{"note":"The UUID class constructor expects a single string, bytes, a fields tuple, or an integer. Passing a list or other incorrect types will often lead to an AttributeError (e.g., trying to call .replace() on a list) rather than a direct TypeError.","wrong":"my_uuid_obj = uuid.UUID(['a1b2c3d4-e5f6-7890-1234-567890abcdef'])","symbol":"UUID","correct":"from uuid import UUID\nmy_uuid_obj = UUID('a1b2c3d4-e5f6-7890-1234-567890abcdef')"}],"quickstart":{"code":"import uuid\n\n# Generate a random UUID (version 4)\nnew_uuid = uuid.uuid4()\nprint(f\"Generated UUID (version 4): {new_uuid}\")\nprint(f\"UUID as hex string: {new_uuid.hex}\")\n\n# Generate a time-based UUID (version 1)\n# Note: uuid1() may expose the computer's MAC address.\ntime_uuid = uuid.uuid1()\nprint(f\"Generated UUID (version 1): {time_uuid}\")\n\n# Reconstruct a UUID from a string\nfrom uuid import UUID\nrecovered_uuid = UUID(str(new_uuid))\nprint(f\"Recovered UUID: {recovered_uuid}\")\nprint(f\"Are they equal? {new_uuid == recovered_uuid}\")","lang":"python","description":"Demonstrates generating version 1 and version 4 UUIDs, and reconstructing a UUID object from its string representation using the PyPI `uuid` package, which mirrors the standard library's API for older Python versions."},"warnings":[{"fix":"For Python 2.6+, simply `import uuid` without `pip install uuid`. If you must support older Python 2.x versions (2.3-2.5), then `pip install uuid` is appropriate.","message":"This PyPI package (version 1.30) is a backport specifically for Python versions 2.3-2.5. For Python 2.6 and newer, the `uuid` module is included in the Python standard library. Installing this PyPI package on Python 2.6+ or Python 3.x is unnecessary and can lead to confusion or potential conflicts, as the standard library version should be used instead.","severity":"breaking","affected_versions":"< 2.6 (PyPI package intended for), >= 2.6 (standard library available)"},{"fix":"If privacy is a concern, prefer `uuid.uuid4()` for generating random UUIDs or `uuid.uuid7()` (available in Python 3.14+) for time-ordered UUIDs without MAC address exposure.","message":"The `uuid.uuid1()` function generates a UUID using the computer's network address (MAC address) and the current time. This can compromise privacy if the generated UUIDs are exposed, as they could potentially be traced back to the originating machine.","severity":"gotcha","affected_versions":"All versions of the `uuid` module (both PyPI backport and standard library)"},{"fix":"Use your database's native UUID type if available (e.g., `UUID` in PostgreSQL). If not, store UUIDs as 16-byte binary fields (e.g., `VARBINARY(16)` or `BINARY(16)`) and convert using `my_uuid.bytes` in Python.","message":"Storing UUIDs as plain strings in databases is inefficient. It consumes more space and can degrade query performance compared to using native UUID data types (e.g., in PostgreSQL) or storing them as 16-byte binary data.","severity":"gotcha","affected_versions":"All Python versions, dependent on database usage."},{"fix":"If you require newer UUID versions (6, 7, or 8), you must use Python 3.14 or a newer version of the standard library. Otherwise, adhere to versions 1, 3, 4, or 5. Consider `uuid4()` for general randomness.","message":"This specific PyPI `uuid` package (v1.30) and older standard library versions only support UUID versions 1, 3, 4, and 5. Newer, potentially more optimized or privacy-friendly versions like UUIDv6, UUIDv7, and UUIDv8 were added to the standard library starting with Python 3.14.","severity":"gotcha","affected_versions":"PyPI `uuid` 1.30 and Python standard library < 3.14"},{"fix":"For mission-critical applications where absolute uniqueness is paramount, consider implementing additional collision detection logic or relying on database-side UUID generation functions where the database ensures uniqueness with constraints.","message":"While UUIDs are designed to be highly unique (e.g., collision probability for UUIDv4 is extremely low), they are not absolutely guaranteed to be unique. In extremely high-volume, distributed systems, theoretical collision possibilities exist.","severity":"gotcha","affected_versions":"All UUID versions and Python versions."},{"fix":"Avoid relying on `uuid1()` for persistent identifiers that must remain constant across hardware or network changes. Use `uuid4()` or name-based UUIDs (`uuid3()`, `uuid5()`) instead, or store and reuse a generated UUID.","message":"The hardware address retrieved by `uuid.getnode()` (used internally by `uuid.uuid1()`) is tied to the system's network interfaces and can change if network configurations are altered (e.g., switching Wi-Fi, using USB Ethernet adapters).","severity":"gotcha","affected_versions":"All versions of the `uuid` module that use `uuid1()` or `getnode()`"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}