Live data from Hacker News

Python Modern Practices

stuartellis.name

41–50 of 56 posts

Re: Python Modern Practices

#41

Curious why there is no mention of conda and its fast alternative mamba (micromamba). In my experience, conda is much more robust in managing. dependencies conflict (thanks to AWS and especially boto3) compared to pip.

I think nowadays conda uses mamba under the hood.

Re: Python Modern Practices

#42

I've been using conda+poetry as my goto combo for years now and it's served me very well. Sure it's said poetry doesn't follow certain standards, but it just abstracts away so much that I don't see myself needing anything else really. If I want to share a non-poetry artifact, it's a simple `poetry build` to create a wheel. I did come across a weird dependency confusion issue recently when I tried using it on a server…

I agree with most of this article but the "don't use poetry" comment is ridiculous. Pdm could be great with time but suggesting it is premature.

Re: Python Modern Practices

#43
post #3

Earlier quoted context omitted.

Was going to comment the same thing. Would love to hear the author expand further on why not use Poetry. I've found it to be pretty solid and continue to use Poetry + Pyenv for all my projects, but open to hearing the case for PDM or Hatch.

I've never worked on a team that uses Poetry, but in my current company another team uses it, and I haven't found it really as slick as I would have imagined, primarily because you need to create a venv and install poetry into that before you even get started, which by that point why not just pip install the rest anyway? For standalone applications it just seems like an unnecessary extra step. It doesn't even mandate…

Actually poetry comes with an optional self-installer, though I prefer to manage it with pipx. And it's recommended not to install it into your project env, as there's the potential for conflicting dependency versions.

Re: Python Modern Practices

#44
post #7
post #2

>Avoid using Poetry for new projects. Poetry predates many standards for Python tooling. This means that it uses non-standard implementations of key features, such as the dependency resolver and configuration formats in pyproject.toml files. What? This is the first I've heard of this.

pyenv? great! then just use pip with requirements.txt... what's wrong with pip freeze? why are there so many competing tools? it's very anti-python IMO.

> what's wrong with pip freeze?

Aside from all the obvious issues of having no distinction between transitive and direct dependencies, it completely breaks cross-platform support if any of your dependencies have platform-specific sub-dependencies (which is not uncommon in python).

Re: Python Modern Practices

#45
post #17
post #7

Earlier quoted context omitted.

pyenv? great! then just use pip with requirements.txt... what's wrong with pip freeze? why are there so many competing tools? it's very anti-python IMO.

> what's wrong with pip freeze? I prefer my requirements.txt to include only the packages I install with pip myself (and not their dependencies).

so then maintain a curated requirements.txt...

Re: Python Modern Practices

#46
post #10

Sad to not see Attrs mentioned. Dataclasses are cool, I guess, but Attrs is seriously great.

It's interesting to me that dataclasses seemed to be a slimmed down attrs but in practice I find it replaces namedtuple not attrs For my use the key is how easily you can add simple conversion of values to attrs. IIRC this was intentionally omitted from dataclasses. For a 1-off using a factory with a dataclass is easy but repeated uses send me back to attrs

Yeah, I think namedtuple's popularity (recommended in this link) was a mistake. It's sole modern use case should be to turn tuples used as an unnamed struct into a named struct while preserving tuple indexing for backward compatibility.

Most people don't need, say, a[-3] as an alias for a.field_name.

Otherwise, for those who want the standard library, use a dataclass with frozen=True for immutability.

Re: Python Modern Practices

#48
post #11

I'm surprised the post doesn't mention uv, which did quite well on HN a few months ago. Any experience? https://github.com/astral-sh/uv https://news.ycombinator.com/item?id=39387641

Can uv replace a `pipx --global` install option?

Re: Python Modern Practices

#49

what are the pros and cons with pydantic models vs data classes? i like the runtime validation in pydantic models. the pattern i landed on is that 1) only use primitive data types such as str, int, pydantic models and pandas dataframes to present data. 2) no classes with methods, no polymorphism, only use module functions.

Pydantic models are significantly more heavyweight than dataclasses -- They serve as validators as opposed to dataclasses, which are primarily just tools for managing structured data. Both are important problems, but they are different.

The power of Pydantic models comes with benefits in terms of what they're able to do out of the box. But this comes at a significant cost of speed, which does matter for some applications. There are plenty of applications where it simply doesn't make sense to validate types every time you stand up a class.

Sure you can turn some of that off with Pydantic, etc, etc, but the fact that dataclasses don't require a third party install and are efficient and easy out of the box makes them useful and non-duplicative.

Re: Python Modern Practices

#50
post #3

Earlier quoted context omitted.

Was going to comment the same thing. Would love to hear the author expand further on why not use Poetry. I've found it to be pretty solid and continue to use Poetry + Pyenv for all my projects, but open to hearing the case for PDM or Hatch.

I've never worked on a team that uses Poetry, but in my current company another team uses it, and I haven't found it really as slick as I would have imagined, primarily because you need to create a venv and install poetry into that before you even get started, which by that point why not just pip install the rest anyway? For standalone applications it just seems like an unnecessary extra step. It doesn't even mandate…

Poetry should not be installed into the local venv. That is a mistake. You should install it with homebrew or using its standalone installer.
Post reply on HN