Timeflake

0.4.3 · active · verified Fri Apr 17

Timeflake is a Python library for generating 128-bit, roughly-ordered, URL-safe UUIDs, inspired by Twitter's Snowflake, Instagram's ID, and Firebase's PushID. It combines a timestamp with a random component. The current version is 0.4.3, with releases typically occurring a few times a year to introduce new features or address issues.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to generate a new Timeflake, access its various representations (integer, hex, base62, UUID, datetime), and parse an existing Timeflake string back into an object.

import timeflake

# Generate a new timeflake
tf = timeflake.timeflake()

print(f"Generated Timeflake: {tf}")
print(f"As integer: {tf.int}")
print(f"As hex: {tf.hex}")
print(f"As base62: {tf.base62}")
print(f"As UUID: {tf.uuid}")
print(f"As datetime: {tf.datetime}")

# Encode and decode a timeflake
encoded_tf = tf.base62
decoded_tf = timeflake.parse(encoded_tf)
print(f"\nOriginal: {tf}, Decoded: {decoding_tf}")

view raw JSON →