ISCC - Flake-Code#
A unique, time-sorted identifier composed of an 48-bit timestamp and 16 to 208 bit randomness.
The ISCC Flake-Code is a unique identifier for distributed ID generation. The 64-bit version can be used as efficient surrogate key in database systems. It has guaranteed uniqueness if generated from a singele process and is time sortable in integer and base32hex representation. The 128-bit version is a K-sortable, globally unique identifier for use in distributed systems and is compatible with UUID.
Example
>>> import iscc_core as ic
>>> ic.gen_flake_code(bits=64)
{'iscc': 'ISCC:OAAQC7YN7PG2XOR4'}
>>> ic.gen_flake_code(bits=128)
{'iscc': 'ISCC:OABQC7YN7RJGUUTLKDSKBXO25MA5E'}
# Or use the convenience Flake class for easy access to different representations
>>> flake = ic.Flake(bits=64)
>>> flake.iscc
'ISCC:OAAQC7YOADBZYNF7'
>>> flake.time
'2022-02-18T18:03:25.468'
>>> flake.int
107820312524764351
>>> flake.string
'05VGS063JGQBU'
gen_flake_code(bits = ic.core_opts.flake_bits)
#
Create an ISCC Flake-Code with the latest standard algorithm
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bits |
int
|
Target bit-length of generated Flake-Code |
ic.core_opts.flake_bits
|
Returns:
Type | Description |
---|---|
dict
|
ISCC object with Flake-Code |
gen_flake_code_v0(bits = ic.core_opts.flake_bits)
#
Create an ISCC Flake-Code with the latest algorithm v0
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bits |
int
|
Target bit-length of generated Flake-Code |
ic.core_opts.flake_bits
|
Returns:
Type | Description |
---|---|
dict
|
ISCC object with Flake-Code |
uid_flake_v0(ts = None, bits = ic.core_opts.flake_bits)
#
Generate time and randomness based Flake-Hash
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ts |
Optional[float]
|
Unix timestamp (defaults to current time) |
None
|
bits |
int
|
Bit-length resulting Flake-Code (multiple of 32) |
ic.core_opts.flake_bits
|
Returns:
Type | Description |
---|---|
bytes
|
Flake-Hash digest |