Registry / serialization / lexid
library2021.1006pypypi✓ verified 85d ago

lexid is a micro library (version 2021.1006) designed to generate and increment lexically ordered numerical IDs. Its core functionality ensures that `older_id < newer_id` remains true throughout a sequence, whether dealing with integers or strings. This is achieved by special incrementing that uses the leftmost character/digit to maintain lexical order and prevent premature numerical overflow. It's useful for scenarios like build numbers or version strings that are often sorted by tools using simple lexical ordering, such as the UNIX sort command or JavaScript's string comparison. The library maintains an active status with updates as needed.

pip install lexid
INSTALL
IMPORT
SIG · LEXID
L
lexid
serializationpythonv2021.1006
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2021.1006 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lexid
import lexid
incr
lexid.incr('1')
The primary function is `incr` accessed via the imported module.

This quickstart demonstrates the basic usage of the `lexid.incr()` function. It shows how to increment a string-based ID and highlights the unique lexical ordering mechanism where the leftmost digit can be incremented 'early' to maintain ordering, which can increase the ID's length. It also includes the recommended practice of starting with a higher number to mitigate frequent rollovers.

import lexid # Incrementing a simple ID id1 = "1" next_id1 = lexid.incr(id1) print(f"Next ID after '{id1}': {next_id1}") # Expected: Next ID after '1': 22 # Demonstrating padding and 'early' increment id2 = "0999" next_id2 = lexid.incr(id2) print(f"Next ID after '{id2}': {next_id2}") # Expected: Next ID after '0999': 11000 # Recommended practice: start with higher numbers to reduce rollovers id3 = "1001" next_id3 = lexid.incr(id3) print(f"Next ID after '{id3}': {next_id3}") # Expected: Next ID after '1001': 1002
Debug
Known issues
gotchaLexid increments IDs to maintain lexical order, which can cause 'early' changes to the leftmost digit and increase string length (e.g., '0999' -> '11000'). This is by design, not a bug, but can be unexpected if the lexical ordering mechanism is not fully understood.
fix
Understand the library's core principle of lexical ordering as explained in the documentation. Test sequences to observe behavior. Consider the impact on storage or display if ID length changes are an issue.
affects: All versions
gotchaStarting IDs with leading zeros, such as '0001', can lead to rapid padding exhaustion and unexpected rollovers (e.g., '0001' -> '0002' -> ... -> '0999' -> '11000').
fix
The documentation recommends starting with a higher number, like '1001', to reduce the frequency of rollovers and avoid potential issues with zero truncation (e.g., if a system processes '0001' as '1').
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'lexid'
The `lexid` library is not installed in your Python environment or the environment you are running your script in.
fix
Run `pip install lexid` in your terminal to install the library.
AttributeError: module 'lexid' has no attribute 'increment'
You are trying to call a function named `increment` which does not exist directly within the `lexid` module. The correct function name for incrementing IDs is `incr`.
fix
Use `lexid.incr()` instead of `lexid.increment()`. For example: `new_id = lexid.incr('1001')`.
ValueError: invalid id_str: 'abc'
The `lexid.incr()` function expects a string or integer representing a lexically ordered numerical ID. Providing a string that does not conform to a valid numerical format (e.g., containing non-digits) will raise this error because the library cannot parse it as an ID to increment.
fix
Ensure the input to `lexid.incr()` is a string or integer that represents a valid numerical ID. For example: `new_id = lexid.incr('123')` or `new_id = lexid.incr(123)`.
Upgrade
Version history
2021.1006latest on PyPI · released Apr 2, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
lexid — pip install lexid · libregistry