unique_id

Python module for unique_id helper functions.

Various ROS components use universally unique identifiers (UUID). This module provides functions for working with a common uuid_msgs/UniqueID message, and the standard Python uuid.UUID class.

Programmers are free to create UUID objects using any approved RFC 4122 method. The standard Python uuid module supports them all.

Functions in this module provide simple APIs, not requiring detailed knowledge of RFC 4122 or the uuid interface. ROS applications are likely to need either a random or a name-based UUID.

unique_id.fromMsg(msg)[source]

Create UUID object from UniqueID message.

Parameters:msguuid_msgs/UniqueID message.
Returns:uuid.UUID object.
unique_id.fromRandom()[source]

Generate a random UUID object.

Returns:type 4 uuid.UUID object.

Different calls to this function at any time or place will almost certainly generate different UUIDs. The method used is RFC 4122 variant 4.

unique_id.fromTime(timestamp, hw_addr)[source]

Generate a Time Based UUID object.

Parameters:
  • timestamp – The rospy.Time timestamp for UUID generation
  • hw_addr – A 48-bit long representing the network address
Returns:

type 1 uuid.UUID object

Different calls to this function at any time or place will almost certainly generate different UUIDs. The method used is RFC 4122 version 1.

unique_id.fromURL(url)[source]

Generate UUID from Uniform Resource Locator.

Parameters:url – URL for identifier creation.
Returns:type 5 uuid.UUID object.

Matching url strings must yield the same UUID. Different url strings will almost certainly generate different UUIDs. The method used is RFC 4122 variant 5, computing the SHA-1 hash of the url.

For any given url, this function returns the same UUID as the corresponding C++ unique_id::fromURL() function.

For example, Open Street Map identifiers are encoded like this, with decimal representations of the integer OSM node, way, or relation identifiers appended to the URL:

fromURL('http://openstreetmap.org/node/' + str(node_id))
fromURL('http://openstreetmap.org/way/' + str(way_id))
fromURL('http://openstreetmap.org/relation/' + str(rel_id))
unique_id.toHexString(msg)[source]

Get the canonical hexadecimal string representation for a UniqueID message.

Parameters:msguuid_msgs/UniqueID message.
Returns:UUID hex string: ‘01234567-89ab-cdef-0123-456789abcdef’.

A uuid.UUID object yields the same representation via the str() function.

unique_id.toMsg(uuid_obj)[source]

Create a UniqueID message from a UUID object.

Parameters:uuid_obj – standard Python uuid.UUID object.
Returns:uuid_msgs/UniqueID message.