{"id":7358,"library":"lexid","title":"Lexical ID Generator","description":"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.","status":"active","version":"2021.1006","language":"en","source_language":"en","source_url":"https://github.com/mbarkhau/lexid","tags":["id generator","lexical ordering","build numbers","versioning","micro library"],"install":[{"cmd":"pip install lexid","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"lexid","correct":"import lexid"},{"note":"The primary function is `incr` accessed via the imported module.","symbol":"incr","correct":"lexid.incr('1')"}],"quickstart":{"code":"import lexid\n\n# Incrementing a simple ID\nid1 = \"1\"\nnext_id1 = lexid.incr(id1)\nprint(f\"Next ID after '{id1}': {next_id1}\")\n# Expected: Next ID after '1': 22\n\n# Demonstrating padding and 'early' increment\nid2 = \"0999\"\nnext_id2 = lexid.incr(id2)\nprint(f\"Next ID after '{id2}': {next_id2}\")\n# Expected: Next ID after '0999': 11000\n\n# Recommended practice: start with higher numbers to reduce rollovers\nid3 = \"1001\"\nnext_id3 = lexid.incr(id3)\nprint(f\"Next ID after '{id3}': {next_id3}\")\n# Expected: Next ID after '1001': 1002\n","lang":"python","description":"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."},"warnings":[{"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.","message":"Lexid 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.","severity":"gotcha","affected_versions":"All versions"},{"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').","message":"Starting IDs with leading zeros, such as '0001', can lead to rapid padding exhaustion and unexpected rollovers (e.g., '0001' -> '0002' -> ... -> '0999' -> '11000').","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install lexid` in your terminal to install the library.","cause":"The `lexid` library is not installed in your Python environment or the environment you are running your script in.","error":"ModuleNotFoundError: No module named 'lexid'"},{"fix":"Use `lexid.incr()` instead of `lexid.increment()`. For example: `new_id = lexid.incr('1001')`.","cause":"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`.","error":"AttributeError: module 'lexid' has no attribute '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)`.","cause":"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.","error":"ValueError: invalid id_str: 'abc'"}]}