Live data from Hacker News

Ask HN: What are some unusual but useful Python libraries you've discovered?

news.ycombinator.com

11–19 of 19 posts

Re: Ask HN: What are some unusual but useful Python libraries you've discovered?

#12
post #10

Defopt generates cli from function interface: https://defopt.readthedocs.io/en/stable/features.html The alternative is either you maintain two interfaces with boilerplate, or write a cli only if that’s the first priority. 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.

I wrote some stuff a while back to try and bridge this kind of issue.

I wrote a spec: https://gitlab.com/accidentallythecable-public/argstruct-spe...

And additionally, a library to build cli args and flags as well as api data from the same structure: https://gitlab.com/accidentallythecable-public/python-module...

This allows you to build an argstruct file specifying commands, ars, descriptions, etc. You can then run an arbitrary callback against the commands, or use argparser for commandline

Re: Ask HN: What are some unusual but useful Python libraries you've discovered?

#15

I use https://github.com/litl/backoff for configurable backoff + retry 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

Backoff doesn't look bad. I have used two libraries for retrying in Python: retry ( https://github.com/invl/retry ) and Tenacity ( https://github.com/jd/tenacity ). Tenacity actually helped me with a recent GPT-4o mini experiment, when OpenRouter gave me an error after a couple hundred requests. I can recommend Tenacity. A downside is that the API is fairly complex and verbose. You will probably look it up each time…

"stamina" is a wrapper for tenacity with nice defaults

Re: Ask HN: What are some unusual but useful Python libraries you've discovered?

#16

Last year I posted a similar Ask HN; it got 11 comments: https://news.ycombinator.com/item?id=38505531 . I asked, "What lesser-known Python libraries do you wish people knew about?" The suggestions there are worth looking up. Don't miss DiskCache ( https://github.com/grantjenks/python-diskcache ). I really like xmltodict ( https://github.com/martinblech/xmltodict ). Despite the name, it works in both directions. It i…

Thanks so much for pzp !

Re: Ask HN: What are some unusual but useful Python libraries you've discovered?

#17

Earlier quoted context omitted.

Backoff doesn't look bad. I have used two libraries for retrying in Python: retry ( https://github.com/invl/retry ) and Tenacity ( https://github.com/jd/tenacity ). Tenacity actually helped me with a recent GPT-4o mini experiment, when OpenRouter gave me an error after a couple hundred requests. I can recommend Tenacity. A downside is that the API is fairly complex and verbose. You will probably look it up each time…

"stamina" is a wrapper for tenacity with nice defaults

I didn't know about stamina. I like it a lot at first glance. Thanks for telling me.

Compared to Backoff, it has docs, and you don't need to tell it each time you want exponential backoff. (Exponential backoff is what you usually want when you don't want a fixed delay.) You can use Tenacity directly when you need something more complex.

https://github.com/hynek/stamina

Post reply on HN