Learn Python with Talk Python's 270 hours of courses

Hatch: A Modern Python Workflow

Episode #408, published Fri, Mar 24, 2023, recorded Wed, Mar 1, 2023

In recent years, there has been a lot of experimenting how we work with dependencies and external libraries for our Python code. There is pip, pip-tools, Poetry, pdm, pyenv, pipenv, Hatch and others workflows. We dove into this deeply back on episode 406: Reimagining Python's Packaging Workflows. We're back with Ofek Lev to take a deeper look at Hatch.


Watch this episode on YouTube
Play on YouTube
Watch the live stream version

Episode Deep Dive

Guests introduction and background

Ofek Lev is the author and maintainer of Hatch and Hatchling, popular Python packaging and workflow tools. He works at Datadog, focusing on agent integrations and monitoring. Ofek originally started coding to automate daily tasks, creating scripts for email templates and other repetitive actions. Over time, that automation mindset grew into deeper involvement with the Python community, culminating in the modern packaging workflow tool we know as Hatch.

What to Know If You're New to Python

Before diving into the intricacies of Hatch and Python packaging, here are a few foundational pointers to make the conversation more accessible:

  • Be aware of virtual environments. They isolate your Python packages so they don’t conflict with each other.
  • Recognize pip is the standard tool for installing external libraries, but there are higher-level workflows that build on it.
  • Understanding a basic project structure (folders, __init__.py, and the pyproject.toml file) will help you follow how Hatch organizes things.

Key points and takeaways

  1. Hatch’s Role in Modern Python Packaging Hatch is positioned as a comprehensive solution for creating, managing, and publishing Python packages. It brings together environment management, versioning, and publishing under one tool, striving for simplicity but also power.
  2. Hatch vs. Other Tools The Python ecosystem has many packaging and environment tools (pip, Poetry, Pipenv, pdm, etc.). Hatch differentiates itself with automatic environment syncing, easy version bumping, and a plugin system allowing for specialized builds or integrations.
  3. Environment Management Made Easy Hatch automatically creates and synchronizes virtual environments on your behalf. You can enter a shell (hatch shell) or run commands within the project (hatch run) without manually creating or activating a venv.
  4. “Hatch New” for Project Bootstrapping With hatch new <project_name>, you get a quickstart layout: a package folder, pyproject.toml, test directory, and default environment settings. This accelerates setting up consistent folder structures and default testing configurations.
  5. Version Bumping and Release Workflow Hatch supports versioning commands like hatch version minor or hatch version rc to update versions automatically. Building (hatch build) then creates both wheels and source distributions, while hatch publish simplifies publishing to PyPI or private indexes.
  6. Lock Files and Future Enhancements While Hatch doesn’t currently ship with its own lock file solution, Ofek emphasized that a plugin interface for locking is in active development. This will allow deeper reproducibility and align with popular tools like pip-tools.
  7. Plugin Ecosystem and Builders Hatch’s plugin interface powers custom build targets, such as building with MyPyC or for Jupyter extensions. Third-party plugins can hook into Hatch’s workflow, extending beyond just wheels and source distributions.
  8. Adoption by Large Projects Jupyter’s extension system recently standardized on Hatchling, highlighting Hatch’s growing acceptance. This recognition by major open-source projects validates Hatch’s reliability and developer-friendly approach.
  9. New Features on the Horizon Ofek plans to introduce “workspaces,” inspired by Cargo in Rust, to better support monorepos with multiple projects. This would simplify collaborative and large-scale development scenarios in one repository.
  10. Speed and Simplicity by Design Hatch uses lazy imports and other techniques under the hood for a faster CLI experience, often outperforming alternative packaging tools. This focus on both speed and simplicity helps new and seasoned developers alike.

Interesting quotes and stories

  • On Why Packaging Tools Matter: One user in the chat mentioned, “I switched to Hatch and pip-tools from poetry and love it.” This sentiment highlights how the right tooling can dramatically improve developer experience.
  • Ofek’s Personal Journey: Ofek started automating tasks because typing was physically challenging, eventually building Hatch as an expression of his belief in removing repetitive manual work for everyone.

Key definitions and terms

  • pyproject.toml: A central configuration file introduced in PEP 518, storing metadata like dependencies, build settings, and more.
  • Wheel: A built (binary) distribution format for Python packages, offering faster and more consistent installs than source distributions.
  • Virtual environment: A self-contained directory tree that contains its own Python installation plus dependencies, isolating it from system-level packages.
  • Plugin: In Hatch context, a mechanism allowing external tools to hook into the build or publishing workflow.

Learning resources

For listeners who want a deeper dive into Python development and packaging, here are some related materials:

  • Modern Python Projects: Create Python packages with modern tooling, learn about project organization, and discover best practices for versioning and dependencies.
  • Getting started with pytest: Learn about testing your packages effectively, since Hatch seamlessly integrates with pytest.

Overall takeaway

Hatch aims to unify core workflows—building, publishing, environment handling, and versioning—into one polished command-line tool. It focuses on simplifying packaging while still offering extensibility through plugins. With upcoming features like lock files and workspaces, Hatch looks poised to become even more compelling for Python developers wanting a single tool that just works. If you’re looking to streamline your packaging experience and accelerate your development process, Hatch is an exciting choice to explore.

Hatch: hatch.pypa.io
Ofek on Twitter: @Ofekmeister
Mamba: github.com
Hatch env management: hatch.pypa.io
Packaging a Python project tutorial: packaging.python.org
Customize project generation: hatch.pypa.io
Textual: textualize.io
Ruff on Talk Python: talkpython.fm
RustUp: rustup.rs
Conda: docs.conda.io
import antigravity: xkcd.com
Watch this episode on YouTube: youtube.com
Episode transcripts: talkpython.fm

--- Stay in touch with us ---
Subscribe to Talk Python on YouTube: youtube.com
Talk Python on Bluesky: @talkpython.fm at bsky.app
Talk Python on Mastodon: talkpython
Michael on Bluesky: @mkennedy.codes at bsky.app
Michael on Mastodon: mkennedy

Episode Transcript

Collapse transcript

00:00 In recent years, there's been a lot of experimenting with how we work with dependencies and external libraries for our Python code.

00:06 There's pip, pip-tools, poetry, PDM, pyenv, pipenv, Hatch, and other workflows.

00:13 We dove into this deeply back on episode 406, reimagining Python's packaging workflow with a panel.

00:22 And this time, we're back with Ofek Lev to take a deeper look at Hatch.

00:26 This is Talk Python to Me, episode 408, recorded March 1st, 2023.

00:32 Welcome to Talk Python to Me, a weekly podcast on Python.

00:49 This is your host, Michael Kennedy.

00:50 Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython.

00:56 Both on fosstodon.org.

00:58 Be careful with impersonating accounts on other instances.

01:01 There are many.

01:01 Keep up with the show and listen to over seven years of past episodes at talkpython.fm.

01:07 We've started streaming most of our episodes live on YouTube.

01:11 Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.

01:19 This episode is sponsored by Microsoft for Startups Founders Hub.

01:23 Check them out at talkpython.fm/foundershub to get early support for your startup.

01:29 And it's brought to you by Sentry.

01:31 Don't let those errors go unnoticed.

01:33 Use Sentry.

01:34 Get started at talkpython.fm/sentry.

01:37 OFEC, welcome to Talk Python to Me.

01:40 Thank you.

01:41 Good to be here.

01:41 It's been a long time, at least a week since you've been on the show.

01:44 Yep, just about a week.

01:47 Welcome back.

01:48 In that appearance, it was a big panel of many of us talking about Python packaging.

01:53 Yeah.

01:54 And you're the author of Hatch and Hatchling and a really interesting take on that tooling story.

02:01 So I thought it'd be fun to go ahead and just dive into that in particular for this episode and get your thoughts on it.

02:07 So I'm looking forward to talking about Hatch.

02:09 Yeah, sounds fun.

02:10 Yeah, it will be fun.

02:11 Before we get into it, though, a lot of people maybe don't know you out there.

02:14 What's your background?

02:15 How did you get into programming in Python?

02:17 Those sorts of things.

02:18 Let us know.

02:19 I guess originally, this was like maybe 15 years ago now, I was just automating stuff that I was doing every day.

02:27 So for me personally, I have a condition that makes me kind of weak.

02:31 So all I can use is like a mouse.

02:33 Therefore, I type pretty slow.

02:35 So I was automating like sentences, templating for like sending emails, basically like the traditional developer mindset.

02:45 If you do anything more than once or twice, just write a script for it.

02:49 So I had like dozens or maybe even a hundred scripts just to automate like boring stuff.

02:55 Kind of like the book, which I've never read the book.

02:58 Automate the boring stuff, but I imagine it's what I was doing.

03:01 That's how I originally got into Python.

03:03 Excellent.

03:03 You were doing the traditional developer thing.

03:06 Why spend 20 minutes doing something where you can spend two weeks automating it?

