
myBasis
Everyday Python utilities for text, iteration, and type coercion.
I made this module to streamline some patterns that seemed both A) frequently-relevant and feasible to streamline. It grew alongside my projects over the years, which means it was in daily use by me from day one.
It covers iteration helpers, regex composition, caching, file formats, and runtime type casting (including a Pydantic model that applies the same casting rules during validation). It has (IMHO) novel, deep approaches to runtime typing ("Vibe Typing"), text processing, and building unusually-huge regular expressions pipelines without losing readability or performance. The regex work was driven by Wikiparse, where I had to write extremely performant code in Python for the first time. Nearly every Python project on this page depends on it. It's on PyPI as my-basis.
$ cat demo.py from my import ty, MyType, Span, ut print(ty.cast('42', int)) print(ty.cast(['1', '2', '3'], list[int])) print(ty.check('42', int)) print(ty.match('hello', str | int)) t = MyType(dict[str, int]) print(t.main) s = Span(3, 9) print(s) odds, evens = ut.partition(range(10), lambda n: n % 2 == 0) print(odds, evens) print(ut.decimal_to_roman(2026)) print(ut.plural(3, 'fox', 'foxes')) $ python demo.py 42 [1, 2, 3] False True <class 'dict'> 3-8 [1, 3, 5, 7, 9] [0, 2, 4, 6, 8] MMXXVI foxes