gpf.common.guids module

This module contains the Guid class, which inherits from Pythons built-in UUID class. It helps validating existing GUIDs (e.g. GlobalID’s) and can generate new ones. It also helps formatting the GUID for use in SQL queries.

class gpf.common.guids.Guid(value=None, allow_new: bool = False)[source]

Bases: uuid.UUID

Takes a UUID-like string or object as input and validates it. Can also be used to generate a new GUID. The Guid class inherits from the Python built-in UUID.

Params:

  • value (object):

    The value to parse as a GUID. Must be set if allow_new is True.

  • allow_new (bool):

    If set to True and value is None, a new GUID will be generated. The default is False, which means that an exception will be raised if value is not set.

Raises:
  • gpf.tools.Guid.MissingGuidError – This exception is raised when allow_new is False and value is None.
  • gpf.tools.Guid.BadGuidError – This exception is raised when value cannot be parsed to a GUID.

Examples:

>>> Guid(allow_new=True)
Guid('459b46ce-6370-48ae-b3cc-220026d49ec2')
>>> guid = Guid('{459b46ce-6370-48ae-b3cc-220026d49ec2}')
>>> str(guid)  # this returns the GUID for Esri SQL expressions
'{459B46CE-6370-48AE-B3CC-220026D49EC2}'
exception MissingGuidError[source]

Bases: TypeError

This exception is raised when Guid is initialized without a value, while allow_new is False, which is the default. Either set a value or set allow_new to True to prevent this error.

exception BadGuidError[source]

Bases: ValueError

This exception is raised when the GUID string cannot be successfully parsed to a valid UUID-like object.