03:10 Yeah.

03:10 Just kidding.

03:11 I mean, like, I honestly, I really think that that's a huge value.

03:15 There's so many people out there, probably many people even listen to this podcast where they don't consider themselves developers,

03:23 but there's like little things that could be automated that are super annoying.

03:28 You don't look forward to it.

03:31 Just a little bit of programming skill will let you really blaze through those things.

03:36 Plus it also gets you further into Python where, you know, maybe one day you're releasing tools to manage everyone else's Python projects.

03:43 Yeah, for sure.

03:44 You don't know where it's going to go, right?

03:46 Yeah.

03:46 Now I work at Datadog working on agent integrations.

03:51 So it's like being that you physically install on your server host, it ships out of the box with like almost 200 integrations,

03:59 like connecting to databases like Postgres or monitoring like Windows APIs or hypervisors like vSphere,

04:09 pretty much whatever our customers want to monitor.

04:12 It's our job to like find a way to connect to it and provide useful data.

04:18 Yeah, excellent.

04:19 A lot of research into every product that we integrate with.

04:22 Sometimes the documentation is kind of sparse.

04:26 So it's lots of investigative work.

04:29 Yeah, I can imagine.

04:30 That sounds really fun.

04:32 And I can see that as a follow on from the way you got started as well, right?

04:37 Automating a bunch of tasks is not that different from kind of automating integration with 100 different apps

04:43 and performance counters and logs and different things, right?

04:48 Definitely.

04:48 Cool.

04:49 Is that part of the application performance monitoring type thing?

04:52 Are there?

04:53 We do that as well.

04:54 That's not my team, but yeah.

04:56 Okay.

04:56 That's part of what we do.

04:57 All right.

04:57 Well, let's go ahead and dive in.

05:01 Sure.

05:01 So as I said, if people want to check it out.

05:02 So as I said, if people want to check it out, you are on the Python packaging discussion.

05:07 And over there was a broad conversation with a bunch of core developers and other interested

05:13 folks building tools like Hatch and so on about where are we with packaging?

05:19 Because a little while ago, I remember packaging mostly felt like pip and set of tools, maybe

05:27 just just util, something like that.

05:29 And then it kind of got unlocked the separation of like the build back ends and stuff.

05:35 And then many people started creating things.

05:37 We had PIP, ENV.

05:38 We have poetry.

05:40 We have PDM.

05:41 There's a bunch of different ones and Hatch is amongst them, right?

05:45 Yeah.

05:45 Let's set the stage by just talking about, first of all, what do we mean when we're talking

05:50 about Python packaging?

05:51 And I'll ask you for you, right?

05:54 Like it might mean something different for me than it might mean for you.

05:58 And it might be different for someone else as well.

06:00 But let's just start with, you know, when we talk packaging, is that getting libraries

06:04 to devs?

06:05 Is that developers deploying their apps to servers?

06:08 Or is that me sending an executable end product to a desktop?

06:13 Like, what does it mean?

06:15 Yeah.

06:15 That's a good question.

06:16 I would say all of those are packaging.

06:19 Historically, though, we've mostly put our efforts toward the first one, which is basically

06:25 like a developer making a library and making that really simple for other developers to use

06:32 that library.

06:32 So in the form of wheels being hosted on PyPI in particular, that's what we put our efforts

06:39 on, which I think either way you look at it was the right choice to focus on in the

06:44 beginning.

06:45 Because like either way, like from either first principles or even hindsight, looking

06:50 back, you can't build a community without packages and being able to get packages and distribute

06:57 packages.

06:58 So I think that was the right choice.

07:00 And I think now we're trying to satisfy other use cases.

07:04 Notably applications, I guess.

07:07 Yeah.

07:07 Yeah.

07:07 I mean, we even have an XKCD for it, right?

07:10 True.

07:11 And I don't know how many people know this.

07:13 If you're in the Python REPL, you can type import anti-gravity.

07:17 And actually, it does something.

07:20 So the old XKCD is there's a person flying and the person on the ground looks at us.

07:25 How are you flying?

07:26 Python just learned it last night.

07:29 Everything's so simple.

07:30 Hello world is just print.

07:32 Hello world.

07:32 The person on the ground says, I don't know.

07:34 Dynamics typing white space.

07:36 Come on, join us.

07:38 Programming's fun again.

07:39 Okay.

07:39 But how are you flying?

07:40 I just typed import anti-gravity.

07:42 Right.

07:43 And it's a great joke.

07:45 But honestly, that is one of those superpowers of Python.

07:49 Is that how many things do we have right now?

07:52 How many packages?

07:52 436,000 packages.

07:55 Like insane.

07:57 It's just insane.

07:58 Yeah.

07:58 No, it's a massive community and really all kinds of domains from doing, you know,

08:04 as we talked about automating scripts, you know, different tasks to doing like

08:09 computing for, whether, you know, biomedical stuff, you know, even embedded devices now

08:17 with like, micro Python, stuff like that.

08:20 So it's, yeah.

08:21 Users of Python do everything pretty much.

08:24 Yeah.

08:25 I think in the near term, we're going to be talking about front end web as well with

08:30 PyScript and PyScript showed the possibilities, but I recently had a show on PyScript intersection

08:39 with micro Python.

08:40 And that starts to be like, well, here's a couple hundred K download.

08:44 And now you've got Python in the front end.

08:46 What do you think about it now?

08:47 But of course that has its own packaging and distribution story that we're going to have

08:52 to think about as well.

08:53 Like, well, kind of like node modules.

08:55 Now, what do you do with packages that got to run on the front end?

08:57 This is getting weird.

08:58 That kind of goes to, you know, talking about like how hard it is to do packaging when you

09:04 have, you know, dozens of use cases that we have to satisfy.

09:08 And with us being mostly just volunteers in our free time trying to do everything.

09:14 So, yeah.

09:14 Yeah.

09:15 It's fun and also challenging.

09:17 Yeah.

09:18 Yeah.

09:18 Absolutely.

09:18 Another area, another thing we could consider could be Conda, right?

09:23 Actually, I got that pulled over here.

09:25 Could be Conda, right?

09:26 This is a completely different take on pip and Wheels.

09:30 Yeah.

09:30 Conda is pretty cool.

09:31 I think Conda, if I have my history right, it came about because there really was no packaging

09:37 story.

09:38 Yeah.

09:38 Some time ago.

09:40 So, Conda, I think was made by Peter Yang, if I remember correctly.

09:44 And he has a whole company now around it supporting Conda.

09:48 And yeah, it just makes it easy to install, very complex stuff.

09:53 So, if your package depends on, yeah, you can put in Fortran and Rust and all kinds of stuff

10:00 and it just magically builds it and you can install it pretty easily.

10:05 Yeah.

10:06 It's pretty impressive.

10:07 It is pretty impressive.

10:08 And, you know, with Wheels now, it's closer, what we do with Pip.

10:12 It used to be setup.py would run and whatever it needed to do, it would do.

10:17 But often that would require, well, compile this.

10:19 Usually it was C back then, but for the scientific libraries, it says, well, compile this thing

10:26 with Fortran and then compile this thing with Scala.

10:29 You're like, I have neither of those things set up as dev tools on my environment.

10:33 I'm a science student.

10:35 What am I doing here?

10:36 Right.

10:37 And so, that was the angle they were solving.

10:39 And I think pip and Conda are coming a little bit closer together.

10:42 I think they're not necessarily converging, but they're more similar now than they used to be.

10:47 Yeah, definitely.

10:47 That is true.

10:48 And yeah, there was talk.

10:50 I don't know how many people are aware, but the Python forums has a subsection on discourse

10:56 for packaging.

10:57 So, yeah, right now there's actually talks from people at Conda trying to decide how we

11:03 can kind of provide a more unified experience.

11:07 Oh, that's interesting.

11:08 Because right now, Conda has their own repo for all their packages.

11:12 And PyPI is its own thing outside of Conda.

11:17 So, yeah, there's talk about possibly making that interoperable.

11:23 Oh, yeah.

11:23 Okay.

11:23 That'd be really interesting.

11:24 Let's see.

11:25 There was a question out here from Copa.

11:28 It says, we're in this realm.

11:30 Like, what do you think about Docker as a way of shipping things?

11:33 You know, a lot of times we'll get checkout, get clone some code on a server, maybe some production

11:40 branch, and then go through these steps, right?

11:43 pip install requirements or a hatch run type of initialization, or you just get that done

11:50 in a Docker container and you just hand that out.

11:52 What are your thoughts on Docker as part of this?

11:54 Yeah, Docker definitely has its use cases.

11:57 Like, I guess in lieu of the block file, you could kind of use Docker as a reproducible,

12:03 you know, environment.

12:05 But I still think there's a place for a way to actually build applications and, you know,

12:11 outside of Docker, outside of containers in a reproducible fashion.

12:15 I think that's still necessary.

