Zero-dependency Python library implementing GNU expand(1) and unexpand(1) semantics: replace tabs with spaces and vice versa, with custom tab stops and leading-only / all-blanks modes.
python -m pip install -e .Requires Python 3.10+. No runtime dependencies.
from expand import expand, unexpand
expand("a\tb\tc", tabsize=4) # "a b c"
expand("a\tb\tc", tabsize=[4, 8, 12]) # "a b c"
unexpand(" hello", tabsize=4) # "\thello"
unexpand(" a b", tabsize=4, all_blanks=True)Replace tabs with spaces. tabsize may be a single int (every-N-columns) or a list of strictly-increasing stops.
Compress runs of spaces back to tabs where they reach a stop boundary.
Subclass of ValueError.
MIT