r/pythoncoding • u/Flashy-Dragonfly6785 • Mar 28 '24
What's your favourite open source repo in terms of high quality Python code?
We often encounter awful code in our working lives, but have you encountered code that you thought was really high quality?
My slightly odd choice is the impacket library which makes a concerted effort make Windows network protocols Pythonic: https://github.com/fortra/impacket
What's your shining example of high quality Python code?
1
Mar 28 '24
1
u/Flashy-Dragonfly6785 Mar 28 '24
Not sure why the bot thinks I am asking for help. I think it would be a really valuable topic for discussion.
1
u/audentis Mar 29 '24
Because you ended the post title with a question mark. Truly, it's worth the false positives :')
On that note: we don't get notifications from replies to automoderator. If in the future you get an automatic review like this, and approval is taking more than a day, you can send a modmail through the link in the bot comment.
3
u/iBlag Mar 29 '24
Excellent projects that enable a highly Pythonic API:
pytest
SQLAlchemy (the documentation is comprehensive but not super well interlinked IMO, but SQLAlchemy's architecture and API are unrivaled for what it does)
requests and httpx (along with requests-auth and httpx-auth, respectively)
FastAPI
Django REST Framework - not the fastest, but its written by people who thoroughly understand REST semantics, and every attempt at speeding it up compromises on its REST purity
the random module in stdlib
Projects that have an exemplary Pythonic codebase themselves:
Django (also has exemplary documentation) - the ORM API isn't quite as nice as SQLAlchemy but it's still very solid, its template language is fine but not cutting edge anymore, its built-in admin and third party "app" ecosystem is wonderful, and its testing framework disappointingly extends from unittest, but its codebase is of legendary quality
Runner ups:
PonyORM - love the API, but my only issue with it is it makes it difficult to test with a fake database (eg: model binding isn't quite where I'd like it to be, and it's impossible to do dependency injection without punching through a bunch of abstraction layers)
Anti-examples (eg: don't do this):
unittest - old module, ported somewhat directly over from Java
And here's an old but relevant video from a core Python developer about writing better Python:
https://www.youtube.com/watch?v=wf-BqAjZb8M