12:17 I do as well.

12:18 And so Docker really, it addresses some of the types of packaging that we discussed really,

12:25 really well.

12:26 For example, I need to get my running code onto a server, but Docker is less good.

12:32 It's not completely irrelevant, but it's less good at giving a developer a library, right?

12:37 If people that make HTTPX and the people that make FastAPI, they're not going to build a

12:44 combo Docker, right?

12:46 There's still a place where you've just got to get the things.

12:49 And that's like a base level closer to where a hatch might be working.

12:52 And also Docker is not fantastic at sending to an end user.

12:56 If I want to build an app that a non-technical, non-developer person can use, Docker is the

13:02 opposite of what they want.

13:03 You know what I mean?

13:04 Yeah, true.

13:04 Yeah.

13:05 I will say there's another use case, which is like, if your machine is like messed up somehow

13:11 and some library package isn't working.

13:14 I've had this happen with my coworkers on their Macs.

13:18 It is nice to be able to just go into a container and start fresh.

13:22 So I've had that happen a few times.

13:24 It is isolated in quite a good way.

13:26 And that's pretty excellent.

13:28 So on that packaging panel that we were on, there was a really interesting focus for a little

13:36 bit talking about, well, what is responsible for what?

13:41 So right now, for example, I might use pip as a way to add tools to Python, to a Python project,

13:49 but I'll have to already have Python there.

13:52 And in other communities, and even a little bit like Honda in this as well, there's tools

13:58 that will say, what you do is use a tool kind of like pip, but it gets you the runtime.

14:03 It would get you a version of Python you asked for plus the libraries.

14:07 You know, I think RustUp was one of the things that was brought up there, right?

14:14 So for people who don't know RustUp, it's an installer for basically setting up a Rust environment

14:21 for doing Rust.

14:22 So pip up, Python up, I don't know.

14:25 I don't know what we would call it.

14:26 But do you want to just, you know, maybe give your thoughts on that?

14:29 Because I think you had some comments on that, like inside out, outside in, where, if you

14:34 could start fresh, where were the tools?

14:36 How would that work?

14:37 Yeah, I think if we were to start fresh, I think the way Rust does it is like now the

14:41 gold standard.

14:42 It's probably the best way to do it, which is how, as you mentioned, Conda, a similar thing,

14:49 where you have a tool that you download.

14:51 And that one tool is in charge of managing the various Python or programming language versions.

14:59 So if I were to start fresh, you would have a tool like catch that you would download, you

15:05 know, as an MSI or EXE or some kind of installer similar to RustUp.

15:10 And then that tool would manage the various Python versions and environments and packaging.

15:17 So for RustUp, when you download this, it gives you RustUp, which manages Rust.

15:23 But then it gives you Cargo, which is a separate command.

15:27 And that's their package manager.

15:29 But in both cases, they live outside of the Python.

15:32 Interesting.

15:32 Yeah.

15:32 Cargo is to Rust as pip is to Python, right?

15:35 That kind of thing.

15:36 Hey, folks, let's pause for an ad.

15:40 Remember last time I had this advertisement for Microsoft for startups?

15:43 Well, I asked the AI to have some fun with it just to show you how powerful what they have

15:48 on offer really is.

15:50 Here we go.

15:50 Me.

15:52 Can you rephrase that Microsoft Founders Hub ad as a hipster?

15:55 AI.

15:56 Sure.

15:57 Here's a rephrased version of the ad in hipster style.

16:00 Yo, Talk Python fam.

16:02 This segment is brought to you by the sickest program out there for startup founders, Microsoft

16:06 for startups Founders Hub.

16:08 If you're a boss running a startup, you're going to want to listen up because this is the

16:12 deal of a lifetime.

16:13 Microsoft for Founders Hub is your ticket to scaling efficiently and preserving your runway

16:17 all the while keeping your cool factor intact.

16:20 With over six figures worth of benefits, this program is seriously next level.

16:24 You'll get $150,000 in Azure credits, the richest cloud credit offering on the market,

16:29 access to the OpenAI APIs in the new Azure OpenAI service, where you can infuse some serious

16:35 generative AI into your apps, and a one-on-one technical advisory from the Microsoft squad, who

16:41 will help you with your tech stack and architectural plans.

16:44 This program is open all, whether you're just starting or you're already killing it.

16:47 And the best part, there's no funding requirement.

16:50 All it takes is five minutes to apply, and you'll be reaping the benefits in no time.

16:54 Check it out and sign up for Microsoft for Startup Founders Hub at talkpython.fm slash

16:58 foundershub.

16:59 Peace out and keep listening.

17:01 Thank you, Hipster Michael.

17:02 And thank you, Microsoft for Startups Founders Hub, for sponsoring the show.

17:08 I think that's pretty helpful because one of the problems is, well, you need to pip install this

17:13 thing.

17:13 Oh, do you have the wrong version of Python?

17:15 Well, you got to, you know, there's a lot of steps back, and there's no immediately obvious

17:20 command other than completely from scratch install a new Python.

17:24 Yeah.

17:25 There's the tools that manage that, right?

17:26 Like, PyEnv can work, although I've had trouble with it.

17:30 Yeah, I've had issues with that.

17:31 Yeah, I think it would be less error-prone in this hypothetical way, where the tool doesn't

17:37 mess with your shell in a global manner.

17:41 It just has its own paths to Python and just does everything by itself.

17:47 That's interesting, and that starts to maybe make it easier to solve the, I want to ship

17:52 you an executable binary, is if the tool were in charge of, I create this working directory

17:58 where part of the things I've installed is all of Python and all the packages you've asked

18:04 me for, I can see how that pretty quickly becomes something.

18:07 I'll bundle that up and hand it to somebody and, you know, give them an entry point.

18:11 Definitely, I could help that situation.

18:13 I think there's not really a standard way to build an AXE from like a Python package.

18:20 There are a few tools, like PyOxidizer is one newer option.

18:25 PyInstaller, CX Freeze, I think was the thing that I've used before.

18:30 So there's a few options.

18:32 Yeah, I've used PyToApp, and that's actually worked really well.

18:34 I've used PyInstaller, and it's worked mostly well, except for I've had weird situations

18:39 where on Windows it's great, but on Mac it has a dangling terminal.

18:44 In addition to the GUI, I'm like, what are we supposed to do that?

18:47 How do we make it go away?

18:48 Like, you know, here's the command.

18:50 Like, no, it's not going away.

18:51 I don't know why.

18:52 And if there was a more official sort of core dev organized way, that would make me super happy.

18:58 I'm not supposed to say for official or unofficial.

19:01 Like, my view is like, if it works, it works.

19:05 So as long as it's satisfying, you know, all the use cases, that's what I would push for.

19:10 So I think right now, based on what I've used personally, I think PyOxidizer would be the

19:16 best choice for distributing standalone apps.

19:19 Interesting.

19:20 Okay.

19:20 All right, cool.

19:21 Well, let's move on and start talking about Hatch.

19:26 So first off, why'd you build it?

19:29 Right?

19:30 We had Pip.

19:31 Why do we need Hatch?

19:33 And, you know, I don't know exactly the timeframe of when it came out.

19:36 So maybe we had other things like poetry or, you know, why'd you go and create this?

19:40 So Hatch, I did, it was kind of an older project back in the end of 2016 or early 2017.

19:48 I wasn't pleased with like the tooling in Python.

19:53 I think very similar to the author of poetry.

19:56 That's kind of why he made poetry.

19:58 So I wanted something that kind of matched my mental model of how development would go

20:05 with building packages and managing environments automatically, stuff like that.

20:10 When I made it though, there weren't very many standards for packaging.

20:15 And everything was kind of in limbo at that point, which kind of discouraged me from continuing.

20:21 Because then I was like, okay, in a six months or a year or two, I'm going to have to rewrite

20:27 to follow standards.

20:29 So I kind of just stopped development for a few years until everything was standardized.

20:35 And then I rewrote it about a year and a half ago with this new version and new docs.

20:42 So that's kind of the history of it.

20:45 Yeah.

20:45 I saw that there's a hatch.toml and a pyproject.toml and you can use either of them.

20:51 Was your hatch.toml the original and then pyproject.toml gained traction?

20:56 You're like, all right, well, we'll integrate with that as well.

20:58 No, hatch.toml came with the rewrite.

21:01 It's mostly for environments.

21:03 Sometimes when you define lots of environments, it's very verbose.

21:07 Like at my workplace, I saw a tox file that was like over a thousand lines.

21:13 So putting that in pyproject wouldn't be very nice.

21:17 So that's why I have a second file to isolate certain features.

21:20 Yeah, that makes sense.

21:21 Just like maybe you don't want to write your entire application in an app.py,

21:24 but maybe have multiple files.

21:27 Yeah, something like that.

21:28 All right.

21:28 Well, out in the audience, we've got some kind words.

21:31 Like I switched to hatch and pip-tools from poetry and love it.

