HACKER Q&A
📣 turndown

Good Python projects to read for modern Python?


Django 4.0 projects would also be appreciated, or simply high quality Django projects.


  👤 kortex Accepted Answer ✓
Anything by Sebastian Ramirez (fastapi), Samuel Colvin (pydantic), or the encode team (starlette).

World class stuff.

https://github.com/tiangolo

https://github.com/samuelcolvin/pydantic

https://github.com/encode


👤 sairahul82
My 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

👤 npage97
I’ve worked on rich https://github.com/willmcgugan/rich including adding strict mypy typing 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.


👤 hotfixguru
I 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

[1] https://github.com/snok/asgi-correlation-id

[2] https://github.com/snok/django-guid

[3] https://github.com/Goldziher/pydantic-factories


👤 greenie_beans
Gonna 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.

👤 est
Django itself.

Really, django is the framework to read if you are into Python.



👤 charlieyu1
Probably 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.

👤 systemvoltage
Peter Norvig’s notebooks and his course.

👤 yla92
I 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

The other is Tornado. https://github.com/tornadoweb/tornado


👤 usrme
Here'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

[1]: https://github.com/deezer/spleeter


👤 l0b0
I'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


👤 uniqueuid
The 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


👤 heavyset_go
I 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.

👤 delneg
I've recently added support for Django 4.0 in https://github.com/Bearle/django_private_chat2

The code is tested & known to work well


👤 flaviojuvenal
The EDX platform is open-source, it's a complex Django project: https://github.com/edx/edx-platform

👤 sandreas
I think that gpiozero might be worth a look: https://github.com/gpiozero/gpiozero/

👤 geenat
Starlette.

Really any recent project by Encode: https://github.com/encode


👤 linkvee

👤 starklevnertz
What’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.