fractional-indexing
raw JSON → 0.1.3 verified Mon Apr 27 auth: no python
A Python implementation of fractional indexing for generating ordering strings (keys) between others, commonly used for sortable IDs in collaborative applications. Current version 0.1.3, stable maintenance mode.
pip install fractional-indexing Common errors
error ImportError: cannot import name 'generate_key_between' from 'fractional_indexing' ↓
cause The function was renamed in older versions. In 0.1.2+, it's available as 'generate_key'.
fix
Use 'from fractional_indexing import generate_key' (and call it with between= and after= parameters).
error TypeError: generate_key() missing 3 required positional arguments: 'start', 'end', and 'before_or_after' ↓
cause Using an incorrect function signature; the function expects keyword arguments, not positional.
fix
Use keyword arguments: generate_key(between='a0', after='a2') or generate_key() for the first key.
error ValueError: after must be greater than before ↓
cause The 'after' key must be lexicographically greater than the 'between' key (or the before/between key).
fix
Ensure the 'after' argument is lexicographically larger than the 'between' argument.
Warnings
gotcha The library is not widely tested for concurrent generation; concurrent calls may produce duplicate keys if shared state is not managed. ↓
fix Ensure single-threaded or use a locking mechanism if generating keys in a multithreaded context.
gotcha Keys are not guaranteed to be unique across multiple independent generators with the same initial state. Always start with no arguments to get a unique initial key per session. ↓
fix Do not reuse keys across different datasets without proper context separation; generate a fresh initial key for each independent ordering.
gotcha The library does not support specifiying a custom base-digit set. It uses a fixed 62-digit set internally. ↓
fix If you need custom encoding, consider forking the library or using another approach.
Imports
- generate_key
from fractional_indexing import generate_key - generate_key_between
from fractional_indexing import generate_key_between - BASE_62_DIGITS
from fractional_indexing import BASE_62_DIGITS
Quickstart
from fractional_indexing import generate_key
# Generate first key
key1 = generate_key()
print(key1) # e.g., 'a0'
# Generate key after key1
key2 = generate_key(after=key1)
print(key2) # e.g., 'a1'
# Generate key between key1 and key2
key_between = generate_key(between=key1, after=key2)
print(key_between) # e.g., 'a0V'