21:34 That's pretty awesome.

21:35 Yeah.

21:36 And then probably before I'll forget, because it was right at the top of the conversation,

21:40 Marwan asks, is there a time estimate for when a hatch might support things like lock files?

21:47 That's a good question.

21:48 So my goal is by PyCon to write the plugin interface for locking.

21:58 So the first version will use pip-tools, actually.

22:01 That would be the first plugin for lock files.

22:04 But I won't be writing like an actual lock file spec.

22:08 I'll just be using an existing tool.

22:12 It's kind of blocked on Brett because he has most context and knowledge about that.

22:18 So yeah, I'm waiting on Brett, basically.

22:21 Got it.

22:21 Brett Cannon.

22:22 That being Brett Cannon.

22:23 Yes.

22:24 Python developer extraordinaire.

22:25 We all know.

22:26 Okay.

22:27 Very cool.

22:28 Other thing before we dive into it here.

22:29 I see that you have some rough action going there.

22:33 I just had Charlie on the show not too long ago to talk about rough.

22:37 It's pretty impressive.

22:38 When did you adopt that?

22:40 I was an early adopter.

22:41 I guess a few months ago now.

22:43 Yeah.

22:43 What's your experience?

22:44 It's fantastic.

22:45 It's kind of like a meme to say it now, but it's true.

22:48 Like, it's so fast.

22:49 It's almost like you wonder if it's doing anything.

22:52 Like, it's...

22:54 That was my first thought.

22:55 When I ran it, I'm like, wait a minute.

22:56 Maybe I didn't give it any files or something.

22:57 Because I ran it on Talk Python training, which is like 20,000 lines of Python code.

23:02 And it just went, bam, like that.

23:04 And I'm like, maybe it didn't take that.

23:05 Because that seems like that should take a moment at least somehow.

23:09 Yeah.

23:10 Okay.

23:10 So you recommend it?

23:11 Yeah.

23:12 All around kind of one location.

23:13 And it supports, like, so many options as well, which is nice.

23:19 Yeah.

23:19 Indeed.

23:19 Cool, cool.

23:20 All right.

23:21 Well, let's start with a high-level overview.

23:24 And then what I want to do is I want to walk through creating a project with this.

23:28 And I've got questions and thoughts as I kind of experience Hatch.

23:32 Not for the first time, but for somewhat of a newbie perspective.

23:36 So I think we'll do that.

23:37 But let's start with the high-level features.

23:40 So the Hatch project is, I guess, conceptually two different projects.

23:44 Hatch itself is the command line.

23:47 So doing publishing and environment management, versioning, stuff like that.

23:53 Then Hatch thing is the build system, similar to a flip or set tools.

24:00 So that's where the build system is.

24:03 And you can use it independently, right?

24:05 You don't have to be doing anything with Hatch to use HatchLeen.

24:09 Basically to replace setup.py, right?

24:13 Yeah.

24:13 You can replace it with the pyproject.toml.

24:16 Yeah.

24:17 And most people do use HatchLeen and not use Hatch.

24:21 So yeah.

24:22 HatchLeen is much more popular than Hatch itself.

24:25 Okay.

24:26 So for a config, it's a bit more simple than setup tools.

24:30 The default logic makes more sense for new users, especially.

24:37 It's hard to mess up packaging with HatchLeen.

24:41 Yeah.

24:41 Excellent.

24:41 So I could have just some random Python project that I've put together with a PyProject.tomal

24:47 I wrote by hand and I could just put HatchLeen in as the build subsystem to make the wheels

24:53 and whatnot, right?

24:54 One benefit of HatchLeen, I hatched too.

24:56 Basically everything is a plugin.

24:58 So you can have like a build hook that does like the mypyC, which we have.

25:04 You can have a metadata hook where you insert like project URLs from some arbitrary location.

25:12 Pretty much everything you can plug into and modify.

25:16 Yeah.

25:16 Excellent.

25:17 All right.

25:18 And then a robust environment management.

25:20 Yeah.

25:21 So for this, this you can think of as a, as talks or knocks, similar in spirit to that.

25:28 The difference is knocks and talks kind of treat environments as applications where an environment

25:36 is tied to a command and you run an environment.

25:39 Whereas in Hatch, you have environments that you define.

25:43 And then within that, you have scripts that you can run.

25:47 So you can have a style environment that might be able to rent with one script or run the

25:55 formatter to change the code with another script.

25:58 An environment itself isn't actually like, like an app.

26:03 You can run arbitrary commands.

26:05 Right.

26:06 Like I could run Hatch test or something like that.

26:10 Yeah.

26:11 And passing flags.

26:12 Yeah.

26:12 Okay.

26:13 And then often people who published packages to PyPI, they've done this with Twine or some

26:21 tool like that.

26:21 And Hatch has that capability as well, right?

26:24 Right.

26:24 Yeah.

26:24 To, yeah.

26:25 PyPI or some private, you know, corporate owned index.

26:31 I think those are probably going to be more popular than they used to be with all the supply

26:36 chain silliness.

26:37 Yeah, that's true.

26:38 Yeah.

26:39 Do you have any visibility into how people are using it, whether it's public or private or

26:43 As far as Hatch?

26:45 Yeah.

26:45 Well, how they're using Hatch to publish, do you have any visibility whether they're

26:49 publishing to PyPI or to some kind of private index?

26:52 Based on the issues I have open, like future requests, most are talking about private indices,

26:58 actually.

26:59 Interesting.

26:59 Yeah.

27:00 It's probably those are the ones where the edge cases live.

27:02 You know, the standard one place is dialed in.

27:05 And what if mine's using Active Directory for authentication as I publish it?

27:10 Like, it's doing what?

27:11 Artifactory is quite popular as well.

27:15 Yeah.

27:15 Yeah.

27:15 That absolutely is.

27:17 Another thing that was interesting is you have the ability to do version management,

27:21 as we'll see in just a minute.

27:22 You can say, like, what version is my package?

27:24 Increment the build or do a major version increment or put it into a release candidate mode.

27:30 Yeah.

27:31 And this is plugable as well.

27:33 So there's one plugin that's popular that wraps setup tools SCM, which doesn't actually

27:39 depend on setup tools anymore.

27:41 It's just in name.

27:42 It's still called that.

27:44 So that pulls your version from Git or Mercurial or Subversion.

27:49 And you can source the versions that way as well.

27:53 Interesting.

27:53 Yeah.

27:53 I really like that.

27:54 I think that's a neat aspect.

27:56 And then configurable project generation with same defaults.

28:01 Yeah.

28:01 I don't have too many options with this yet, but you can make it a flat layout or like a source

28:08 directory.

28:09 There's an option to add tests, which puts more stuff in your PyProject.com.

28:16 You can add a CLI, which has a very simple template for GitHub actions.

28:22 And then there's a flag for your CLI that would give you a click and set up a command line for

28:30 your package.

28:31 I don't know how directly related this is to anything that Hatch does.

28:35 But the usage of the PyProject.toml and then building it as a package, something you could

28:40 install, gives you a really nice way to create a global CLI, right?

28:45 With just the entry points in the PyProject.toml.

28:48 Yeah.

28:48 That's what that CLI flag does.

28:49 Yeah.

28:50 It's very nice.

28:51 Okay.

28:51 Yeah.

28:52 Then also you say it's two to three times faster than equivalent tools.

28:55 That's great.

28:56 It really is just one trick.

28:57 It's just I make the code not as readable by using lazy imports everywhere.

29:04 I just put lazy imports and that's why it's faster, essentially.

29:08 Yeah.

29:09 Because there's a lot of execution paths that only use some of the imports in effect, right?

29:12 Yeah.

29:13 Going back to the scripts, Jonathan points out, I love the custom scripts within Hatch.

29:17 It makes creating build pipelines way easier and moves most of the logic within the Hatch

29:22 configure rather than spreading them around multiple files, which is, that's pretty cool.

29:25 Yeah.

29:25 That's what I do as well.

29:26 Cool.

29:26 I even use Hatch for non-Python projects just for the scripting.

29:31 Yeah.

29:32 Cool.

29:32 Well, I mean, Python traditionally had been used for a lot of that, you know, called it glue

29:38 code, right?

29:38 A lot of, well, I really want to do these other things with these other systems and scripts,

29:42 but let me kind of orchestrate that in Python.

29:44 And that sounds a bit, a bit like that.

29:46 Yeah.

29:47 Let's do a little walkthrough, I think.

29:48 I think that'll be fun.

29:49 But first of all, I think this is just MKDocs, but thank you for pointing it out that your

29:55 documentation and your website here have hotkeys.

29:59 Yeah.

29:59 MKDocs with the material theme, which is very nice.

30:03 Yeah.

30:03 So it turns out if I just press a dot, it goes to the next page.

30:06 And if I comment, it goes to the previous page.

30:08 And it doesn't sound like much, but actually it's really nice.

30:11 It is really nice.

