Readit News logoReadit News
Posted by u/turndown 4 years ago
Ask HN: Good Python projects to read for modern Python?
Django 4.0 projects would also be appreciated, or simply high quality Django projects.
kortex · 4 years ago
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

unbanned · 4 years ago
Fastapi 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

mkl95 · 4 years ago
> Fastapi is far from world class in any category other than usage.

Imho FastAPI's weakest point is maintenance. The Github repo has 800+ open issues and 400+ open PRs. Tiangolo is the only user that constantly makes non trivial contributions. I just can't see that being sustainable in the long term if all those items are not actively triaged.

kortex · 4 years ago
OP asked for good projects to read. I think the code quality is very high, the documentation is great, it's been a joy to use, and it's been more than fast enough for my purposes.

I didn't make that speed claim, though I am aware that tidbit is controversial.

gigatexal · 4 years ago
Hrmm. But is the code pythonic? I’d say it is. That’s what the OP is looking for.
richardw · 4 years ago
Do you have any opinion on whether it’s a good example of a modern Python project, as per OP’s request?
slrainka · 4 years ago
Back it up with some evidence
sairahul82 · 4 years ago
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
turndown · 4 years ago
I appreciate you providing a method for finding stuff, thanks.
npage97 · 4 years ago
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.

roveo · 4 years ago
What'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.p...

npage97 · 4 years ago
Yea 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.htmlhttps://rich.readthedocs.io/en/stable/markdown.html

FreakLegion · 4 years ago
It'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()

detaro · 4 years ago
That clearly prints out a reference of the colors, so yes, as shorthand for devs.
hotfixguru · 4 years ago
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 · 4 years ago
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.
neilfrndes · 4 years ago
If you're running a startup, I recommend reading this guide to structuring Django projects: https://news.ycombinator.com/item?id=27605052
spurgu · 4 years ago
Not just Django and startups, that looks like a good guide on architecture overall!
hotfixguru · 4 years ago
NetBox[0] is a large project that does this.

https://github.com/netbox-community/netbox

est · 4 years ago
Django itself.

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

yourkin · 4 years ago
I'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 · 4 years 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.

charlieyu1 · 4 years ago
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.