ngsildclient.utils.uuid#
This module contains a few helper functions to deal with UUIDs.
Functions
|
Returns a unique identifier, 22 characters long. |
|
Returns a "short" string representation of the UUID object. |
- ngsildclient.utils.uuid.shortuuid(random=False)[source]#
Returns a unique identifier, 22 characters long.
May be useful in some cases to create a unique Entity identifier. The string will be 22 characters long, base64-encoded, with padding characters removed. The encoding uses the urlsafe alphabet with a slightly difference. The dash character (sometimes used as a field separator) is replaced by the tilde character.
- Parameters
random (bool, optional) – if set uses UUID1 else UUID4, by default False
- Returns
A short unique identifier, 22 characters longs.
- Return type
str
Example
>>> from ngsildclient import * >>> crop = Entity("AgriCrop", shortuuid()) >>> crop.pprint() { "@context": [ "https://uri.etsi.org/ngsi-ld/v1/ngsi-ld-core-context.jsonld" ], "id": "urn:ngsi-ld:AgriCrop:SQiKZZRYRnOYgeojIVz5lA", "type": "AgriCrop" }
- ngsildclient.utils.uuid.uuidshortener(uuid)[source]#
Returns a “short” string representation of the UUID object.
The string will be 22 characters long, base64-encoded, with padding characters removed. The encoding uses the urlsafe alphabet with a slightly difference. The dash character (sometimes used as a field separator) is replaced by the tilde character.
- Parameters
uuid (uuid.UUID) – The input UUID object
- Returns
Its string representation, 22 characters
- Return type
str
Example
>>> from uuid import uuid4 >>> from ngsildclient.utils.uuid import uuidshortener >>> uuid = uuid4() >>> print(uuid) 632dd95d-55bf-4f4e-9dd1-05f02531756f >>> shortid: str = uuidshortener(uuid) >>> print(shortid) Yy3ZXVW_T06d0QXwJTF1bw