30:12 Before we leave this front page, one other thing to note to go back to the top, just because

30:17 I'm very happy with it.

30:18 The logo was actually generated by Dolly, the AI.

30:22 Okay.

30:22 Yeah.

30:23 Fantastic.

30:24 Yeah.

30:24 I generated the logo.

30:25 And then I had a brother of a friend from work, I like actually touch it up.

30:30 So.

30:30 Oh, it's a really cool logo.

30:31 I like it.

30:32 I didn't catch on that it was made by Dolly, but now I see that.

30:35 I've been doing a lot with mid-journey.

30:38 And I think these AI tools are, I think they're a little bit fraught with maybe a few moral

30:43 issues about like, well, did you really train it on stuff that you were allowed to train on?

30:47 But putting that aside, if they exist, you know, assuming just they exist, they're really

30:51 neat.

30:51 And there's really amazing stuff you can do with them.

30:53 Yeah.

30:54 Yeah.

30:54 Cool.

30:55 I guess maybe a quick sidebar there is if you were a project maintainer out there and you

31:00 don't really have a logo, drop in on Dolly or Mid Journey and spend half an hour and

31:06 you probably will.

31:07 But I just think there are so many people that build web apps out there that don't put

31:12 hotkeys into them.

31:13 And it's, it is not that hard.

31:15 And it is such a nice experience.

31:17 And it brings you so much closer to a native app type of experience.

31:20 So please put, put some hotkeys out there for us.

31:22 All right.

31:23 So pressing dot takes to the first one.

31:25 So installing hatch, obviously you can pip install it.

31:28 However, you offer some interesting other areas I want to talk about.

31:32 First of all, my favorite pipX.

31:35 I love pipX.

31:36 If you've got a tool that you don't directly import into your code that does stuff against

31:42 your Python apps.

31:43 Boy, pipX is almost always a good choice.

31:46 What do you think?

31:47 Oh yeah.

31:47 PipX is awesome.

31:48 Yeah.

31:49 Yeah.

31:49 It just allows you to, you know, provide isolated apps for command line apps.

31:55 Yeah.

31:55 It manages everything and you don't even have to think about it.

31:58 So yeah.

31:59 It just creates its own little environment.

32:00 And you can say upgrade all my installed CLI tools.

32:03 It's like package manager.

32:05 If the thing that it's managing is built with Python is great.

32:08 I had chat on the creator of pipX a while ago.

32:11 So people, if they want to hear more about it, they can listen to that show.

32:13 Homebrew.

32:14 Good.

32:14 MacPort is interesting.

32:17 But the one that stood out to me was Mamba.

32:19 I'm like, wait, what's Mamba?

32:23 It's interesting.

32:24 I hadn't heard of that, but yeah.

32:25 Yeah.

32:25 I don't use Konda that much, but as far as I know, there's a few different distributions

32:30 of Konda.

32:31 So there's Anaconda, which gives you like over a gigabyte installed, like massive scientific

32:39 computing.

32:39 There's Miniconda and Miniconda gives you just the bare minimum Konda CLI with like package

32:47 management.

32:48 And that's what most people use, I think.

32:50 But now there's Mamba, which is like Miniconda.

32:53 But it pulls from Konda Forge by default.

32:57 And Konda Forge is sort of like our PyPI, where anybody can contribute their own packages.

33:05 So I think that's the main difference.

33:07 And yeah, it is faster and it was rewritten.

33:11 And that's what Mamba is.

33:13 It's a re-implementation of Konda, the Konda package manager in C++, doing parallel downloading

33:20 and other bits of that, which is interesting.

33:23 Cool.

33:24 Well, I don't use either all that much, but it's still kind of cool to see there.

33:29 So you could Mamba install Hatch if that was your workflow as well, right?

33:33 Okay.

33:34 So installing it pretty easy.

33:36 If you were to do it, if somebody gave you a blank machine and said, set this up to use

33:40 Hatch, what would you do?

33:42 For now, I would do PIPX.

33:44 Okay.

33:45 In the future, like we talked about in the beginning, I plan to have like an actual executable that

33:51 does the work, like Python does.

33:53 But until then, then probably PIPX.

33:56 Okay.

33:56 So maybe then it would be Homebrew and Winget and apps, things like the higher level OS ones.

34:03 Okay.

34:03 This portion of Talk Python to Me is brought to you by Sentry.

34:08 Is your Python application fast?

34:11 Or does it sometimes suffer from slowdowns and unexpected latency?

34:15 Does this usually only happen in production?

34:18 It's really tough to track down the problems at that point, isn't it?

34:21 If you've looked at APM, application performance monitoring products before, they may have felt

34:26 out of place for software teams.

34:28 Many of them are more focused on legacy problems made for ops and infrastructure teams to keep

34:33 their infrastructure and services up and running.

34:36 Sentry has just launched their new APM service.

34:40 And Sentry's approach to application monitoring is focused on being actionable, affordable, and

34:45 actually built for developers.

34:47 Whether it's a slow running query or latent payment endpoint that's at risk of timing out

34:51 and causing sales to tank, Sentry removes the complexity and does the analysis for you,

34:57 surfacing the most critical performance issues so you can address them immediately.

35:01 Most legacy APM tools focus on an ingest-everything approach, resulting in high storage costs,

35:07 noisy environments, and an enormous amount of telemetry data most developers will never need

35:12 to analyze.

35:13 Sentry has taken a different approach, building the most affordable APM solution in the market.

35:19 They've removed the noise and extracted the maximum value out of your performance data while passing

35:23 the savings directly onto you, especially for Talk Python listeners who use the code Talk Python.

35:29 So get started at talkpython.fm/sentry and be sure to use their code Talk Python all lowercase

35:36 so you let them know that you heard about them from us.

35:39 My thanks to Sentry for keeping this podcast going strong.

35:43 All right, so the way we get started is we just say Hatch New.

35:50 And I thought one of the things I don't normally do here on the podcast, but I think it might be fun,

35:54 is just to kind of go through these steps here to see what it's like to get a sense,

36:00 because then I can ask questions.

36:02 So I'll say Hatch New Calci.

36:05 I'll call my little app Calci.

36:06 And tell us about what we get when we run that.

36:08 Sure.

36:09 So it makes your package as you named it with About.py and Init.py.

36:16 The Init.py obviously makes it, turns that directory into a Python package.

36:21 The About.py stores the version by default.

36:25 And that's where it reads it by default.

36:28 It gives you, oh yeah, go ahead.

36:30 Well, I was just going to say, one of the things I can type now is Hatch version.

36:33 And it gives me, basically pulls out the version of About.py, right?

36:38 Yeah, and you can, if you do the same command again, but pass in R like minor,

36:44 then you can bump it as well.

36:46 Yeah, so the old version is what it says, is 001.

36:49 The new version is 010.

36:51 Could I say build and get 11?

36:53 Something like that?

36:54 No, what would I type to change the last one?

36:56 RC.

36:56 You should do RC.

36:57 Okay.

36:58 It's documented the allowed arguments as well.

37:01 Got it, yeah, sure.

37:01 So yeah, then it also gives you a test directory that doesn't have any predefined tests,

37:07 but you can add tests to it.

37:09 And then the most important part is the PyProject.tomla, which has your metadata and your other config.

37:17 So it's got the build system set to be Hatchling.

37:20 And then it's got all the project settings, like who is the author?

37:23 What are the requirements?

37:25 And all that stuff, right?

37:26 And from the author, it would have gotten that from Git.

37:29 The default comes from Git.

37:31 So that's why it has the right stuff for you.

37:33 And then down here is testing.

37:36 So some coverage stuff and environments.

37:40 When I typed Hatchinew, could I have made it ask me those questions, like who are you and stuff?

37:44 There is an interactive mode, yeah.

37:46 Okay, yeah.

37:47 Yeah, so you also, as part of this PyProject.tomla, you create some of these commands.

37:54 These are the scripts you were talking about a little bit, right?

37:56 Like you've got the test and other options you can run.

37:59 This default example down there has environment, which is just default, which is a little bit special.

38:06 It just means you don't have to add a prefix on the command line.

38:09 And so there's two scripts by default.

38:11 A cove.

38:13 So you could do like a hatch run cove, and it would run pytest with coverage.

38:18 And then another command is no cove.

38:21 Yeah.

38:21 And I can do hatch test, hatch run test.

38:24 Is that a thing as well?

38:25 There is no test command.

38:26 You could do pytest.

38:28 So if you do hatch run pytest, it could, yeah.

38:31 Yeah, excellent.

38:32 That's really cool.

38:32 Yeah, so it basically creates the structure for you.

38:36 And the workflow that we just discussed would be if I've got a folder and I want to start from absolute scratch.

38:43 I want to create the entire directory structure through hatch.

38:48 But there's also a way I can go to an existing one and kind of convert it to hatch or upgrade it to hatch, right?

38:55 Me and other contributors have done it so much that most of the edge cases are gone.

