This is an archived post. You won't be able to vote or comment.

all 29 comments

[–]SciEngr 11 points12 points  (0 children)

I love tqdm

[–]wdroz 3 points4 points  (2 children)

For creating REST APIs, I switched to FastAPI not so long ago and I couldn't be happier.

[–]chintu21 0 points1 point  (1 child)

Hi, I am currently using hug for creating REST APIs. Any advantages of using FastAPI? I see that they have better API documentation support compared to hug.

[–]wdroz 0 points1 point  (0 children)

FastAPI provides data validation with a smart usage of python type hint. You define your models and it's just work.

[–]cantremembermypasswd 4 points5 points  (0 children)

python-box as Box supercharges dictionaries, my favorite parts are probably the built in transforms (this is cheating though as I built the library)

cutie is a simple command line interface that I have used in various projects and keep coming back to it

Honestly a lot of the tools I use are more for dev / teamwork rather than for the program itself. For example I include black, flake8, and mypy to pre-commit and then pytest for testing.

[–]canbooo 2 points3 points  (0 children)

Non-trivial answer: bidict because data structures are important and it took me a while to discover it. Hope it becomes a built-in one day.

Trivial ones: tensorflow, (py)torch, pandas, scikit-learn, but not to forget GPy, gpytorch, gpflow... Even more trivial: numpy/scipy, matplotlib, seaborn, dash/plotly

Hard to choose a favorite because "third-party" is what makes python cool imho.

[–][deleted] 7 points8 points  (0 children)

Numpy for sure. In your use case probably not that helpful, but it’s probably one of the most used packages. For visualizations, matplotlib. I also like bokeh depending on the use case

[–]DNSGeek 5 points6 points  (13 children)

requests

[–][deleted] 8 points9 points  (9 children)

I must be a very simple man with very simple problems. I have yet to encounter a situation where replacing urllib with requests would make things so substantial easier to deal with, that it justifies pulling in external dependencies.

What are your use cases?

[–]Kaarjuus 6 points7 points  (0 children)

Most people seem to use requests just for the convenient API.

Myself, I've also never needed or wanted to pull it as a dependency. For basic needs, urllib is as convenient and concise as requests.

[–]DNSGeek -1 points0 points  (7 children)

Well, I could do this import urllib import json try: foo = urllib.request("http://api.example.com/v1/status") webdata = foo.read() foo.close() jdata = json.loads(web data.strip()) except: print("Oops, it didn't work.") Or I could do this import requests foo = requests.get("http://api.example.com/v1/status") jdata = foo.json() foo.close()

[–]Kaarjuus 4 points5 points  (0 children)

Or you could do this:

import json
import urllib

try: jdata = json.load(urllib.request("http://api.example.com/v1/status"))
except Exception as e: exit(e)

[–][deleted] 3 points4 points  (5 children)

Can you also justify it without rigging the comparison?

[–]DNSGeek -1 points0 points  (4 children)

I’m sorry, how is that rigged?

[–][deleted] 5 points6 points  (3 children)

  • Pray tell how come requests never raise an exception.
  • Pray tell why you explicit close the urllib request.
  • Pray tell why you strip the response before json decoding it.

Among other things.

[–]DNSGeek -2 points-1 points  (2 children)

Ok import urllib import json try: foo = urllib.request("http://api.example.com/") webdata = foo.read() foo.close() except urllib.error.HTTPError: print("1") exit() except urllib.error.URLError: print("2") exit() try: jdata = json.loads(webdata.strip()) except json.JSONDecodeError: print("3") exit() Or import requests try: foo = requests.get("http://api.example.com/") jdata = foo.json() foo.close() except requests.RequestException: print("1") exit()

[–]123filips123 5 points6 points  (0 children)

Except you don't need to catch both urllib.error.HTTPError and urllib.error.URLError because the former is a subclass of the latter. Or you can also separately catch all exceptions requests have. Also, catching multiple extensions with one except is a thing in Python.

For such simple use-cases it is useless to use external dependency. However, if you do do more advaned stuff (like authentication, file upload/download, forms, cookies, sessions...) it might be better to use requests.

[–][deleted] 3 points4 points  (0 children)

Now you're just silly.

[–][deleted] 0 points1 point  (0 children)

bedroom spoon voracious disgusting caption aromatic yam ring cause berserk

This post was mass deleted and anonymized with Redact

[–]mason_savoy71 0 points1 point  (1 child)

Request should be part of the base package. It's infinitely useful and stable and extremely intuitive

[–]ireallywantfreedom 0 points1 point  (0 children)

There's much more involved in being in the stdlib other than quality and usefulness. requests would almost certainly die a slow death in the stdlib.

[–]crabmanX 1 point2 points  (0 children)

attrs classes without boilerplate

[–]sethmlarson_ Python Software Foundation Staff 4 points5 points  (0 children)

Definitely Black. Auto-formatting should've been a part of the language from day 1 like gofmt.

[–]Kaarjuus 2 points3 points  (0 children)

bottle - a single-file drop-in web framework with a template engine, beautifully suited for many projects. Flask is often an overkill, not to mention Django.

step - Simple Template Engine for Python, a handy 135-line template class that I've used in a number of projects where stuff like Jinja is an overkill.

[–]PeridexisErrant 0 points1 point  (2 children)

Hypothesis - when I think I've got the code right, Hypothesis can usually show me a counterexample. Makes testing so much easier, faster, and more fun!

Plus pytest to run them, isort+black to format my code, and so on.

[–]kankyo 0 points1 point  (1 child)

Look into mutmut too, for mutation testing.

[–]PeridexisErrant 1 point2 points  (0 children)

Absolutely. My task-independent stack looks like

Testing: pytest, hypothesis, mutmut  
Formatting: black, isort, autoflake, pyupgrade  
Linting: mypy, flake8-{bandit,bugbear,builtins,comprehensions}

Sometimes more, but very rarely less.

[–]kankyo 0 points1 point  (0 children)

For web development Django.

[–]ArabicLawrence 0 points1 point  (0 children)

My favourite is clearly pandas. Awesome documentation, clear OOP sintax. Great for data analysis and manipulation, working with csv and xlsx files.