atomic-counter
is a rust library for generating a monotonically increasing sequence of integers. Depending on the particular configuration of the counter, the generated sequence will be produce unique numbers down to the nanosecond, regardless of memory state.
E.g. if you quit the process and recreate a new counter >1ns
later, your sequence is guaranteed to still be monotonically increasing (but with a gap).
from atomic_counter import Counter
c = Counter(base_in_nanos)
c.next() # generate next number in sequence
To create e.g. a daily counter, pass in base=today in nanos
. As this is a common occurrence for sequences that reset daily, a convenience function def daily() -> Counter:
is provided.