39:01 So it can take pretty much any setup.py and turn it into hatch pyproject.tomalot.

39:09 It's pretty good now.

39:11 Okay.

39:11 And because it doesn't actually need hatch the CLI, the environment tool to do that, to run and build,

39:20 you could just use that to get your pyproject.tomalot and use hatchling as a build engine, right?

39:27 But still just keep going.

39:28 Yeah, exactly.

39:29 Okay.

39:29 So people are sitting out there like, I really should be using pyproject.tomal, but, you know, inertia, I don't really want to do it.

39:36 Like, hatch new init might do it, right?

39:39 Yeah, yeah.

39:40 That's an option.

39:41 Before you time out, if you do which Python, maybe I can just illustrate.

39:46 And if you do hatch run which Python 3, it will show you that it's actually in a managed virtual environment.

39:53 Okay.

39:55 So it's created a virtual environment over in, at least for me, library application support, hatch environments, and so on, so on, based on the project name.

40:03 And then it has some big long deal on the end?

40:05 It's just a hat, yeah.

40:06 It's just a checksum.

40:08 Okay.

40:08 What is that a checksum based on?

40:10 The reason I ask is, what do I change to make this no longer work?

40:16 So I do that because it's possible that somewhere else on your machine, you might have another project, maybe a fork of calci with the same name.

40:25 So I have to have a hash.

40:26 Likely.

40:26 It's a very popular library, so it's likely.

40:29 That's why I do that, yeah.

40:31 I see.

40:31 Okay.

40:31 That's like a hash of the path to where the project is or something.

40:35 Okay.

40:35 Yep.

40:35 A lot of projects, a lot of management tools work this way.

40:38 Conda works this way, for example, where there's some other place where the virtual environments live.

40:44 Is there a way, another workflow that's pretty common is to have the virtual environment in a VNV folder at the root of the project.

40:51 Is there a way when I create my project to say, I want a local ENV?

40:56 Not at project creation time, but there is a way in either hatch config or in pyproject.tomo.

41:04 They're able to change that.

41:05 Yeah.

41:06 Which is documented on the site.

41:08 Yeah.

41:08 The hatch config is one of the things I would do.

41:13 There's a lot of cool CLI tools where you can ask it to show me the details of whatever it is.

41:18 So what would I put, say, into the config to say, create my VNV locally and call it what?

41:27 Is it this DERS VNV?

41:28 Yeah, DERS and ENV.

41:30 Yeah.

41:30 What would I put in there?

41:32 You would have a subtable for virtual and then have the path be just .vend, basically.

41:40 Right.

41:40 Okay.

41:41 So like a .slash, whatever you want to call it locally.

41:43 Yeah.

41:44 Is this, I guess I could do hatch find config or config find, I guess?

41:50 Config find.

41:51 Config find.

41:51 Yeah.

41:52 Right.

41:52 And that will, so this is a global, like, how do my projects get started using hatch for my machine, not a per project deal, right?

42:00 Yeah.

42:00 That's cool.

42:01 So kind of like git config.

42:03 Once I set up my machine, if I say, well, I like my virtual environments like this, then I'll be okay.

42:09 Right?

42:09 Yeah.

42:10 It makes it easier to distribute tooling.

42:12 Like for, if you're managing like some corporate environment where you're using hatch for everything, then it's nice to have a config that you can modify.

42:22 Just as a machine level, then every project will do the same.

42:27 Just as a team to say, look, we always want tests.

42:30 We always want this other thing that we call it that we always want this default library.

42:34 Sorry.

42:35 We want this default license, right?

42:37 We don't want MIT.

42:39 We want, you know, corp.inc or whatever license that we use.

42:43 So quick question from ZL out there that I think is relevant.

42:46 Is this useful for application development, not libraries?

42:50 Say if I'm building like a Flask app or a FastAPI app, like would, would this be relevant?

42:55 Yeah.

42:55 So especially with the environment management, that's kind of what applications will use anyway.

43:00 The missing feature, of course, like the other person asked is the lock files.

43:06 For any app you're going to want to be able to reproducibly build the app.

43:11 So right now there's not a way built in other than using an environment with like pip-tools or something.

43:18 So I'm going to add that plugin interface soon.

43:21 Interesting.

43:22 Does pip-tools work with piproject.toml?

43:24 It does now.

43:24 Yeah, it does.

43:25 Yeah.

43:26 I've only used it with requirements.in and then generate the requirements.txt of it.

43:30 Yeah.

43:31 They added that last summer, I think.

43:33 I'm so behind the times on this.

43:34 You know, these workflows, I'm sort of joking, but also not.

43:38 These workflows, you kind of get into like, well, here's how I build these apps.

43:41 Here's how I manage my requirements.

43:43 And then you just tunnel, I think a lot of people just go, okay, well, that's working

43:47 for me.

43:47 I'm doing that.

43:48 You know?

43:48 Yeah, me too.

43:49 Me too.

43:49 Yeah.

43:50 Yeah.

43:50 Yeah.

43:50 And then, so if I want to, like, so for example, when I asked which Python, it said the one from

43:58 Homebrew you've installed, silly.

43:59 Of course, that's your global Python.

44:01 If I want to activate a virtual environment, if I want to get into like this application

44:06 mode, I would do hatch shell, right?

44:09 Yes.

44:09 Uh-huh.

44:10 And because I have an awesome, oh my posh, you can see my prompt here's now taking on

44:14 the calci 3.11.2 environment as part of my prompt.

44:18 So.

44:18 That's very cool.

44:19 Yeah.

44:19 That's the one.

44:20 So it's working.

44:21 Now, if I ask just straight up, which Python is that virtual environment one, right?

44:25 Yeah.

44:26 And I can do pip list and so on, but there's also ways, I think I recall, in hatch to like

44:32 show me my dependencies and get a list of.

44:34 Yeah.

44:34 Hatch, dep, show.

44:36 Dep, show.

44:37 Yeah.

44:37 Is it show dep?

44:38 Table.

44:38 Ah, table.

44:39 It's just a few options.

44:40 Yeah.

44:40 Okay.

44:41 That's your environment.

44:42 I only have right now two dependencies, pytest and pytest cov.

44:45 Yeah.

44:46 Interesting.

44:46 Or I could do requirements.

44:49 Yep.

44:49 And I would split out the.

44:50 The same, but it's not as a table, right?

44:52 Just plain text.

44:53 Yeah.

44:53 Just like requirements.txt.

44:54 Got it.

44:55 Okay.

44:56 Yeah.

44:56 Excellent.

44:57 What do you recommend?

44:58 So there's the hatch run commands, which we'll use the environment, or you can just go into

45:02 the shell and run it.

45:03 Or if I'm sneaky and I put my virtual environment in there, I might have something that automatically

45:11 detects that environment and picks it up.

45:13 So for example, PyCharm might go, you know what?

45:16 I see a VE and V folder.

45:17 We'll use that and, and just grab it and not care about hatch directly.

45:22 Right.

45:23 That's actually one of the reasons I was asking about putting it locally is it's kind

45:27 of a hassle to find that thing and tell your editor, go find it over here.

45:31 Whereas it automatically finds the top level of project variant, you know?

45:37 Yeah.

45:37 So you can do, as we talked about, sitting in the current directory, like a .vnv.

45:43 And yeah, PyCharm VS Code, they'll pick it up because it is just a virtual environment at

45:49 the end of the day.

45:50 Nothing too special.

45:51 So yeah, it will work out of the box.

45:54 Yeah.

45:54 And Colette's out there in the audience has got us covered.

45:56 pip-tools command is pip tool, pip compile, rebuild, output file, such and such, pyproject.txt

46:02 from pyproject.toml.

46:04 Yeah.

46:05 Cool.

46:05 Nice.

46:06 Yeah.

46:06 And variations on that, I suspect.

46:08 So one thing that I was thinking about this that I expected hatch to do, and maybe it does

46:14 and maybe it doesn't, I just don't know, is suppose I want to use requests for calci.

46:19 Like calci can't run locally.

46:21 It needs its calculator API service that it's going to connect to.

46:25 So it needs a request or HTTPX or something.

46:27 Yeah.

46:28 Is there a way with hatch to say, I have a new requirement, set that up, put it in the pyproject.toml, install it.

46:33 That's going to come with the lock file plugin.

46:36 I figured it wouldn't make sense to add those commands until I knew how locking would work.

46:43 Because adding and removing always hits the locking logic.

46:48 And since there wasn't locking, it didn't make sense to me to add those commands.

46:53 All right.

46:54 Yeah.

46:54 That makes sense.

46:54 It's going to come soon.

46:55 So right now, you would just modify your pyproject.toml until those are added.

47:00 And then I think there's a way where hatch looked at your pyproject.toml and said, okay, you're

47:05 going to need these dependencies, right, when you run it.

47:09 In what sense?

47:10 I thought it installed the dependencies that were in the pyproject.toml.

