API¶
License: MIT Author: Jakob Majkilde
-
class
universalid.
Unid
¶ Class here
-
static
create
(prefix=None, time=None)¶ - Creates a 32-character combination of digits (0-9, A-Z), where:
- First 20 digits: The specified prefix plus random digits
- Next 7 digits: Date/time
- Next 4 digits: microseconds
- last digit: sequence number
Parameters: - prefix (str) – Optional. Defaults to None. The resulting unid will start with the specified prefix
- time (datetime) – Optional. Defaults to datetime.utcnow()
Returns: new unique unid
Return type: str
Examples:
To create a new unid based on the current date/time
>> Unid.create() 'B90HSWB2RP1ISBQVGSBU0PK8L5T0HWY0'
Create a unid with a custom prefix, e.g. a country code
>> Unid.create('dk') 'DK396ODJJ0QUE4APFO2H0PK8L8R5RB31'
Create a unid based on a specific time
>> Unid.create(time=datetime.datetime(2018, 12, 20, 11, 34, 15, 229884)) 'ODPN11WEQJWXVDOE3A390PK16P34XDO2'
-
static
get_time
(unid)¶ Extract the creation date/time from a given unid
Parameters: unid (str) – the unid Returns: the date/time from the unid Return type: datetime >>> Unid.get_time("7ADQ2D6JCJXI2Q82J06X0PK16P34XDO1") datetime.datetime(2018, 12, 20, 11, 34, 15, 229884)
-
static