Registry / devops / python-hostlist

python-hostlist

JSON →
library2.3.0pypypi✓ verified 87d ago

python-hostlist is a Python module designed for parsing and expanding hostlist strings (e.g., 'host[01-03],host[05,07]'). It can expand such strings into a list of individual hostnames and also compress a list of hostnames back into a compact hostlist string. The library is actively maintained, with releases typically driven by bug fixes or minor feature additions.

pip install python-hostlist
INSTALL
IMPORT
SIG · PYTHON-HOSTLIST
P
python-hostlist
devopspythonv2.3.0
Install
2.4s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.0 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.4s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

hostlist
import hostlist
import python_hostlist
The installed package `python-hostlist` exposes its functionality under the `hostlist` top-level module name, not `python_hostlist`.

Demonstrates basic expansion and compression of hostlist strings, and checking for hostlist validity.

import hostlist # Expand a hostlist string expanded_hosts = hostlist.expand_hostlist('host[01-03,05],server[10-12]') print(f"Expanded: {expanded_hosts}") # Compress a list of hostnames hostnames = ['node01', 'node02', 'node03', 'node05', 'node07'] compressed_string = hostlist.compress_hostlist(hostnames) print(f"Compressed: {compressed_string}") # Check if a string is a valid hostlist is_valid = hostlist.is_hostlist('test[1-5]') print(f"Is 'test[1-5]' a valid hostlist? {is_valid}") is_invalid = hostlist.is_hostlist('test[1-a]') print(f"Is 'test[1-a]' a valid hostlist? {is_invalid}")
hostlist --version
Debug
Known issues
breakingPython 2 support was dropped in version 2.0.0. All versions >= 2.0.0 require Python 3 (specifically >=3.6).
fix
Ensure your environment uses Python 3.6 or newer. Upgrade your Python interpreter if necessary.
affects: >= 2.0.0
breakingThe `hostlist.get_ranges()` and `hostlist.get_groups()` functions were removed in version 2.2.0.
fix
Rewrite your code to use `hostlist.expand_hostlist()` and process the resulting list, or use `hostlist.compress_hostlist()` for the inverse operation. There are no direct replacements for these specific functions.
affects: >= 2.2.0
gotchaThe `compress_hostlist` function expects a sorted list of hostnames for optimal and consistent compression. Providing an unsorted list may result in a less efficient or unexpectedly formatted hostlist string.
fix
Always sort your list of hostnames before passing it to `hostlist.compress_hostlist()`, e.g., `hostlist.compress_hostlist(sorted(my_hostnames))`.
affects: All versions
gotchaInvalid hostlist string formats will raise a `hostlist.HostlistFormatException`.
fix
Always validate input strings using `hostlist.is_hostlist()` or wrap calls to `expand_hostlist()` in a `try...except hostlist.HostlistFormatException` block to handle malformed input gracefully.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'python_hostlist'
Attempting to import the module using the package name (`python_hostlist`) instead of its internal module name (`hostlist`).
fix
Change `import python_hostlist` to `import hostlist`.
hostlist.HostlistFormatException: Invalid Hostlist: host[1-a]
The input string provided to functions like `expand_hostlist` does not conform to the expected hostlist format.
fix
Review the hostlist string for syntax errors. Ensure ranges are numeric (e.g., `host[01-03]`) and separators are correct. Consider using `hostlist.is_hostlist()` to pre-validate inputs.
The compressed hostlist string is not as compact or ordered as expected.
The input list of hostnames provided to `compress_hostlist` was not sorted, leading to sub-optimal compression or unusual ordering.
fix
Sort the list of hostnames before passing it to the compression function: `hostlist.compress_hostlist(sorted(my_hostnames))`.
Upgrade
Version history
2.3.0latest on PyPI · released Aug 29, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
35 hits · last 30 days
node
32
Resources
python-hostlist — pip install python-hostlist · libregistry