47:13 Even if it won't edit it, like if I put something in there and I try to run it, it'll say, oh,

47:17 you need this.

47:18 Yeah.

47:18 It'll sync automatically.

47:19 What command do I use to do that one?

47:21 Either a run command or the shell command.

47:25 I see.

47:25 Oh, even the shell will do it, huh?

47:27 Do you hatch run pip list, for example?

47:30 Yeah.

47:30 Okay.

47:30 Now in pyproject.toml, add requests maybe to.

47:35 Yeah.

47:36 All right.

47:36 Now I have requests and friends of requests.

47:38 Yeah.

47:39 Yeah.

47:39 Yeah.

47:39 Okay.

47:40 That's pretty cool.

47:41 Nice.

47:42 And then I'm looking forward to the lock stuff because I absolutely love pip-tools.

47:46 I think it is a glorious way.

47:49 I used, for a while, I used PendaBot at GitHub and it drives me crazy.

47:54 It's like so noisy.

47:55 I'll get like 30 PRs a week.

47:58 I'm like, you know, could you just package this up?

48:01 And so now I just start periodically.

48:04 I just go, okay, I'm going to use pip-tools and just ask like, how has the world changed?

48:07 And then update my stuff in a more sane way.

48:10 It was a bit noisy for us too at work.

48:12 So we had like a custom dependency update logic as well.

48:17 I think there is an open page request for a dependent bot to chunk the updates, but I

48:22 don't know if it has happened yet.

48:24 Yeah.

48:24 I think I've seen one of those for a couple of years and there was like a hundred plus

48:28 one.

48:28 Me too.

48:28 Me too.

48:29 Like I got to review these things.

48:31 You know what I mean?

48:32 And I don't know if it's there.

48:34 It's not there on my projects.

48:35 It's still.

48:36 Yeah.

48:36 I'll get 20.

48:37 I'll do a pip compile update and I'll push that and I'll get like 20 messages.

48:42 These are no longer required.

48:43 I'm like, okay, thanks.

48:44 Could you just batch them?

48:47 Yeah.

48:47 Anyway.

48:47 Yeah.

48:48 Okay.

48:48 So calci is coming along here.

48:50 Let's just imagine that it does good stuff.

48:51 I haven't even written any code for it, but it depends upon requests.

48:55 So that's a start.

48:55 The next step going kind of forking on the various possible definitions of what packaging

49:01 is.

49:01 A next step for this thing might be, I want to put it onto PyPI or create a wheel I can share.

49:06 So hatch also supports that, right?

49:08 Yeah.

49:08 So first you have to create the artifacts.

49:12 So you would do hatch build and that would build Metafault, both the source distribution

49:17 and the wheel.

49:19 Okay.

49:19 Now in your current directory, just like the other tools, there's going to be a dist,

49:24 D-I-S-T that now has those.

49:27 And if you run a hatch publish, that would put it on PyPI by default.

49:33 And it would prompt you for your username.

49:37 I'm not entering that.

49:38 I don't want to own calci on PyPI.

49:41 No, just kidding.

49:41 But yeah, I don't think I have it configured, so it wouldn't really do anything.

49:44 But it would.

49:45 It would go and put it on PyPI, right?

49:47 Yeah.

49:47 Potentially.

49:48 Yeah.

49:48 That's pretty straightforward.

49:49 You also point out in the docs that CI build wheel and things like TOX, you could be

49:58 the build, just hatchling could be the build system for that, right?

50:01 Hatch does a lot.

50:02 So you can use parts.

50:04 Say you wanted to only use environment management to replace like TOX and NOX, you could do that.

50:11 If you wanted to only use hatchling with like CI build wheel or other tools, you could do

50:17 that.

50:17 If you wanted to only use the version management, you could do that.

50:21 It's kind of choose whatever you want.

50:24 Yeah.

50:24 You're not locked in.

50:25 Yeah.

50:26 So the last thing I could do is publish, but I'm not really going to go.

50:29 Yeah.

50:30 There's also a way to set in the config file.

50:33 You said that if I set into the config file under the publish index, disable true, where

50:39 you can make it confirm rather than just straight up publishing it, right?

50:42 Yeah.

50:43 That was a feature request.

50:44 Yep.

50:45 So yeah, cool.

50:45 Another thing that is always, I've always stumbled on when I do this, at least with Twine is I'll

50:53 have some project.

50:54 I've done this.

50:55 I published a version later.

50:56 I'll come back to it.

50:57 I'll make some changes.

50:58 I'll increment the version.

50:59 I used to have to do that manually, but now I can just do a hatch version and then something

51:05 like, I could build one again.

51:07 Minor.

51:08 There you go.

51:09 There we go.

51:10 It'll automatically change it.

51:12 And that changes the code, which is great.

51:13 So now if I do a hatch build, which is really nice, it'll create a new one.

51:18 But if I look in my project, I've got the old one and the new one.

51:22 And you can't republish the old one, I don't think.

51:24 So what happens if I just say publish now and I've already got 0.1.0 out there?

51:29 Yeah.

51:29 So you can do hatch build dash C for a clean and it should clean it first.

51:35 Okay.

51:36 That's cool.

51:36 Because then I can just say hatch publish and not worry about conflicts.

51:40 Anything that exists already on PyPI, it will ignore us.

51:44 It'll put a warning, but it won't fail the command.

51:47 I think Twine by default does fail.

51:50 I think it does as well.

51:52 So I do the inverse because that was frustrating to me too.

51:55 So I do the opposite.

51:57 Yeah.

51:58 Perfect.

51:59 I love it.

51:59 Okay.

52:00 Yeah.

52:01 That's a really cool aspect.

52:02 And so, yeah, that was, I guess, walking through that.

52:07 I think it was neat to just kind of explore it together.

52:09 So thanks for talking me through that.

52:11 Yeah.

52:12 The past month I've been pretty busy at work, but I'm going to pick up development again next

52:17 week for hatch.

52:18 There's a bunch of open feature requests.

52:21 I have to crank out.

52:23 Yeah.

52:23 This is a pretty popular project on GitHub with 3.7,000 stars.

52:27 So I suspect there's some user feedback.

52:29 Yeah.

52:30 And so it's the main next features are the lock file plugin mechanism.

52:37 And also people are asking about workspaces, which is basically like kind of like editable

52:44 and stuff, but more built in and fundamental.

52:47 So I'm going to add that especially useful for monorepos.

52:51 Oh, right.

52:52 Okay.

52:53 Because you don't necessarily want to hatch build all of Google or whatever, right?

52:58 Right.

52:59 Right, right.

53:01 So a workspace is like a view into the monorepo that I said, I know there's like 500 projects

53:06 here and they all have their things, but I want the web app and the data layer.

53:11 That's it.

53:12 Something like that.

53:13 Right.

53:13 Exactly.

53:14 Yeah.

53:14 Okay.

53:14 That sounds useful.

53:16 Yeah.

53:16 And I'm modeling it after cargo workspaces in Rust.

53:20 I worked with that recently and I think they have pretty good config and like a model of

53:26 how local development works.

53:28 Okay.

53:29 Yeah.

53:29 That sounds really great.

53:30 Yeah.

53:30 I do my preview of what hatch will look like at basically cargo workspaces.

53:35 Nice.

53:37 Jonathan out there says, that sounds like music to his ears.

53:41 Definitely waiting on the workspaces feature for our monorepo work.

53:44 Nice.

53:45 And then also Ryan is asking you, any chance there could be a package build target?

53:50 I'm using PECs via TOCs currently.

53:54 Yes, that's possible.

53:55 One thing that's great about plugins is I don't have to do every feature.

54:00 Anybody can do that.

54:02 So we do have, if you go to the docs and go to the top, plugins.

54:07 Plugins, where are you?

54:08 You're home.

54:09 Yeah.

54:09 Plugins.

54:10 Builder.

54:11 Builder.

54:11 Yeah.

54:11 And then reference.

54:12 Yep.

54:13 And then, yeah.

54:14 So known third party.

54:15 So here's some examples of third party builder plugins.

54:19 So the build command that you ran, it has an option to output a target.

54:25 Okay.

54:26 Named target.

54:26 Other than wheel and sdst.

54:29 So you can write an arbitrary builder and build those targets.

54:34 So yeah.

54:34 Okay.

54:35 It's probably not super hard to do, I'm guessing, to just like basically bundle up the commands

54:40 to build the PECs.

54:41 Yeah.

54:41 And just implement the interface and that's all I gotta do.

54:44 Yeah.

54:44 Excellent.

54:44 Good to hear.

54:45 I vote for the lock file management, the dependency management.

54:50 I'm excited to hear that that's coming.

54:52 Yep.

54:53 That's coming next.

54:53 Are you thinking of building on something like pip-tools or doing your own?

54:58 I wouldn't feel confident doing my own without feedback from like other folks that have been in this for longer.

