5 ms·
I have a really high usefulness threshold for adding external dependencies to Python projects. If you can get away with never getting into the virtual environme
by nemetroid 6y ago
I have a really high usefulness threshold for adding external dependencies to Python projects. If you can get away with never getting into the virtual environment mess, distribution/installation/development becomes _so_ much simpler.
Of course, sometimes you can't avoid external dependencies (personally, this often involves pandas). But the standard library gets you really far. And even though urllib.request is clunky, I will only use Requests if something else already is forcing me to add external dependencies.
- dahfizz 6y agoI definitely agree for production-grade applications. Most of the time I'm using python, though, its to script a task I need to do or throw together a small app on a raspberry pi at home. In those cases, I have my own "standard library" of packages I always have installed system-wide, like requests. Unless I am making a "real" application, I do my best to avoid virtualenvs altogether.
- BiteCode_dev 6y agoYou don't have to. Use zipapps, this allows you to create a project with as many deps as you want, but use it as if it was a single python module. It's an official feature (https://docs.python.org/fr/3/library/zipapp.html https://docs.python.org/fr/3/library/zipapp.html) that lets Python execute an entire project bundled into a zip file. If you don't want to create it by hand, use shiv: https://pypi.org/project/shiv/ https://pypi.org/project/shiv/ It's the best of both worlds.
- dahfizz 6y agoThat's really cool! I can't believe I've never come across this, thanks for sharing!
- BiteCode_dev 6y agoYou are not alone. __main__.py in a zip has been supported litterally since Python 2.6 but very few people knew about it. Eventually in 3.5, the zipapp module has been released to make the feature more discoverable, but again it has been mostly ignored. I think the reason is that something like shiv was missing: it streamlines the process, shows a finish product instead of just telling people "all the thing they can do", and the automatic unzipping solved plenty of problems that you had with alternative like Pex, espacially on windows or with static resources. So now you have it. Spread the word.
- zdw 6y agoUrllib and surrounding web-API modules have made such great strides (and are built in in 3.x) that Requests isn't needed in almost all cases these days - I find some of the error handling it covers over at lower levels to be more problematic than useful. 90% of the time the only lines in my requirements.txt file are for PyYAML and Jinja2. Using just the Python standard library is the ideal case for scripts and other sysadmin-ey tools - no dependencies, runs with everywhere (tested in multiple python versions via tox) in a single source file.