October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk2 min

How to Check if a String Is a GUID in Python

Check a GUID or UUID string in Python with the built-in uuid module, and use a normalized round-trip check when the exact hyphenated form matters.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Python’s built-in uuid module: pass the value to uuid.UUID() and catch ValueError if it cannot be parsed. If you need to require the usual hyphenated spelling rather than accept other valid UUID representations, compare the parsed value with its normalized string form.

Parse a GUID string with Python’s built-in module

Python’s uuid module can parse UUIDs, also known as GUIDs. A third-party package is not needed for this basic check. For string input, an unparseable value raises ValueError.

import uuid

def is_uuid(value: str) -> bool:
    try:
        uuid.UUID(value)
    except (ValueError, TypeError, AttributeError):
        return False
    return True

The extra TypeError and AttributeError catches make this helper return False for unexpected inputs such as None. If the function contract guarantees that value is a string, catching ValueError alone is sufficient.

Decide whether alternate spellings are acceptable

uuid.UUID(value) is a parser, not a check that the original text uses one exact spelling. Python documents that braces, hyphens, and the urn:uuid: prefix may be omitted. If any representation Python accepts is fine, successful parsing is enough.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To require the conventional hyphenated text form while allowing uppercase or lowercase letters, compare the original value with the parsed UUID’s normalized string:

import uuid

def is_canonical_uuid(value: str) -> bool:
    try:
        parsed = uuid.UUID(value)
    except (ValueError, TypeError, AttributeError):
        return False
    return str(parsed) == value.lower()

This accepts uppercase letters in the hyphenated form, but rejects other parseable spellings such as braces, omitted hyphens, or a URN prefix. The check treats the conventional hyphenated spelling as the requirement; it does not require lowercase input.

Add version or variant checks only when required

Parsing establishes that Python can construct a UUID from the representation. It does not enforce an application-specific UUID version or variant. If your requirements specify one, parse the value first, then inspect parsed.version or parsed.variant as a separate policy check. Python documents these attributes, and RFC 9562 describes version and variant as parts of UUID structure.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What GUID and UUID mean

RFC 9562 uses UUID (Universally Unique IDentifier) and GUID (Globally Unique IDentifier) for the same identifier family. A UUID is 128 bits; its ordinary text representation groups hexadecimal digits with hyphens, and the letters may be uppercase, lowercase, or mixed case.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For exact parsing behavior and UUID object attributes, see the Python 3.14.8 uuid documentation. For the UUID definition and format, see RFC 9562.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.