55:06 Like Brett Cannon.

55:08 I think he wrote the first lock file PEP attempt last year.

55:12 For various reasons, it kind of got rejected.

55:15 But I think his next attempt will happen.

55:18 I just don't know when.

55:19 Excellent.

55:20 There's also a suggestion, a Cython builder would be cool.

55:23 Maybe a mypyc.

55:25 I don't know.

55:26 There's a lot of options.

55:26 That one exists actually.

55:27 Oh, the mypyc one does?

55:29 Okay.

55:29 I do remember seeing.

55:30 Yeah.

55:30 If you go back to the plugins.

55:32 I know the docs are a lot.

55:34 Sorry.

55:34 Back one.

55:35 Build hook.

55:36 Okay.

55:37 And then reference.

55:38 And it's listed under a third party.

55:40 Hatch mypyc.

55:41 I maintain that one actually.

55:43 Okay.

55:43 Nice.

55:44 Actually, Black builds with that now.

55:47 Nice.

55:47 What about the Jupyter builder?

55:50 What does that do?

55:51 So recently, Jupyter switched their entire extension ecosystem to Hatchlang actually.

55:59 So now the standard way to do Jupyter stuff is with Hatchlang.

56:04 And that's the plugin that everything happens with.

56:07 Nice.

56:07 Okay.

56:07 Cool.

56:08 Probably makes you feel good to see major projects like that using your tools.

56:12 I'm happy with people who are finding a value in it.

56:15 And every time someone says, oh, it's so easy to use, it makes me happy.

56:20 Yeah.

56:21 Indeed.

56:21 I like stuff that I can do a lot, but it's very simple.

56:24 That's my purpose.

56:26 Yeah.

56:26 I think I might play with the config, the global config, to see how close I can make it match

56:31 my current workflow and make it kind of coexist what I'm doing.

56:34 So that'd be fun.

56:35 Awesome.

56:36 All right.

56:37 Well, I think we're about out of time.

56:40 Anything else you want to throw out there while we're talking about your project?

56:43 If anybody wants to contribute, there's lots of open issues.

56:48 I have had lots of really nice contributors.

56:51 They almost finished adding type hinting everywhere.

56:56 In the beginning, I had zero type hinting.

56:58 And then a bunch of contributors helped out with that.

57:01 And that was almost fully my pie.

57:03 So.

57:04 Cool.

57:05 Yeah.

57:05 I saw you had 40 contributors.

57:07 So that's really cool.

57:07 Yeah.

57:08 Maybe one other quick comment that I'd like to ask you about here is I see the domain this

57:14 is on is hatch.pypa as in Python Packaging Authority dot IO.

57:18 Mm-hmm.

57:19 How'd it end up on pypa dot IO versus, you know, hatch dot dev or whatever?

57:25 This is just the standard domain for all the packages.

57:28 So if you type in pip rather than hatch and get rid of the latest part, it'll go right

57:35 to the pip docs.

57:35 Right, right, right.

57:36 Well, I was thinking more about like how did it become sort of official?

57:40 I announced hatch 1.0, like the rewrite that happened last year sometime.

57:46 And then the same day, maybe the next day, I forget who, but somebody in the discord was

57:52 asking if I wanted to join the pipa.

57:55 And I was like, well, sure, that makes sense.

57:58 So then there was a vote on the mailing list and it was unanimous that they agreed.

58:03 And then after I think seven or 10 days, then we transferred the repo and it was hosted

58:10 on the new domain.

58:12 Oh, yeah.

58:12 And it's also under the GitHub organization of pypa.

58:14 That's right.

58:15 Yeah.

58:15 Excellent.

58:16 All right.

58:17 Well, really nice project.

58:18 Congrats on all the uptake and.

58:21 Thanks.

58:21 Yeah.

58:22 It looks like people are enjoying it.

58:23 So two quick questions before you get out of here.

58:26 I didn't get to ask you this on the panel one because one, we were over time and two,

58:30 there was a bunch of people in order just another 10 minute debate.

58:33 Yeah.

58:33 First of all, notable pypi package, something that you've come across.

58:36 Oh, this is super cool.

58:37 People should know about package X.

58:39 Anything come to mind?

58:40 I guess it's a bit cliche because right now it's actually pretty popular, but I would

58:45 still evangelize textual.

58:47 Textual is like a new application for booting T-UIs, which is like textual user interfaces.

58:56 I've actually been doing a project at work that uses this and it's very nice.

59:02 It's pretty awesome.

59:03 It's kind of nuts what this thing does.

59:05 Yeah.

59:06 This is like the higher order UI framework built on Rich by Wilma Guggen and team.

59:11 You get like fly out docking panels and scrolling within.

59:17 It's crazy.

59:17 Yeah.

59:17 It's kind of like if the web could be in a terminal.

59:21 Something like that.

59:23 It's true.

59:24 I plan to actually use this for a hatch when I have time.

59:27 On the interactive creation of a new project, on the left-hand side, you would have inputs,

59:36 and then it would render the pyproject.tama on the right-hand side and markdown.

59:41 Oh, that's super cool.

59:41 In a few months.

59:42 Yeah.

59:43 Fun.

59:43 And then if you're going to work on hatch, what editor are you using these days?

59:48 I price time for large projects.

59:51 When I'm doing like one-off scripts, then VS Code.

59:55 Mm-hmm.

59:56 Okay.

59:56 Cool.

59:57 All right.

59:57 This may be a question I got to start asking people.

59:59 I don't know.

01:00:00 PyCharm and all the JetBrains IDs, I believe, are starting to promote what they call the new UI,

01:00:07 which I think is much more like VS Code.

01:00:10 Are you the old school style or are you the new UI style?

01:00:15 I've not seen that yet, actually.

01:00:17 There's a gear in the upper right.

01:00:18 If you click on it, it'll say new UI.

01:00:20 To me, I'm old school.

01:00:21 I love the old one.

01:00:22 I mean, I'm using PyCharm, not VS Code for a reason.

01:00:25 So I don't want it to look more like VS Code for my style, right?

01:00:29 But I know other people prefer the opposite.

01:00:30 I wouldn't mind using VS Code.

01:00:32 There's one missing feature that is like a blocker where I just won't use VS Code full time,

01:00:38 which is it can't yet do vertical tabs.

01:00:41 There's an open feature for years.

01:00:44 And I guess technically, there's some kind of challenge to implementing that.

01:00:49 So right now, if you have like 100 tabs, it doesn't look very nice.

01:00:53 It's all horizontal.

01:00:54 It's just a bunch of Xs.

01:00:55 Yeah.

01:00:57 I can't select them.

01:00:58 I just close them.

01:00:59 Yeah.

01:00:59 Yeah, I got it.

01:01:00 Okay.

01:01:00 Very cool.

01:01:01 All right.

01:01:02 Well, congrats with Hatch.

01:01:04 And thanks for coming on the show.

01:01:06 Yeah, thank you very much.

01:01:07 Nice talking to you.

01:01:08 Yeah, you too.

01:01:09 Bye-bye.

01:01:09 All right.

01:01:09 Bye-bye.

01:01:11 This has been another episode of Talk Python to Me.

01:01:14 Thank you to our sponsors.

01:01:16 Be sure to check out what they're offering.

01:01:17 It really helps support the show.

01:01:19 Don't miss out on the opportunity to level up your startup game with Microsoft for Startups

01:01:23 Founders Hub.

01:01:23 Get over six figures in benefits, including Azure credits and access to OpenAI's APIs.

01:01:28 Apply now at talkpython.fm/founders hub.

01:01:31 Take some stress out of your life.

01:01:34 Get notified immediately about errors and performance issues in your web or mobile applications with

01:01:39 Sentry.

01:01:40 Just visit talkpython.fm/sentry and get started for free.

01:01:44 And be sure to use the promo code talkpython, all one word.

01:01:48 Want to level up your Python?

01:01:49 We have one of the largest catalogs of Python video courses over at Talk Python.

01:01:54 Our content ranges from true beginners to deeply advanced topics like memory and async.

01:01:59 And best of all, there's not a subscription in sight.

01:02:01 Check it out for yourself at training.talkpython.fm.

01:02:04 Be sure to subscribe to the show, open your favorite podcast app, and search for Python.

01:02:09 We should be right at the top.

01:02:10 You can also find the iTunes feed at /itunes, the Google Play feed at /play,

01:02:15 and the direct RSS feed at /rss on talkpython.fm.

01:02:20 We're live streaming most of our recordings these days.

01:02:23 If you want to be part of the show and have your comments featured on the air, be sure to

01:02:27 subscribe to our YouTube channel at talkpython.fm/youtube.

01:02:31 This is your host, Michael Kennedy.

01:02:33 Thanks so much for listening.

01:02:34 I really appreciate it.

01:02:35 Now get out there and write some Python code.

01:02:37 We'll see you next time.

Talk Python's Mastodon Michael Kennedy's Mastodon