Hey everyone! I'm always on the lookout for new and interesting Python libraries that might not be well-known but are incredibly useful. Recently, I stumbled upon Rich for beautiful console output and Pydantic for data validation, which have been game-changers for my projects. What are some of the lesser-known libraries you've discovered that you think more people should know about? Share your favorites and how you use them!
Last year I posted a similar Ask HN;
it got 11 comments: <a href="https://news.ycombinator.com/item?id=38505531">https://news.ycombinator.com/item?id=38505531</a>.
I asked, "What lesser-known Python libraries do you wish people knew about?"
The suggestions there are worth looking up.
Don't miss DiskCache (<a href="https://github.com/grantjenks/python-diskcache">https://github.com/grantjenks/python-diskcache</a>).<p>I really like xmltodict (<a href="https://github.com/martinblech/xmltodict">https://github.com/martinblech/xmltodict</a>).
Despite the name, it works in both directions.
It is the most ergonomic library I have used for creating XML.
It has external type stubs: <a href="https://pypi.org/project/types-xmltodict/" rel="nofollow">https://pypi.org/project/types-xmltodict/</a>.<p>Since you have recently discovered Rich, you may want rich-argparse (<a href="https://github.com/hamdanal/rich-argparse">https://github.com/hamdanal/rich-argparse</a>).
It colorizes argparse CLIs with little effort from the user.<p>DeepDiff (<a href="https://github.com/seperman/deepdiff">https://github.com/seperman/deepdiff</a>) has helped me with testing.
I needed to compare two nested data structures but ignore any differences in floats (timestamps).
DeepDiff let me do it:<p><pre><code> diff = DeepDiff(
run_session(config), run_session(config, force=True), exclude_types=(float,)
)
assert not diff
</code></pre>
pzp (<a href="https://github.com/andreax79/pzp">https://github.com/andreax79/pzp</a>) is like fzf in pure Python to use in your programs.
Keep in mind it is currently version 0.0.x.
I have found bugs, but I think it is just cool that it exists.
I use <a href="https://github.com/litl/backoff">https://github.com/litl/backoff</a> for configurable backoff + retry<p>context: OpenAI API used to be super flaky back in the early days, i needed to retry my requests quite frequently and i found this
Happy user of Andrew Moffat's <a href="https://sh.readthedocs.io" rel="nofollow">https://sh.readthedocs.io</a> for over a decade.
Defopt generates cli from function interface: <a href="https://defopt.readthedocs.io/en/stable/features.html" rel="nofollow">https://defopt.readthedocs.io/en/stable/features.html</a><p>The alternative is either you maintain two interfaces with boilerplate, or write a cli only if that’s the first priority.<p>Similar solutions exist, like fire. But fire’s cli is like an afterthought, in the sense it gives people a way to run things in command line where they already know how to run it from Python.
This has been an absolute game changer: <a href="https://github.com/pytries/marisa-trie">https://github.com/pytries/marisa-trie</a> (succinct trie with fast lookup and minimal RAM)
Use case and more details in the wonderful book by Ian and Micha: High Performance Python
pg8000 [1] is a Postgres library implemented in pure Python. I've spent enough time trying to get psycopg installed on MacOS and Docker that I appreciate just being able to pip install it at any time.<p>[1] <a href="https://github.com/tlocke/pg8000">https://github.com/tlocke/pg8000</a>