9 ms·
Ask HN: Good Python projects to read for modern Python?
Django 4.0 projects would also be appreciated, or simply high quality Django projects.
- delneg 5y agoI've recently added support for Django 4.0 in https://github.com/Bearle/django_private_chat2 https://github.com/Bearle/django_private_chat2 The code is tested & known to work well
- greenie_beans 5y agoGonna hijack and ask for some Django projects with a lot of forms, especially nested forms with a lot of relationships. I’d be curious to learn from other folks how to do forms, how the views work (update vs create), etc.
- neilfrndes 5y agoIf you're running a startup, I recommend reading this guide to structuring Django projects: https://news.ycombinator.com/item?id=27605052 https://news.ycombinator.com/item?id=27605052
- spurgu 5y agoNot just Django and startups, that looks like a good guide on architecture overall!
- hotfixguru 5y agoNetBox[0] is a large project that does this. https://github.com/netbox-community/netbox https://github.com/netbox-community/netbox
- sairahul82 5y agoMy favorite way to find good projects to explore is using GitHub.com. I go to explore page and checkout trending projects for the week/today. https://github.com/trending/python?since=daily https://github.com/trending/python?since=daily
- turndown 5y agoI appreciate you providing a method for finding stuff, thanks.
- kortex 5y agoAnything by Sebastian Ramirez (fastapi), Samuel Colvin (pydantic), or the encode team (starlette). World class stuff. https://github.com/tiangolo https://github.com/tiangolo https://github.com/samuelcolvin/pydantic https://github.com/samuelcolvin/pydantic https://github.com/encode https://github.com/encode
- unbanned 5y agoFastapi is far from world class in any category other than usage. >Fast: Very high performance, on par with NodeJS and Go. Is a downright lie
- slrainka 5y agoBack it up with some evidence
- boustrophedon 5y agoNot the parent, but evidence was pretty easy to find[0]. fastapi comes in around 250-300th place in most of the benchmarks. ¯\_(ツ)_/¯ [0] https://www.techempower.com/benchmarks https://www.techempower.com/benchmarks
- faizshah 5y agoThat chart shows fastapi and nestjs are 2 of the fastest libraries among dynamic languages. And nestjs is <20% faster than fastapi because fastify is <20% faster than starlette. Not sure what this has to do with the library’s quality though, it is a high quality modern python library.
- Zababa 5y ago> That chart shows fastapi and nestjs are 2 of the fastest libraries among dynamic languages. With only JavaScript, Perl, Lua, PHP, Python and TypeScript enabled, fastapi is 64th and nestjs is 73rd, out of 136 libaries. They have a score that's ~10 times lower than the fastest libraries.
- systemvoltage 5y agoPeter Norvig’s notebooks and his course.
- ravish0007 5y agoI second this
- lngnmn2 5y ago/thread
- 41b696ef1113 5y agoAppreciating that Norvig is much smarter than myself... I find his style to be not great, too many code-golfing one liners. Not everything has to be a list comprehension (or even, a double list comprehension). Give me a boring loop with minimal action per line, please.
- systemvoltage 5y agoNorvig's approach of converting thoughts into a program is what you need to focus on. It is trivial to convert a list comprehension into a loop. In "When is Cheryl's birthday?" [1], the way he converts the problem into functional units is insane. A couple of list comprehensions shouldn't scare you. Look above and beyond the details. [1] https://github.com/norvig/pytudes/blob/main/ipynb/Cheryl.ipynb https://github.com/norvig/pytudes/blob/main/ipynb/Cheryl.ipy...
- npage97 5y agoI’ve worked on rich https://github.com/willmcgugan/rich https://github.com/willmcgugan/rich including adding strict mypy typing https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict https://mypy.readthedocs.io/en/stable/command_line.html#cmdo.... I found Will’s codebase easy to read and reason about, making it easy to help extend.
- roveo 5y agoWhat's up with if __name__ == "__main__": some random code at the end of module files? Never seen that, why is it used? I understand that it's a guard that only runs when the module is executed directly, but what is the code put there? For developers to quickly visually test stuff by running the module? Here, for example https://github.com/willmcgugan/rich/blob/master/rich/color.py#L557-L581 https://github.com/willmcgugan/rich/blob/master/rich/color.p...
- detaro 5y agoThat clearly prints out a reference of the colors, so yes, as shorthand for devs.
- npage97 5y agoYea it is there for devs to see different rich features in their console. You can run some examples using the -m flag + the submodule: python -m rich.live python -m rich.markdown # this is actually a markdown to terminal cli https://rich.readthedocs.io/en/stable/live.html https://rich.readthedocs.io/en/stable/live.html https://rich.readthedocs.io/en/stable/markdown.html https://rich.readthedocs.io/en/stable/markdown.html
- FreakLegion 5y agoIt's a common pattern as others have said, but this specific version of it is poor practice. The code should be in a function instead of polluting the global namespace (otherwise 'console', 'table', and 'color' end up being shadowed if they're used elsewhere in the file). Keep it clean with e.g.: def main() -> None: pass if __name__ == "__main__": main()
- charlieyu1 5y agoProbably read something that is related to your project. My moment of enlightenment was reading SymPy code. It was well explained and documented. Reading the code answered so many questions that you couldn’t get an answer on SO.
- cspickert 5y agohttps://github.com/getsentry/sentry https://github.com/getsentry/sentry
- l0b0 5y agoI'd recommend a project from work, Geostore[1]. Highlights: - 100% test coverage (with some typical exceptions like `if __name__ == "__main__":` blocks) - Randomises test sequence and inputs reproducibly - Passes Pylint with max McCabe complexity of 6 - Passes `mypy --strict` - Formatted using Black and isort [1] https://github.com/linz/geostore https://github.com/linz/geostore
- sandreas 5y agoI think that gpiozero might be worth a look: https://github.com/gpiozero/gpiozero/ https://github.com/gpiozero/gpiozero/
- heavyset_go 5y agoI don't think a lot of it exists yet, to be honest. Python 3.10's been a game changer when it comes to new patterns and idioms, and I don't think the dust has settled yet.
- HerrMonnezza 5y agoWhy is Python 3.10 a game changer? (Honest question)
- addcninblue 5y agoI think OP is referring to new features like pattern matching [1] that's been sorely missed in python for a while. [1]: https://www.python.org/dev/peps/pep-0634/ https://www.python.org/dev/peps/pep-0634/
- heavyset_go 5y agoStructural pattern matching is a big one. Similar to how type hinting gave us new patterns and libraries like Pydantic, FastAPI, etc, I suspect there will be new libraries and patterns that lean on structural typing heavily. 3.10 is also a culmination of additional features from 3.8 and 3.9 that were pretty lackluster on their own, but in combination with features from other point versions, you can do some cool things that you couldn't do as elegantly before.
- est 5y agoDjango itself. Really, django is the framework to read if you are into Python.
- yourkin 5y agoI've been working with Django since version 0.96. Still a lot of love for it, but for the last several years it's not my default for new projects though. The Django codebase is far from what can be called modern. As an experiment, it's easy to open up some Django core modules side by side with other frameworks that were mentioned (FastAPI for one) and to see that the code looks so different to the point where a programmer with not a lot of experience with Python might think those are different languages altogether. Much of Django's core has not changed in a very long time, so there would be no type annotations and other modern Python constructs. FastAPI, pydantic, uvicorn, httpx would be in my list to answer OPs question.
- est 5y ago> the code looks so different to the point where a programmer with not a lot of experience with Python might think those are different languages altogether Some of us actually prefer the "old" style of Python. Type annotations are too "Java-ish" for me, I hate source code that declares a function with signature takes more than half of the screen space, I hate making http requests with three layers of nested `async with`. If you are into static typing or RAII why not choose a real deal language instead.
- deleted 5y ago[deleted]
- hotfixguru 5y agoI think, in general, most FastAPI and Pydantic related libraries are heavily typed, use poetry, GitHub pipelines, black, isort, flake8 etc. so if you want to look at the ecosystem around a package I’ll recommend a few here, that has a smaller scope than the huge libraries Pydantic/FastAPI are. All packages listed below has all these things. FastAPI-Azure-Auth [0] is a library to do authentication and authorization through Azure AD using tokens. ASGI—Correlation-ID[1] is a package that utilizes contextvars to store information through the asyncio stack, in order to attach correlation/request ID to every log message from a request. Django-GUID [2] does the same for both sync and async Django. Pydantic-factories [3] is an awesome library to mock data for your pydantic models. [0] https://github.com/Intility/fastapi-azure-auth https://github.com/Intility/fastapi-azure-auth [1] https://github.com/snok/asgi-correlation-id https://github.com/snok/asgi-correlation-id [2] https://github.com/snok/django-guid https://github.com/snok/django-guid [3] https://github.com/Goldziher/pydantic-factories https://github.com/Goldziher/pydantic-factories
- usrme 5y agoHere's a few that haven't been mentioned yet: - PDM: A modern Python package manager with PEP 582 support[1] - Spleeter: Deezer source separation library including pretrained models[2] --- [0]: https://github.com/pdm-project/pdm https://github.com/pdm-project/pdm [1]: https://github.com/deezer/spleeter https://github.com/deezer/spleeter
- linkvee 5y agohere's one https://github.com/VeemsHQ/veems https://github.com/VeemsHQ/veems
- yla92 5y agoI think Bottle.py is quite interesting. It is a single file library (around 4k line) and has no dependencies other than the Python Standard Library. https://github.com/bottlepy/bottle/blob/master/bottle.py https://github.com/bottlepy/bottle/blob/master/bottle.py The other is Tornado. https://github.com/tornadoweb/tornado https://github.com/tornadoweb/tornado
- reidrac 5y ago+1 for Tornado. I used it early on when the docs where not there (IIRC), and spent some time reading the code. Very readable. Not sure if pythonic or not.
- est 5y agopeewee the ORM is also single file. Not perfect source code, but accomplish the task well.
- thijsvandien 5y agoTornado is an absolute feat of engineering. Shout-out to @bdarnell.
- uniqueuid 5y agoThe telethon library [1] is a very interesting case. It's fully async, implements the weird binary mtproto protocol, has optional C components for speedup and is partly auto-generated from protocol specs. It is an incredibly complex piece of code, but is immensely rigidly structured, typed and makes heavy use of OO to remain readable and manageable. So instead of perfect hypothetical textbook code, I think this is a very instructive realistic project. [1] https://github.com/LonamiWebs/Telethon https://github.com/LonamiWebs/Telethon
- starklevnertz 5y agoWhat’s your goal? Source code is not to be read like a book. If you read it, you must do so with a goal, context and purpose.
- drewcoo 5y agoIs there another way to read books? Only looking at the pictures isn't reading.
- deleted 5y ago[deleted]
- flaviojuvenal 5y agoThe EDX platform is open-source, it's a complex Django project: https://github.com/edx/edx-platform https://github.com/edx/edx-platform
- geenat 5y agoStarlette. Really any recent project by Encode: https://github.com/encode https://github.com/encode