Latest / Talk Python To Me / #314: Ask us about modern Python projects and tools
Transcript
- 0:00Here's an episode that I did not see coming.
- 0:02Sebastian Wibowski and I put together a live stream, Ask Me Anything, as a follow-up to
- 0:06some of his ideas around his recent course, Modern Python Projects.
- 0:09We dove deep into comparisons of poetry versus pip versus pyenv and answered questions like,
- 0:15do I need to use Docker?
- 0:17And when should I?
- 0:17And so on.
- 0:18After the AMA was over, I realized it would make a great podcast too.
- 0:22So here you go.
- 0:23This is our AMA with Sebastian, all around the ideas of modern Python workflows.
- 0:28I hope you enjoy it.
- 0:29This is Talk Python To Me, episode 314, recorded April 19th, 2021.
- 0:35Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the
- 0:53ecosystem, and the personalities.
- 0:54This is your host, Michael Kennedy.
- 0:56Follow me on Twitter where I'm @mkennedy.
- 0:58And keep up with the show and listen to past episodes at talkpython.fm.
- 1:02And follow the show on Twitter via at talkpython.
- 1:05This episode is brought to you by 45 Drives and us over at Talk Python Training.
- 1:10Please check out what we're offering during those segments.
- 1:12It really helps support the show.
- 1:13Everyone out there, thank you so much for being here today.
- 1:18It's exciting to have you here in the live stream, or if you're watching later, watching
- 1:22the record.
- 1:23So Sebastian, welcome.
- 1:25It's great to have you part of this Ask Me Anything.
- 1:28In fact, it's your Ask Me Anything, really.
- 1:30Thank you.
- 1:30Yeah, I'm excited to be here.
- 1:31Yeah, of course, I'll give my thoughts as well.
- 1:34But you've done a lot of thinking about tooling and putting the right tools together and what
- 1:39maybe constitutes what you might call a modern Python project or the tool chain of a modern
- 1:45Python developer.
- 1:46And there's a couple of things that we've already done together that are maybe worth
- 1:50calling out that we'll build on here today.
- 1:53So a while ago, I guess, what was this?
- 1:55Oh my gosh, this was back last year, August 29th, 2020.
- 1:59You were on Talk Python.
- 2:01You came on and talked about the modern Python developers toolkit.
- 2:04And then we talked a little bit after that and said, you know, it would be really cool actually
- 2:07to put a course like this together for people.
- 2:09So over at Talk Python training, you created the Modern Python Projects course.
- 2:13This is almost a nine hour course that takes a lot of the ideas you mentioned there previously
- 2:18on the podcast and makes them concrete, makes it something that actually people can employ
- 2:24and use.
- 2:25And so, yeah, those are some of the things that we've done together before.
- 2:29But we're just going to take a broader view and talk about what this whole idea of modern
- 2:35Python projects might be.
- 2:36Yeah.
- 2:37So let's just kick it off with a quick high level overview.
- 2:41Like, what are your thoughts?
- 2:42What constitutes modern Python development?
- 2:45How has it changed over time?
- 2:47Things like that.
- 2:47Then we'll get to the people's individual questions.
- 2:49Yeah.
- 2:50So as you mentioned, this whole idea started as PyCon workshop where I wanted to share with
- 2:55people some ideas for tools that I've been using.
- 2:59And I know that a lot of other people have been using because I sometimes see people like
- 3:04start programming in Python and they still stick to using the default Python shell.
- 3:09And they don't know about many great tools that are in the ecosystem.
- 3:13You'll hear like, oh, I used idle to try to run this.
- 3:16And you're like, whoa, whoa, whoa, please don't use idle.
- 3:18I mean, it's built in, but there's really more helpful options these days, right?
- 3:21Something like this.
- 3:22Yeah.
- 3:23I mean, Python is really cool with the batteries included because you have a lot of things
- 3:27there.
- 3:27But at the same time, there are a lot of other different tools and projects that can make
- 3:32your life much, much easier.
- 3:33And that's what I wanted to share with people.
- 3:36Nice.
- 3:36And I would like to point out for people who maybe don't know, there's a lot of amazing
- 3:41tools that are not part of Python on purpose.
- 3:44And the reason they're not part of Python is not that they're amazing.
- 3:47It's that Python releases, it used to be every 18 months and now every 12 months.
- 3:52And once something goes into Python, it can't be taken out almost ever.
- 3:55So it's very hard to move fast and break things type of mentality with Python itself and the
- 4:02standard library and so on.
- 4:04But stuff outside of it can be much more rapid.
- 4:07For example, there was a conversation with the core devs around making requests, the package
- 4:12part of Python as a better way to do it because it's vastly a better way to do it than the built
- 4:17in HTTP libraries.
- 4:18They decided not to put requests into Python itself because they said it would actually
- 4:24slow down and hamper requests and make it less valuable.
- 4:27And it's better to leave it as its own standalone thing.
- 4:30And I think that touches on a lot of what you're talking about, Sebastian, is that there's what's
- 4:36built into Python and a lot of it is really good.
- 4:38But oftentimes there's better things outside and they're not likely to be moved into Python
- 4:43for their own good.
- 4:44Yeah, exactly.
- 4:45And since installing new packages or tools in Python is just one peep command away, it's
- 4:50very easy to add new tools, experiment with them.
- 4:53But at the same time, it's worth knowing which tools are kind of like the backed up by the
- 5:00Python community, like which one are the most popular.
- 5:02Right.
- 5:03What are the de facto primary ways?
- 5:05Like pytest, for example, would be in a case there.
- 5:07Yeah.
- 5:07Exactly.
- 5:08Okay.
- 5:09Yeah.
- 5:09For example, I wanted to mention Cookie Cutter because if you're looking for a way to start
- 5:14a new project, then you're wondering, no matter if it's like a Django website or if it's like
- 5:19a Python module, a lot of people know about Cookie Cutter templates.
- 5:22And they are a great way to start because you use a template that many people use before you.
- 5:27It has a lot of same defaults already set up for you.
- 5:30But if you never heard about Cookie Cutter templates, there is like no way you're gonna
- 5:35randomly find it because like Cookie Cutter doesn't even have Python in its name.
- 5:40So unless you know there is a tool for that, there is like no way for you to find it.
- 5:43Right.
- 5:43Exactly.
- 5:44But it's so super helpful.
- 5:45Okay.
- 5:46Fantastic.
- 5:46Well, we have a bunch of questions from the Ask Us Anything or Ask You Anything that we've
- 5:52already gotten because we sent out an email and said, hey, send us your questions.
- 5:55We're also, Norbert has a question here in the live chat.
- 5:59Which would you like to go with first?
- 6:01You want to do the live chat question?
- 6:02You want to pick some out of our previous ones?
- 6:05So we make sure we get to them since they asked first.
- 6:07What are your thoughts?
- 6:07So maybe go with the one that we got beforehand because there are some interesting questions
- 6:12that we picked up and I think they will be useful to more people.
- 6:15And then we will do the live chat.
- 6:16Yeah.
- 6:17All right.
- 6:17That sounds great.
- 6:18So folks out there, please keep putting your questions and follow up questions to what we're
- 6:22about to talk about in the live chat and we'll get to them.
- 6:24All right.
- 6:25So the first one is what's the point of setting up something like pyenv using VENV and so on
- 6:31when you can just use Docker?
- 6:33Yeah.
- 6:34So maybe a little bit of background just for people who are like not really sure what these,
- 6:38all these things are and then the trade-offs.
- 6:40Exactly.
- 6:41So pyenv is a tool that you can use to manage different Python versions on your computer.
- 6:46So for example, if you want to have Python 3.6, 3.7, 3.8, 3.9 install at the same time
- 6:52and easily switch between them, you can use that.
- 6:55And then VENV is a tool used to create virtual environments.
- 6:58So it's a way to isolate the dependencies of your project.
- 7:03So basically you would use pyenv and VENV to isolate Python and Python packages.
- 7:08Right.
- 7:09So pyenv is getting the version you want and then VENV is isolating that for a particular project, right?
- 7:15Exactly.
- 7:15Okay.
- 7:16They work together.
- 7:17And then the same thing could be solved with Docker where you have like Docker image that you use to spin Docker containers
- 7:24and everything is isolated inside of it.
- 7:27So you have a specific Python version that you choose based on which Docker image you use.
- 7:33And then inside this Docker container, you install pip packages and they are isolated from both your computer
- 7:39and other Docker images, Docker containers.
- 7:42And so coming back to the question, I actually use both.
- 7:45I use Docker in a lot of my projects and it's very convenient.
- 7:51And especially if you want to later deploy your project or share it with your colleagues.
- 7:57But at the same time, I don't want to spin up a Docker image if I just want to run a Python script.
- 8:03So I still use pyenv to manage Python versions on my computer.
- 8:07So I can use pyenv to install, to change the global version of Python on my computer.
- 8:14And I saw that it's already useful for me because sometimes when I'm installing packages with Homebrew,
- 8:20by the way, I'm using Mac.
- 8:22So Homebrew is the package manager for Mac.
- 8:24Yeah, I use Homebrew as well.
- 8:25And I think that's also part of the modern pool chain is that you have something that updates your tools.
- 8:30Yeah, exactly.
- 8:31Automatically.
- 8:32And then each time it's installing something, I see that it's trying to install some Python version in the background.
- 8:39And at the beginning, I was worried because it was messing up the global Python versions.
- 8:44But with pyenv, I have Python versions separated from my system.
- 8:49So whatever Homebrew is messing up there, I don't really care.
- 8:52I have pyenv that lives in a separate folder and it modifies the system path variables.
- 8:58So these separate folders are being read before the system Python.
- 9:02And that works in front of the Homebrew.
- 9:07So I don't really care what the system Python on my computer.
- 9:10By the way, Mac is still using 2.7.
- 9:14I don't care what Homebrew is installing.
- 9:16I have pyenv and that works really flawless.
- 9:19But Docker is also really great because if you want to start a project using a different Python version, you just change one variable in the Docker file and that's it.
- 9:29Yeah.
- 9:29So there are many benefits to using that.
- 9:31I think Docker is really useful and I do use it some of the time.
- 9:35But it's not the first tool that I reach for because a lot of times I don't need that complexity.
- 9:42You know, if I'm going to say fire up something like, oh, I need Redis just like this and I need Celery like that and I need MongoDB like set up like that.
- 9:50And then I want to just make that whole package work together.
- 9:53And I really would like it to be exactly on Ubuntu, which is the way I run things in production.
- 9:57Then I would definitely reach for Docker.
- 9:59But if I just want to just develop one of my web apps or some API I'm working on, chances are running it locally is totally good.
- 10:07And it's just fewer things in the mix to worry about.
- 10:10So to me, a virtual environment seems totally good for that.
- 10:13To me, it's easy to see what everyone is super excited about and then go, oh, I have to do that as well.
- 10:18And like that makes sense when there's enough complexity or you're in the same sort of situation that they're also excited about.
- 10:24But it doesn't mean it applies everywhere.
- 10:26Like if I just wanted to do basic Jupyter work on something that I could run on my machine, I wouldn't necessarily fire up Docker to make that happen.
- 10:32Yeah, exactly.
- 10:33I want to also point out that this question is specific about using Docker to replace Pi and virtual environments.
- 10:40And it's not about using Docker in general.
- 10:42I think we have another question coming up later about using Docker in general.
- 10:46Yeah, yeah, exactly.
- 10:47All right.
- 10:49Another thing worth pointing out while we have this on the screen is it doesn't work exactly on Windows, right?
- 10:55But there is ienv-win, W-I-N.
- 10:58Yeah.
- 10:59So the question is, what's the benefit of using that on Windows over, say, Conda?
- 11:04And I feel like almost it's like a general question.
- 11:07What's the advantages of something like Pi, ENV plus virtual environments and pip over Conda almost?
- 11:13I would say if you're using Conda on Windows or whatever operating system and you are happy with it, I don't really see any reason to switch to something else.
- 11:23I mean, Conda is like this one huge tool that you can use to manage both Python versions, dependencies, installing packages and stuff like that.
- 11:31So I would say if you're happy, just stick with it.
- 11:34But if you're not using Conda and for some reason you don't want to use it, but you're on Windows and you want to install different versions of Python, then Py and Win is a great tool to do that.
- 11:45Because unlike Conda, it's very specific.
- 11:48It's just for managing Python versions.
- 11:51It doesn't do a lot of other things that Conda does.
- 11:54But if you're looking for this specific type of tool, then I would stick with Py and Win.
- 11:59This portion of Talk Python is brought to you by 45 Drives.
- 12:0445 Drives offers the only enterprise data storage servers powered by open source.
- 12:10They build their solutions with off-the-shelf hardware and use software-defined open source designs that are unmatched in price and flexibility.
- 12:19The open source solutions 45 Drives uses are powerful, robust and completely supported from end to end.
- 12:25And best of all, they come with zero software licensing fees and no vendor lock-in.
- 12:3045 Drives offers servers ranging from 4 to 60 bays and can guide your organization through any sized data storage challenge.
- 12:37Check out what they have to offer over at talkpython.fm/45drives.
- 12:42If you get in touch with them and say you heard about their offer from us, you'll get a chance to win a custom front plate.
- 12:47So visit talkpython.fm/45drives or just click the link in your podcast player.
- 12:53I think one of the things that I would point out here is that the conda packages to some degree and certainly the official anaconda version, not initially the Honda Forge version.
- 13:07So you'll see if you're going to get a little bit more than the other thing.
- 13:10So you'll see if you're going to get a little bit more.
- 13:11You'll see if you're going to get a little bit more.
- 13:12You'll see if you're going to get a little bit more.
- 13:13You'll see if you're going to get a little bit more.
- 13:14You'll see if you're going to get a little bit more.
- 13:15You'll see if you're going to get a little bit more.
- 13:17And then eventually, you know, once it's been verified to be working well and all that, it gets brought into anaconda.
- 13:24And generally, that's not a big deal.
- 13:26But sometimes if you want to be on the absolute latest, there's a little bit of a delay.
- 13:30And the place where absolute latest matters the most is if there's a security vulnerability in an API framework or a web framework.
- 13:38You want to update if something like that were to come out, say, with Django, which has happened recently.
- 13:44You would like to update to the new version immediately before anybody starts poking around on those things.
- 13:49And things like Honda and these other more verified places sometimes lag behind.
- 13:55And if it takes a little bit longer to get the latest notebook, UI or whatever, who cares?
- 14:00But if there's an active exploit on the Internet against my thing, then you definitely are going to want the latest, latest, latest as soon as possible.
- 14:09So I think that's one thing to consider if that's your world.
- 14:13That's something I run into.
- 14:14Yeah.
- 14:15All right.
- 14:15Let's take a couple of things out of the live stream comments just because they're follow-ups, right?
- 14:21So one question is, what's the best homebrew equivalent for Windows?
- 14:25I've got some thoughts, but go ahead, Sebastian.
- 14:27Okay.
- 14:28I'm not a Windows user.
- 14:30I have no idea.
- 14:31I've heard about Chocolaty, but I only heard about it.
- 14:35Sorry.
- 14:36Yeah.
- 14:36So.
- 14:37Yeah.
- 14:38And Crested says Chocolaty and then Scoop and Winget.
- 14:42I don't know about Scoop or Winget, but Chocolaty is very much like Homebrew.
- 14:47And I'm familiar with that one.
- 14:48And that one works pretty well.
- 14:49So that's pretty cool.
- 14:51But I definitely recommend if you're on Windows, check out Chocolaty.
- 14:54If you're on Mac, check out Homebrew.
- 14:56And then a lot of the Linux distributions already actually have this, right?
- 15:00Like apt on Ubuntu and so on.
- 15:02You don't need to go searching for those because that's the primary way.
- 15:05Yeah.
- 15:05And then finally, Mike Levin says, the best Homebrew equivalent for Windows is an Ubuntu
- 15:12repo under WSL.
- 15:13Okay.
- 15:13That's an interesting one as well.
- 15:15But yeah.
- 15:15So you also have WSL, but then you have apt as well.
- 15:17All right.
- 15:19Cool.
- 15:19Thank you everyone for that.
- 15:20And we'll get back to some of the main questions as well.
- 15:23So next one, Sebastian.
- 15:25is about Poetry.
- 15:28I've been using setup.py in my Python projects, but I see a lot of tutorials recommending other
- 15:33tools like pipenv or Poetry.
- 15:35Should you switch?
- 15:36So basically, Poetry and pipenv can be used to manage projects.
- 15:42So they are much more than just like a setup.py replacement.
- 15:46Actually, pipenv is not a replacement for setup.py, but I will get to that in a moment.
- 15:51So basically, those are like bigger tools that you can use to manage your
- 15:55whole project.
- 15:56You can use it to like add dependencies, to update dependencies.
- 15:59They will manage the virtual environments for you.
- 16:02So you don't have to activate anything and things like that.
- 16:05And with Poetry, you can also publish packages to pip, which is basically a replacement for
- 16:11setup.py.
- 16:12You don't need to have setup.py with Poetry, which is kind of convenient because I always
- 16:17have to Google out what I should put in the setup.py.
- 16:20There is also a package called fleet if you want a lightweight replacement for setup.py,
- 16:25but that's an off topic.
- 16:26And if you like using setup.py, and again, you don't have a real reason to switch to something
- 16:34else, I would say stick with setup.py because that's like the de facto way of doing things
- 16:41in Python.
- 16:42Setup.py is supported by Python itself.
- 16:46There is also this project Toml that is now supported with like recent pip.
- 16:51But for many years, setup.py was the way of building packages.
- 16:55So I wouldn't just switch for the sake of switching.
- 16:59But if you're looking for a tool that can manage your whole project, then I would use either
- 17:05pip.env or Poetry.
- 17:06And if you want to publish, then I would go with Poetry.
- 17:09Yeah.
- 17:09And I think you also want to consider, are you building a package or are you building an
- 17:14application?
- 17:14Because some of the things that you do differently, particularly around like pip.env, is a little
- 17:20bit more targeted at building applications than it is packages, from my understanding.
- 17:24Yeah, exactly.
- 17:26And one thing to consider is that both Poetry and pip.env will be an external dependency for
- 17:32your project.
- 17:32So if for some reason they break or stop being maintained, then you're gonna have to migrate
- 17:39to something else.
- 17:40While if you still use setup.py and requirements files, then all the tools are there when you
- 17:47install Python.
- 17:47Yeah, that's a good point.
- 17:49But also, yeah, it's like a bootstrapping step to get started.
- 17:52So if you have setup.py, you don't need to install anything else to kind of like check
- 17:57it out and try it.
- 17:58Whereas, you know, if you have Poetry, the first thing you have to do with a new environment
- 18:04is set up Poetry.
- 18:04So then you can then initialize all the stuff, right?
- 18:07Yeah, exactly.
- 18:08I think I was recording an episode for the courses with Poetry.
- 18:12And the first package that I wanted to add was the latest pytest.
- 18:16And the first command I got was an error because Poetry already had an older version of
- 18:21pytest pin down.
- 18:23So I had to like open the config file and remove it.
- 18:26But the first impression was kind of weird.
- 18:29You try to add a package and it breaks.
- 18:31But otherwise, I would say it's a good tool.
- 18:34If you like it, use it.
- 18:35But keep in mind that it's yet another dependency for you.
- 18:38Okay.
- 18:39Let me ask a follow-up from Incrusted on the live stream.
- 18:45What is the best way, if any, for distributing Python applications to non-developers?
- 18:49So this conversation of Poetry and PIP-EMV and setup, all that is for developers, right?
- 18:54Yeah.
- 18:55So what's the story on where's the icon thing I can put my doc or pin to my taskbar and let
- 19:01people click?
- 19:02What do I do there?
- 19:03Yeah, that's a good question.
- 19:04I also covered this in the course because I was also looking for a way that you can distribute
- 19:09your Python application with people who don't know what Python is.
- 19:12And there is this PyInstaller package that you can use to create an executable files that contains
- 19:19all the dependencies.
- 19:21And it works really great.
- 19:22I was able to spin up a Windows machine, create an executable, then spin up another Windows machine
- 19:29without even Python installed, move it there, and it was working fine.
- 19:32It was using like a graphical user interface.
- 19:34The only downside I saw is that they are not cross-compilers.
- 19:39So if you want to build an application for Windows, you have to compile it on Windows.
- 19:44If you want to build a Mac application, you have to do the same thing on Mac.
- 19:47Otherwise, I would say PyInstaller is a really great way to build executable Python binaries.
- 19:53Yeah, I agree.
- 19:54And so does Patrick Lobiel.
- 19:55Hey, Patrick.
- 19:57Thanks for that.
- 19:57Also add one thing really quick to this.
- 20:00I really, really quickly, partly to show it as an example for people, and partly because
- 20:04this is the thing that I do all the time.
- 20:06I built the little thing, a little Mac menu bar app, 100% in Python, and distributed it as a
- 20:13.app file, just like you all are talking about here.
- 20:17So I created this thing.
- 20:18It looks like this.
- 20:19It does a few more things now.
- 20:20But if you're copying some title and you want to turn it into a file name, or you want to
- 20:25make sure you strip off stuff or clean out the text before you paste it somewhere else,
- 20:29I built this little thing that goes in the menu bar, filled it with Python, and it runs
- 20:34with PyInstaller, I believe.
- 20:36No, that uses PyToApp, actually.
- 20:38It's the one that it uses, I think.
- 20:42So anyway, there's a couple of options.
- 20:44But yeah, it's usually some variation of what you need to do on Windows and on Mac, and you
- 20:49actually have to have a Windows machine and you have to have a macOS machine in order to
- 20:54create those distributables.
- 20:55So kind of a pain there.
- 20:57By the way, if someone is wondering what's this PyToApp, because I was checking this as
- 21:01well.
- 21:01So there is PyInstaller that can be used for Windows, Mac, and Linux distributions.
- 21:06And there is this PyToApp that is like a PyInstaller, but for creating Mac application.
- 21:12And there's also PyToWin, which is also, again, like a subset of...
- 21:16PyToExe, right?
- 21:17Yeah, PyToExe.
- 21:18Yeah.
- 21:18That is like a subset of PyInstaller for Windows.
- 21:21I feel like they might be more specific, like covering, you know, adding things like icons and
- 21:26other stuff, maybe a little bit better.
- 21:27I'm not sure.
- 21:28For example, like this one, it has like an icon set that you create for it.
- 21:33And the reason I chose PyToApp is this is based on Rumps, which is a ridiculously uncomplicated
- 21:40like Mac notifications or something.
- 21:42I don't remember what the URL, the acronym stands for, but it's 100% a Mac app.
- 21:47So I figured I'd just use the Mac app builder thing for it because there's no chance it's
- 21:52running on any other thing because the framework itself is only for Macs.
- 21:56So yeah, anyway, let's go to the next question.
- 21:58Here we go.
- 21:59Which one should I choose?
- 22:01PIP, ENV, or Poetry, or something else?
- 22:04I would say they are both very similar.
- 22:06It's just that Poetry allows you to easily publish packages on PyPI.
- 22:11So if you're building a Python package, I would go with Poetry.
- 22:15If you're not building a Python package, then I think both should be fine.
- 22:19They offer a similar set of functionality.
- 22:21Okay.
- 22:22Yeah, very cool.
- 22:23Very cool.
- 22:24Kondo versus pip.
- 22:25We sort of touched on this a little bit, but maybe a little more.
- 22:28Yeah.
- 22:29So that's an interesting question because with Conda, you install binaries from the Conda
- 22:35repository.
- 22:35While with pip, you install packages from PyPI and they are not always binaries.
- 22:41So the main difference is when there is no binary.
- 22:46So if there is no binary, pip will try to build this package from sources.
- 22:50And if you're missing some dependencies on your computer, then it's going to crash.
- 22:54Right.
- 22:54If you're on Windows and you see cannot find vcvars.bat, this is the problem.
- 22:59Yeah.
- 23:00If you're somewhere else and it just fails to install with something that looks like
- 23:03a C++ compiler, that's the problem.
- 23:06And that's part of the problem what Conda is trying to solve, right?
- 23:08Exactly.
- 23:08So with Conda, there is no such problem because every package that is published in the Conda
- 23:14repository is a binary.
- 23:16So it contains all the dependencies, which can be super helpful if you're not like, if you're
- 23:22going to have a computer science background or if you're not very experienced with debugging,
- 23:26there's missing whatever you said, Mike.
- 23:30So let's say you, I don't know, if you're a data scientist and you just want to have your
- 23:36code running, you don't care about setting up stuff, you just want to install some packages
- 23:41and have it running.
- 23:42Conda is an excellent choice because it has like a very good support for all those data
- 23:47science packages.
- 23:48You just install them, you have all the dependencies installed.
- 23:51So it makes things much, much easier in that sense.
- 23:54Yeah.
- 23:54Especially in the data science world where there's really weird dependencies, like you need a Fortran
- 23:59compiler, like I definitely don't have that on my machine.
- 24:02Yeah.
- 24:02On the other hand, as you already mentioned, Michael, those binaries don't always have the
- 24:06latest version.
- 24:07So someone first have to create this binary.
- 24:09And if there is like a vulnerability, then you have a problem.
- 24:13And there might be some like less popular packages that are available on PyPI, but no one created
- 24:19a binary for Conda.
- 24:20So either you have to wait until someone does that or you have to create it yourself.
- 24:25Yeah.
- 24:25Because with Conda, you can also install packages from pip, from PyPI, but you basically
- 24:31have to build a binary yourself.
- 24:33So again, if you're not like very experienced developer, you probably don't know how to do
- 24:38this.
- 24:39Yeah.
- 24:39So I would say like the benefit of using pip is that you can install any package from PyPI
- 24:44while with Conda you can't, but with Conda installing things is much easier.
- 24:49Yeah.
- 24:49I think that sounds like a pretty good summary.
- 24:51It's worth pointing out that the workflow is quite different from a virtual environment
- 24:56from Conda, right?
- 24:57Like Conda, you create the environment off somewhere magical with the name and then you activate
- 25:00it by saying the name.
- 25:01Whereas pip, it's more, you explicitly say this one here in this location.
- 25:06Yeah.
- 25:06So Mike Levin has a chat stream.
- 25:08I'll go through here.
- 25:10Thanks, Mike.
- 25:11So Conda was, he says only necessary, I'll say was more necessary before pip included
- 25:15binaries, specifically with wheels.
- 25:17And now that wheels, it doesn't happen as much pip can replace Anaconda now.
- 25:22That's true.
- 25:23But Frankie one says, yeah, but not everything has a cross platform wheel as well.
- 25:28So I do agree with that.
- 25:29For example, MicroWSGI, when I install that, it seems to like compile away for good 30 seconds
- 25:35instead of coming with some binary version that can just drop in or so on.
- 25:40So yeah, I agree, Mike, that that's generally true, that things are much better now that
- 25:46we have wheels, but it's not also that it's not a hundred percent.
- 25:49What do you think?
- 25:49Yeah, I agree with that.
- 25:50And one thing that I want to also add is that while we are talking about binaries and dependencies,
- 25:56if you are, let's say, a web developer and you're installing Django or FastAPI, there
- 26:02is like very little chance that you're going to be missing some dependencies.
- 26:06So you probably will never have problems with pip.
- 26:10So for some cases using pip, it's going to be perfectly fine for all your work life.
- 26:15Yeah.
- 26:16So it's the weirder, farther out it gets.
- 26:18Like, like I said, Fortran dependencies with some weird C library or something.
- 26:23And then also Joan Pino says, I've used PyInstaller for some side projects and it works really well.
- 26:30Yeah, quite cool.
- 26:31That's definitely a neat option.
- 26:32All right, Sebastian, onto the next.
- 26:35How do you hide secrets for development for production?
- 26:39We've talked about, I think we haven't talked about yet, but there's, as in secret,
- 26:44which is quite unnerving to see, should get going along here and finding all the secrets that people have put into public repos
- 26:52or what were private repos, but then got turned public and people are pulling these out.
- 26:57That's very much not good.
- 27:00This is not what you want to do.
- 27:01Just put the secrets right in your source code.
- 27:04So what do you do?
- 27:05What are your recommendations here?
- 27:06So my recommendation is pretty standard to use the environment to hide the, well, the secrets and start them as environment variables.
- 27:15And for example, you can have like a file with the YAML extension.
- 27:21You can put it in the Git repository.
- 27:23It's just, you don't put the secrets there.
- 27:26You just put the structure and let's say dummy values or whatever.
- 27:29So you remember that you have to set up all those environment variables.
- 27:33Right.
- 27:33That's one of the challenges because if you put it in environment variables or you put it into the, some like secrets template.yaml versus secrets.yaml,
- 27:41where the secrets.yaml is not in the repository.
- 27:44In a real project, there's going to be a bunch of stuff.
- 27:46You got to have the names just right.
- 27:47And you got to like knowing what you're even supposed to fill out for the app to work is a challenge.
- 27:51So having this template around is super helpful, but not with the real secrets, right?
- 27:56Yeah.
- 27:56And there are some libraries that you can use that will make managing those templates much easier for you.
- 28:02And why am I saying about those templates is that quite often when there is no template,
- 28:08people start putting variables into the environment and they spin up a new server.
- 28:13And they realize that they forgot about some environment variables and then things stop working.
- 28:19So good practice is to have this like example environment variables file where you list all the variables that have to be set.
- 28:27And then you have like a proper environment file that you never put to the GitHub repository where you actually specify the real secrets and then you load it to the environment.
- 28:37Yeah.
- 28:38And Crested has an interesting location.
- 28:40Under a rock.
- 28:43Under a rock.
- 28:44Yeah.
- 28:44Yeah.
- 28:44No, but then more seriously points out that there are tools for keeping secrets in version control too, like certain vaults, right?
- 28:51Like HashiCorp has something and we've had some sponsors with Talk Python and things where basically set up like the equivalent of one password or LastPass, but for your server, right?
- 29:02Yeah, definitely.
- 29:02Yeah.
- 29:02Definitely.
- 29:02If you have to be more careful about your secret, it makes sense to use an external tool.
- 29:08But if a lot of those things can be mitigated by setting up the API keys properly.
- 29:13For example, if you have like an API key for AWS, you just limit what this account can do.
- 29:21And that way you don't spin up.
- 29:23If it leaks, then you don't spin up 1000 servers mining Bitcoins for you.
- 29:27And then you wake up with like $1 million debt or something like that.
- 29:30So there are different ways to mitigate depends on what's the level of risk.
- 29:34But the easiest thing is to use the environment.
- 29:36Yeah.
- 29:36And you can combine them as well, right?
- 29:38Like you could have an encryption key in the environment variable and then actually encrypt the other elements in ways and then use instead of, because that way, if it's just in the environment, you could log in.
- 29:49If you hack into the process, you could just go, well, OS.env, like what's in here?
- 29:53Let's just look around.
- 29:54And if it's all full of encrypted stuff, you're like, I don't have no idea how to unencrypt this.
- 29:58There's layers, right?
- 29:59And obviously running your app is lower privileges is really important.
- 30:03Firewalls and isolate.
- 30:05There's like layers.
- 30:06This is not the only thing, but one of the things is not to put raw passwords and API keys in your source code.
- 30:12Cool.
- 30:13All right.
- 30:13Let's talk Docker again.
- 30:14Yeah.
- 30:15So.
- 30:15Should people use Docker?
- 30:17What do you think?
- 30:17More broadly.
- 30:18Yeah, exactly.
- 30:19This is a more broad question than the first one we had.
- 30:21It depends who you ask.
- 30:22Because there are some people who will tell you that you should always use Docker.
- 30:26And when you start using Docker, you should spin up a Kubernetes cluster and then you finally will be able to deploy your almost static block there.
- 30:33Yeah.
- 30:34But don't listen to those people.
- 30:36I mean, it really depends on what you're trying to do.
- 30:38Because Docker has those amazing benefits that it makes deploying your application much, much easier.
- 30:45So especially when you want to scale something up, Docker really pays off.
- 30:49Because for example, let's say you're deploying your website for the first time and probably renting a virtual private server and then installing a Django website there.
- 30:58It's easier than writing a Docker file.
- 31:07It makes it much easier because you always use the same Docker file.
- 31:10And spinning up 100 virtual private servers by hand is probably not something that you want to do.
- 31:16There is a higher cost up front.
- 31:24And another huge advantage of Docker is that it makes collaborating with people much easier.
- 31:33So when I was joining a new team, there were like some setup scripts and you had to install some dependencies and you had to set up some environment variables.
- 31:40And then after two days, you were finally able to start coding.
- 31:43And now when I joined new projects that are using Docker, it's just two commands.
- 31:48Docker build and Docker run.
- 31:50And you have this whole work, all development environment running.
- 31:53You have the website there.
- 31:54You have database.
- 31:55You have the ready server, whatever.
- 31:57So it makes joining a new team much, much easier.
- 32:01On the other hand, let's say if you have like a Python script or like one off script that you want to, I don't know, scrape some data from the internet, there is like absolutely no point in adding yourself more work to write a Docker file if you know that you're going to be throwing away this code like tomorrow.
- 32:19So it depends on what's your use case.
- 32:22If it's for like simple things, I wouldn't bother unless you really like using Docker.
- 32:26But for like more advanced projects, it will probably pay off.
- 32:30Yeah, I was speaking with one of the Python listeners having a, what do you think about this and how do we solve this problem type of conversation?
- 32:38And it was basically, how do I make sure that everyone on my team has exactly the same version of Python, right?
- 32:47I want to make sure that they're using 3.9.2, not 3.9.3, not 3.9.1.
- 32:54You definitely don't want one because that has that floating point vulnerability.
- 32:57But you know what I mean?
- 32:58Like you don't want variation.
- 33:00You want exactly that thing.
- 33:01And if you really care down to that degree, you know, Docker is great because then you just make everyone run the same Docker image.
- 33:08You provide it in some, I don't know, local Docker hub type thing, or just put the Docker file into version control.
- 33:16And if it changes, then it just rebuilds and it runs and off you go, right?
- 33:19Yeah.
- 33:20Yeah.
- 33:20So it helps a lot for that.
- 33:21But I totally agree.
- 33:22I wouldn't use it for like super simple things.
- 33:25You're just causing yourself more challenges when often it's not really that useful or that needed, I guess is the way to put it.
- 33:33So there's some interesting follow-ups here in the live stream.
- 33:36In addition to under a rock, Frankie one says, I thought GitHub now automatically detects when you commit secrets accidentally.
- 33:43I think I did hear that it takes an attempt.
- 33:46I wouldn't count on GitHub catching all of my secrets.
- 33:49I would be more deliberate about it.
- 33:51Do you know anything about this?
- 33:52Not really.
- 33:53I know that there are those bots that check like for the vulnerabilities and stuff like that.
- 33:57So I would imagine that it also has a bot to detect secrets in the commits.
- 34:02But I'm just wondering how it works.
- 34:03Because when you push something to GitHub, it's automatically available there.
- 34:07So does GitHub put some blocker on your repo to not show the latest commit?
- 34:14Because usually what I see people doing is that they commit, they push a commit with a secret and they realize they push that.
- 34:21So they push another commit removing the secret.
- 34:23But there are like bots running through GitHub harvesting those.
- 34:27So the moment you push it, it's already distributed to some people or to shigit.
- 34:32It's too late.
- 34:33It's too late.
- 34:35The stream has already been observed.
- 34:37It's really not good.
- 34:39Related to this sort of follow on, I think related to the Docker a little bit, maybe in some ways.
- 34:45So THP says, if you're not an expert, Pythonista, how do you manage supply chain, full chain attacks appropriately?
- 34:53You want to maybe give people an idea what supply chain vulnerabilities are and then we could talk about this?
- 34:59I don't know what our supply chain vulnerabilities.
- 35:01I'll give you the run.
- 35:03So for example, recently there were about 4,000 malicious packages that were put into PyPI.
- 35:08Then there was another vulnerability where if you're running a private PyPI server so that you can have like your team can publish and share packages across applications.
- 35:17And then often those will like fall through to the real PyPI.
- 35:21So I could just say pip install requests and it'll get the one from PyPI.
- 35:25If I say pip install data layer, it'll get our local data layer.
- 35:28Right.
- 35:29One of the vulnerabilities was if somebody finds a way to publish your private name thing, but to PyPI with a higher version number, pip would prefer that one.
- 35:39And go give that.
- 35:41But that might be one that is some sort of vulnerability or something along those lines.
- 35:45Right.
- 35:45So this may be more like more concerning is in PHP.
- 35:50Somebody put in some code to run that if you put Xerodium, I believe, as a header.
- 35:57I think it was in the headers or no, it was in the user agent.
- 36:00If you put the word Xerodium and then some PHP code in the user agent and request it against a PHP site, which 79% of the Internet runs on, I think a lot.
- 36:11It would actually just run that arbitrary code.
- 36:14So those are the types of things I think that we're talking about here.
- 36:16That's a very good question.
- 36:17And to be honest, I don't really know how you can mitigate those kind of attacks because like, yeah, the package name typos can happen.
- 36:28And there is probably not much you can do.
- 36:31The only thing that comes to my mind is to use like a, if you don't know how to solve those problems, it's probably worth paying someone to take care of that.
- 36:40So I don't know, maybe using Heroku would be a bit more helpful.
- 36:45I don't know how they can mitigate this stuff.
- 36:48I don't know.
- 36:49What about you, Michael?
- 36:50Yeah, I got a couple of ideas.
- 36:51None of them are perfect.
- 36:53You can pin your versions.
- 36:54So you can go and look at all the libraries you're using and say, okay, I trust them as they are now.
- 37:00And if you pin the version and your requirements.txt or your pyproject.tml or whatever, you're not going to automatically get the latest version, which may have some kind of vulnerability snuck into it.
- 37:11So you can consciously decide to move to the next version.
- 37:15Hopefully, you know, if somebody were to hack into Django, maybe that gets out, but it wouldn't last very long.
- 37:21Right.
- 37:22And so if you don't automatically upgrade on just the next deploy, then you're going to at least be a little bit better off.
- 37:28So pin your versions, probably one.
- 37:30You could whitelist.
- 37:31You can do things like set up a private PyPI server and just whitelist packages so people can't arbitrarily install various things, but they only install ones you approve.
- 37:42You can use this thing.
- 37:43You can use this as the sneak package advisor.
- 37:47So if I want to learn about FastAPI, like what's the story of FastAPI?
- 37:51This is cool because it's not just security, but it's more than just security.
- 37:54Gives you like the health, the maintainability level or how much it's maintained, whether it has any known security issues, whether community is active, whether it's influential, all sorts of cool graphs about who's working on it, when it's been worked on, amount of funding, security analysis by sneak.
- 38:13And so on.
- 38:14So this is a pretty good thing.
- 38:15So together, right?
- 38:17So if I were to say I'm going to pin my versions and then those versions are going to be verified or with or maybe I'm going to create a whitelist and only allow you install from the whitelist.
- 38:26And I'll make sure that everything that gets through the whitelist at least has been checked out by sneak.
- 38:30Not perfect, but it's better than just pip install random thing and hope for the best.
- 38:35So yeah, anyway, let's see.
- 38:37And Crested also follows on with is vendoring dependencies an appropriate mitigation?
- 38:43Like instead of pip installing requests, like finding the key bits of requests and just copying that code into your application.
- 38:50It certainly would help.
- 38:52On the downside, if a non-intended vulnerability were to get into requests, not a hack, but just something that was a ultimately became a security hole.
- 39:01You've now vendored in that instead of automatically getting the upgrade, right?
- 39:04I don't know.
- 39:05What do you think?
- 39:06Yeah, I think it's easy to do this because you can basically put the virtual environment folder with your project and that's it.
- 39:13In the long run, it's probably harder to maintain.
- 39:15And I think, as you said, like hitting the dependency versions, making sure you don't have typos probably can save you from a lot of those problems.
- 39:25Yeah, be very careful when you pip install something that you get the spelling right.
- 39:28Because there was one of those vulnerable ones.
- 39:31It was something like asteroids versus asteroid.
- 39:34I mean, it was like plural versus singular and that was it.
- 39:37Right?
- 39:38It's very subtle.
- 39:39Yeah.
- 39:39And I guess if you're using like more popular packages, then probably should be safe.
- 39:44I would say like with some more obscure packages, it can maybe happen that they will get abandoned and someone will either hack the Git repository or like squat it.
- 39:54I don't know if it's actually possible with PyPI, but with bigger packages, it's probably not an issue.
- 39:59Yeah, for sure.
- 40:00I think it's a relative thing.
- 40:02So let's see.
- 40:04PyLang, hey PyLang, also says you can develop in a VM or Docker.
- 40:08And related to that, Doug Farrell.
- 40:11Hey, Doug.
- 40:11He says, really interested in how to set up a Docker-based development environment.
- 40:15So one of the things I think you want to distinguish here in this supply chain thing is I'm trying something out.
- 40:23If it's going to run that setup high when I pip install it, it could pip install virus onto my machine.
- 40:29If that's your concern, you can develop in a virtual machine.
- 40:32You can develop in Docker.
- 40:33Because then all it sees is what's inside the Docker machine, which is nothing, basically.
- 40:38So that's really cool.
- 40:39So that's really cool.
- 40:40But also, as Encrusted points out, you know, that if this is developing your application and pushing it to production, that vulnerability comes along onside the web server.
- 40:51So that's a challenge, right?
- 40:53So in this exploratory world, I think things like Docker actually help a lot solve this problem.
- 40:58But in a production world, it does nothing.
- 41:01Nothing to help.
- 41:02But maybe let's follow on real quick with that.
- 41:05I think this development environment based on Docker is pretty interesting.
- 41:09For example, PyCharm now lets you set up a Docker image as the run target, which you can even debug into.
- 41:16And so you just press run, and it starts the Docker thing.
- 41:19It attaches to it.
- 41:20You just run it there.
- 41:22I think VS Code also has something along these lines.
- 41:25What do you think about this?
- 41:26Yeah, because I'm using VS Code.
- 41:28I was trying to set it up with Docker some time ago, and it was possible to also put the breakpoints there and maybe run, let's say, a Django application in Docker and have breakpoints work there.
- 41:38It just requires a bit of setup.
- 41:41But I would guess that either by now or soon in the future, the guys from the VS Code will further simplify it.
- 41:50Because they just keep adding things to make stuff easier.
- 41:53Yeah.
- 41:53So it's definitely a viable option.
- 41:55Yeah, that sounds good.
- 41:57Here is the thing for PyCharm, right?
- 42:01I basically configure an interpreter using Docker.
- 42:04And just press go, and then boom, off it runs in Docker, which is, I think, pretty awesome.
- 42:11Talk Python To Me is partially supported by our training courses.
- 42:14Do you want to learn Python, but you can't bear to subscribe to yet another service?
- 42:19At Talk Python Training, we hate subscriptions too.
- 42:22That's why our course bundle gives you full access to the entire library of courses for one fair price.
- 42:28That's right.
- 42:29With the course bundle, you save 70% off the full price of our courses, and you own them all forever.
- 42:35That includes courses published at the time of the purchase, as well as courses released within about a year of the bundle.
- 42:41So stop subscribing and start learning at talkpython.fm/everything.
- 42:49Yeah, some comments about this basically being so much about dependencies and stuff.
- 42:53But I do think a lot of it really is, it's like, how do you get the right libraries?
- 42:57How do you keep those libraries up to date?
- 42:59How do you do that securely?
- 43:00How do you deploy those things out to the world?
- 43:02How do you share that with the user?
- 43:03So much of this stuff is a pretty interesting thing to talk about.
- 43:06One follow-up here from Doug is, are there resources or links that would help me and everyone understand how to build a Django debuggable Docker environment?
- 43:14I think actually, the thing that I have on the screen here, if you're into PyCharm, is one I'll throw that into the live chat here.
- 43:21I mean, that is, click these three buttons and then press the debug button and it runs in Docker.
- 43:27Do you have something like this for VS Code?
- 43:29So what I did, I checked the documentation.
- 43:31I think VS Code was also using Django as an example in the documentation.
- 43:36So you would have to dig in their docs, but they're pretty easy to follow.
- 43:40From the top of my head, I don't know anything.
- 43:43Yeah, okay.
- 43:44So let's see.
- 43:45I think Incrusted has a pretty interesting comment, question here.
- 43:49What's the story around code formatters, linters, and type checkers?
- 43:54Autocomplete got the better of them there, but no problem.
- 43:56Could you be more specific?
- 43:58Because I'm not sure.
- 43:59Well, yeah, I'm guessing like, did you use black?
- 44:03Did you use mypy?
- 44:05Things like that, I would guess.
- 44:07But yeah, Incrusted, give us a follow-up if you want.
- 44:10So I will start and you can clarify the question.
- 44:12So I would say definitely use some of those tools.
- 44:14Definitely, I would recommend using black.
- 44:18Because some people don't like it.
- 44:21It's opinionated and you might not like how it formats some code, even though you can actually
- 44:26put comments to disable formatting if you want to like preserve your beautifully form, a dictionary
- 44:32of list of tuples of dictionaries and stuff like that.
- 44:35But if everyone on your team is using code formatter, no matter if it's black or if it's something
- 44:40else, then at least during the code reviews, you don't have some silly discussions about
- 44:45code styles.
- 44:46And I had those discussions in the past and they were terrible because code reviews should
- 44:51focus on what's happening in the code, not how the code looks like.
- 44:55So definitely some kind of formatter is very, very useful.
- 44:59Black is the most popular one.
- 45:01It works out of the box.
- 45:02So I would suggest using that.
- 45:04And speaking of linters, I really like Flake 8, but there's also PyLint.
- 45:11And you can actually use both of them.
- 45:13And even though I have like, I don't know, eight years, nine years of Python, Flake 8 still
- 45:20finds some silly bugs that I'm doing in the code.
- 45:22And because like sometimes you're tired, you may like assign to an undefined variables and
- 45:28stuff like that.
- 45:28So instead of like waiting for your code to actually run and give you this error because
- 45:33there is like no compilation, so you can't get the errors beforehand, you immediately can
- 45:39get those easy to spot errors for free.
- 45:42So definitely spend some time adding them to your code editor.
- 45:46And then you can keep going crazy because like Flake 8 has plenty of plugins that you can
- 45:51further extend it.
- 45:52You have a bunch of other static analysis tools.
- 45:55I'm listing them in the course.
- 45:57I think there is like a website with the resources for the course that you can find some cool plugins.
- 46:01And there is stuff like, for example, Sorcery that I really like that gives you some
- 46:06recommendations of how to reformat your code.
- 46:08For example, when you're writing a for loop and it's basically building a list, you will
- 46:12get a recommendation to use a list comprehension showing you how this list comprehension will
- 46:17look like.
- 46:17So that's yet another tool that...
- 46:19Yeah.
- 46:20One of the things about Sorcery that annoyed me quite a bit is in the early days, it would
- 46:25recommend all these refactorings.
- 46:27And like nine out of 10, I'm like, yeah, that's a great refactoring.
- 46:30Other times like, no, this is a horrible refactoring.
- 46:32Like, I don't want this change.
- 46:34And I know the pattern I'm using is better than this, even though you are your program to think
- 46:39this is it.
- 46:39And you couldn't disable notification.
- 46:42So I just have this permanent mark of a warning on my screen for certain bits of code.
- 46:48They recently added a way to add for you to disable that on a per project basis.
- 46:52So now I'm also all about Sorcery.
- 46:54Now that I can turn off the one or two refactorings that I'm not a huge fan of, and then the rest
- 46:59are really nice, like you say.
- 47:00Yeah, I didn't have this experience with Sorcery.
- 47:03I like it.
- 47:03But as I said, there are like plenty of tools, so you can check them out.
- 47:07Each of them works in a slightly different way.
- 47:09You can combine them.
- 47:10You can disable some stuff if you don't like.
- 47:12For example, I didn't like piling because it was too strict.
- 47:15Yeah.
- 47:15Like when you had a class that had too little, too few methods, it was saying like, well,
- 47:20this shouldn't be class and stuff like that.
- 47:22Right, but maybe you're putting it there because it's going to get bigger in a month as the
- 47:26thing grows, but you're like putting that flexibility in now, and it's going to tell you, no, you
- 47:32shouldn't have it, right, which is not necessarily the case.
- 47:34Exactly.
- 47:35I mean, it's trying to make you write the most beautiful code.
- 47:38It's just sometimes I prefer my ugly code.
- 47:41Yeah.
- 47:42Well, yeah, for sure.
- 47:43And so a couple other follow-ups.
- 47:45Patrick Leveal says, I love using black and flake 8 with pre-commit.
- 47:48Very cool.
- 47:50The thought, Doug had the same thought as I did, that what he really likes about IDs
- 47:53like PyCharm and VS Code and the tools and plugins is that they basically do this while
- 47:58you're writing code.
- 47:59And to me, like I don't run flake 8 separately.
- 48:02I just use PyCharm with all its settings turned on, and it's super obvious if something's wrong.
- 48:07And actually what I did when I redid all my stuff with Sorcery, I went through like the
- 48:1220,000 lines of Python code that are Talk Python training, and I went and accepted every refactoring
- 48:18that Sorcery was giving me.
- 48:20Except for that one that I don't like.
- 48:22And then while I was going through, I found there's a few PyCharm warnings that I had been
- 48:27ignoring.
- 48:27They were fine, but they're like, you really should do this other thing.
- 48:29And I just fixed everything.
- 48:31Got it pristine and perfect.
- 48:33And so now I really pay attention to those warnings because there's no like leftover junk warnings.
- 48:39And I think that's actually a really big deal about a lot of this.
- 48:41And who was it over here?
- 48:43Someone, I don't see the comment, maybe I'll find it, but was asking basically, how hard
- 48:48do you enforce this?
- 48:49Yeah, here you go.
- 48:50And Chris, it says, my Py and others should be hard enforced.
- 48:54How strictly should you adhere to those?
- 48:55Like, for example, do you break continuous integration if some linter fails or something
- 49:00like that?
- 49:01Yeah, that's a very good question.
- 49:02I think it's a matter of how the rest of the teams like it.
- 49:06I work with some teams that were like very reluctant to use any of those tools.
- 49:11I work with some team leaders that said that CI has to work.
- 49:16Your commit has to pass all the CI checks.
- 49:19So it's a matter of preference.
- 49:22I mean, tools are there to help you, not to hinder you.
- 49:25So if some tool doesn't work well for you, you should kind of configure it or maybe replace
- 49:30it.
- 49:30Sure.
- 49:31So I know one question that we had kind of queued up and some people maybe a little bit
- 49:37touched on it, but we haven't really talked about the language hardly at all, have we?
- 49:41Like using language features and stuff.
- 49:43So what do you think about things like Hypen's, like this kind of stuff?
- 49:47Yeah, that's another sensitive topic.
- 49:49I would say they can be definitely useful.
- 49:52I mean, if you, especially if you have like a lot of code, some legacy code, being able
- 49:58to immediately see what are the argument types that the given function takes, what's the return
- 50:03value, what's the type of the return value a function returns in your code editor, it's
- 50:09super useful.
- 50:09Yeah.
- 50:10And even though with Python, we have duck typing, so we can get quite far with this.
- 50:16There can be some subtle bugs that type hints can help you.
- 50:20But the thing with type hints is, well, my problem with type hints is the same problem
- 50:27as with test and documentation.
- 50:29It's not strictly a problem, but it's a yet another thing that you have to take care of.
- 50:33I'm not saying I don't like writing type hints, but for example, let's say you're writing code
- 50:37and then you have to add tests.
- 50:39You have to add documentation and you have to add type hints and then you code changes and
- 50:43you have to update all three places.
- 50:45Because it's not only about updating tests and documentation, you also have to make sure
- 50:49that your type hints are updated because you have wrong type hints and they are useless.
- 50:54Yeah.
- 50:54And of course there are tools like mypy, but they are external tools.
- 50:58So you have to configure them.
- 50:59And at the beginning, you'll probably have a lot of warnings and stuff like that.
- 51:03So I would say that type hints will give you back as much love as you give them.
- 51:08So if you spend time making sure that the type hints are properly declared, that you're not
- 51:13using any in all around your code, then they are going to be very, very useful.
- 51:19Yeah.
- 51:19I absolutely love the type hints, but I think you should remain Pythonic as you think about
- 51:26using them.
- 51:26So there's, I think there's two blends is one is do you want to go down the mypy, have the
- 51:31checkers completely verify everything is absolutely hanging together like C# or C++
- 51:36compilers do like it's a hundred percent.
- 51:39This is an integer and everywhere it's an integer.
- 51:42So you like lay all that out.
- 51:43That's one way of using these.
- 51:45The other way, which is the way that I like is put them on the boundaries, right?
- 51:49If I'm creating a package and I want to put that package on PyPI, it would be awesome if
- 51:54the public API of that package all had type hints or type annotations, because then when
- 52:00I use it, I know automatically my editor knows automatically, am I doing the right thing or the
- 52:04wrong thing without having to constantly dive into the documentation?
- 52:07Is this a string or a class that contains the information that I'm supposed to pass?
- 52:12for location, right?
- 52:14Is that a quote Portland comma Oregon or is it a location object?
- 52:19But those two things said or a dictionary or what the heck goes in here, right?
- 52:22Like those kinds of answers just go away instantly.
- 52:24And when you're using it wrong, your editors will like put some kind of squiggly or something
- 52:28and say, no, no, you're using it wrong.
- 52:30And I think that's the biggest value of type hints is like right on those boundaries where
- 52:35you're maybe unfamiliar with it or something.
- 52:37It'll really communicate that across.
- 52:39Yeah.
- 52:39I wouldn't use type hints on like throwaway code, but I usually try to start to add them
- 52:46as my project grows bigger.
- 52:47So for like small project, it's easy to kind of understand what's going on, but as it keeps
- 52:51growing, it really pays off to start adding type hints.
- 52:55Yeah, for sure.
- 52:56All right.
- 52:58Getting short on our time here, but I know there's a couple of people who got in right at the beginning
- 53:02and we kind of skipped over it a little bit just because we were getting to the pre-questions
- 53:07first.
- 53:07But Patrick Lobiel has one that I think is worth touching about.
- 53:10What do you think that good Python GUI development, why do you think they're rare, especially for
- 53:14beginners, you know, real UI is way more motivating than terminal output?
- 53:18I agree that it is way more motivating.
- 53:20And I also agree that we're quite short on good UI development, GUI development options.
- 53:26Sebastian?
- 53:27Yeah.
- 53:27Same opinion.
- 53:28I was never using a lot of GUI, so I'm not very familiar how many tutorials are there, but
- 53:34I was building one for the course and I decided to use TK-Inter because it comes with Python.
- 53:41And there weren't that many tutorials, you're right.
- 53:44I found one that was very useful because it was showing a lot of different components of
- 53:49TK-Inter.
- 53:49But apart from that, I would say there weren't many showing you how to build some specific
- 53:57thing, like a specific project or something like that.
- 54:02Yeah.
- 54:02I just dream of the days when we got something like VB6 or Windows Forms was in .NET where
- 54:08you just have a nice UI thing.
- 54:10Oh, here's a button.
- 54:11Here's a text box.
- 54:12You put it over there.
- 54:12You want code to run, you double click it.
- 54:14You write the three lines of code.
- 54:15You go back to working.
- 54:16Like you push a button, you get a thing that you distribute to people's applications.
- 54:20Like I don't really understand why we don't have something like that in Python where it's
- 54:25sort of a visual layout, push a button.
- 54:28It does something, PyInstaller magic, PyToApp magic.
- 54:31Here's your app.
- 54:32Give it to someone.
- 54:33Like that would be transformative and we just, we don't have it.
- 54:36I think it's a bit of a chicken and egg thing, but one can dream, one can dream.
- 54:40All right.
- 54:40Norbert Patrick also talks about some enterprise development stuff.
- 54:45What's your take on things like Azure Active Directory and security topics like DB encryption,
- 54:50major cloud platform deployments and so on.
- 54:53Bit of an open-ended one, but what are your thoughts generally?
- 54:55I have almost no experience with Azure.
- 55:00And yeah, as you said, it's kind of a broad topic.
- 55:03So don't really know what to say here without like a specific question.
- 55:08I'll throw a few things out there.
- 55:09One, Azure Active Directory seems pretty interesting to me.
- 55:13One of the things that's an ultra pain is federated identity or trusting other people's identity.
- 55:18Like if I want to let all of your users single sign on at your place and then single sign on
- 55:23on my site, like that's not an easy thing to do right now.
- 55:25And I think Azure Active Directory makes that quite easy.
- 55:28I haven't done a lot with it, but in that use case, I think it's pretty useful.
- 55:32I honestly don't do much with Active Directory at all, like corporate accounts and like building public web apps and things like that.
- 55:38So that they don't make sense in that world.
- 55:40Database encryption.
- 55:41Very interesting.
- 55:43There's a lot of levels.
- 55:44Is this data encrypted at rest?
- 55:46Is it encrypted in memory?
- 55:47Is it encrypted in the response?
- 55:49A lot of the modern databases have like encrypted columns.
- 55:52For example, MongoDB has different encrypted columns you can have.
- 55:56And then certain clients, as they talk to it, they either may or may not be permitted to decrypt that column.
- 56:02So it could return all the columns or values without overexposing the data potentially.
- 56:07I don't do anything like that, but also encrypting backups, right?
- 56:10Like, what do you think about, I got to take a backup of the database.
- 56:14Now what?
- 56:14This is like the worst possible thing I could lose is the backup to the database, right?
- 56:20It's the only thing worse is letting people get access to the live database.
- 56:23I don't got thoughts on that.
- 56:25Like, do you have any recommendations?
- 56:26I can tell people what I've been doing lately, but it's not perfect.
- 56:29No, I will leave this question to you.
- 56:31So I've been using like an encrypted volumes.
- 56:35Like in Mac, you can create virtual encrypted volumes that you can just open and close.
- 56:39Like highly, highly encrypted.
- 56:41And so, but it appears as a drive.
- 56:43So I've been doing my backups lately straight to that thing and then closing the encrypted vault
- 56:49when I'm not actively backing up a database.
- 56:51So then I put that somewhere safe.
- 56:54But if for some reason something were to happen to it, at least what they get hold of is an encrypted
- 57:00vault with a huge password that they probably can't mess with.
- 57:03So I don't know.
- 57:04Lots to think about.
- 57:06Lots to be up late at night worrying about.
- 57:08Yeah.
- 57:09And then Vincent throws out there, we have VB style and Anvil.
- 57:12And yes, Anvil was certainly on my mind.
- 57:14I didn't quite call it out, but.
- 57:15I forgot about it, but then I remember them from some conferences and yeah.
- 57:19Anvil is really interesting in that it has that.
- 57:21It's the thing that that's different here is what you get is Anvil is super neat, but you
- 57:26do get a specific type of web application.
- 57:29But if that specific type of web application works for you, then they do have this VB style,
- 57:35drag and drop, double click, run your code, which is absolutely beautiful.
- 57:39But if I wanted to build Todoist or one password in Python, there's no real way to do that nicely.
- 57:48I think one nice thing about Anvil is that it actually generates a nice code that is readable.
- 57:54Because the one problem I have with this, what you see is what you get text editors is that I remember them from the time when you were building websites like that.
- 58:02And the resulting HTML was an abomination.
- 58:06You just couldn't modify it by hand anymore.
- 58:08So I'm worried that if we get tools like that for Python, it's also going to result in like unreadable code.
- 58:15But I know that Anvil actually generates a pretty nice code.
- 58:18Yeah, I remember some of the tools you would look at the, here's the auto generated code.
- 58:24And it was like, basically, there's giant comments.
- 58:26Don't touch this.
- 58:27Don't try to read this.
- 58:28Just leave it alone.
- 58:29Any attempt to mess with it will probably just break everything.
- 58:32Don't touch it.
- 58:34So Doug also thinks Anvil is awesome.
- 58:37Yeah, very cool.
- 58:38And it used to be it had to run on the Anvil cloud.
- 58:41I believe they've open sourced their runtime so you can like self host it and stuff.
- 58:44That's worth checking out.
- 58:46And then, I don't know, maybe, maybe this is the last, last comment.
- 58:50I'd say maybe one more out there.
- 58:52We're throwing out something out there.
- 58:53But Kristen says, are there any courses out there that teach you how to get started with a lot of what we're talking about without any background knowledge?
- 59:01I certainly will give another shout out to your course, Sebastian, Modern Python Projects over at Talk Python Training.
- 59:07That is definitely a great course that goes deep into all these things, like nine hours of conversation of like, here's my screen.
- 59:15Let's go do these things.
- 59:16Is it with no background knowledge?
- 59:18I mean, you do have to know Python, right, to do this.
- 59:21So basically, what are the assumptions for your course?
- 59:23You have to know Python.
- 59:25And that's it.
- 59:26I show you a lot of those tools, but I always start from scratch.
- 59:30Like, I even had like empty macOS accounts.
- 59:34So I made sure that I don't miss some dependencies and stuff like that.
- 59:38I also like spin up a Windows VM for some parts that require Windows.
- 59:42So I think you should be good with just knowing Python.
- 59:46Yeah.
- 59:46Okay.
- 59:47A couple of real quick ones here.
- 59:49Doug says, oh, man, yes.
- 59:51Visual Python would be amazing.
- 59:52I like Visual Basic.
- 59:53I agree.
- 59:54And then THP says, Fman build system is a pretty cool.
- 59:58Fman is a pretty cool UI in the Fman build system for building those things up and distributed.
- 1:00:04And that's pretty interesting.
- 1:00:05I haven't done anything with Fman.
- 1:00:06Have you?
- 1:00:06No.
- 1:00:07First time I heard the name.
- 1:00:08Yeah.
- 1:00:08It's like a file management tool, I believe, in Python.
- 1:00:11The person who created it then also built this build system and this UI on top of it.
- 1:00:16So pretty interesting.
- 1:00:16Looks cool.
- 1:00:17Let's see.
- 1:00:18There's another one from Joan.
- 1:00:20Is Quart and its async capabilities ready to level up Flask webmaps for medium-sized enterprises
- 1:00:25or currently better to stick with Flask?
- 1:00:27I have no experience with Quart.
- 1:00:29So I don't know.
- 1:00:30What about you, Michael?
- 1:00:30None.
- 1:00:31I mean, I interviewed the guy who did it and I've played around with it and it seems okay.
- 1:00:36But at enterprise, like it's got to be five nines level of up.
- 1:00:40I've never run anything like that.
- 1:00:41Honestly, if I was really, really looking to build a web app with async capabilities,
- 1:00:46I would either look at FastAPI or Starlette.
- 1:00:49Like I know people might think, oh, with FastAPI, that's an API thing, not a web thing.
- 1:00:54But to be honest, you know, it can be, definitely can be done.
- 1:00:58And I actually built a whole class on how to take FastAPI and sort of replace Flask with it.
- 1:01:04So it's not that hard.
- 1:01:05It supports templates, supports static files, all those kinds of things.
- 1:01:08It is super cool.
- 1:01:09And yeah, thanks Norbert for the shout out on the 10 apps course.
- 1:01:13That's really a fun one.
- 1:01:14But yeah, so I think actually if I was trying to go all in on async,
- 1:01:18I feel like FastAPI is one of the best async frameworks out there.
- 1:01:23It's just, it all holds together really, really well.
- 1:01:26So, all right.
- 1:01:27Yeah, I think that might be it.
- 1:01:29Sebastian, you want to just maybe give us some wrap up thoughts here on this whole idea?
- 1:01:34Well, thank you for coming.
- 1:01:35And thank you for those questions.
- 1:01:36They were really great.
- 1:01:37And I hope we answered all of them.
- 1:01:41Yeah, I think, you know, there's so much variety.
- 1:01:44I've worked in different technologies over the years.
- 1:01:47I've been doing development like 25 years or so.
- 1:01:49And some of the time you'll find some language or some ecosystem where there's sort of a central,
- 1:01:56like this is how you do things, like specifically in the Microsoft space with .NET.
- 1:02:00Here's the one web framework you use.
- 1:02:03Here's the one database ORM you use to talk to the one database you use.
- 1:02:07And while that's really helpful, now I know what to do.
- 1:02:11I do these four things and I'm good.
- 1:02:12This is the recommended way.
- 1:02:13In Python, we don't have that.
- 1:02:15And that's absolutely a blessing, but it's something of a curse as well in that there's
- 1:02:21this paradox of choice, right?
- 1:02:22Oh, it's amazing.
- 1:02:24We have this cool ORM library.
- 1:02:25Oh, wait, there's 10.
- 1:02:26Well, if there's 10 ORM libraries, which one should I choose?
- 1:02:29And we were having this conversation.
- 1:02:30Should we use Flask?
- 1:02:31Should we use FastAPI?
- 1:02:32Should we use Court on top of Flask?
- 1:02:34Should we use Django?
- 1:02:35Like you can just go on and on and on about all the trade-offs that you have to make.
- 1:02:40So I think one of the big challenges is choosing a path and then going down it.
- 1:02:46Choosing, say, I'm going to use Poetry, Flask, Microwisgee, let's go, or something like that.
- 1:02:52Whatever your branch that you happen to follow.
- 1:02:54I think that's a big challenge.
- 1:02:56And maybe I'll throw out one more thing for people out there on the live stream, if I can
- 1:03:01pull it up quick enough, is awesome-python.com.
- 1:03:04Awesome-python.com.
- 1:03:07This kind of helps at least narrow that list, right?
- 1:03:10So for example, if I'm interested in caching, like here are probably the eight most popular
- 1:03:17caching libraries that you might use or something like that.
- 1:03:20It's not perfect, but at least it gives you some way to explore when you're totally new.
- 1:03:24Because I think that that's one of the big challenges here, Sebastian, is not that there
- 1:03:28are not enough choices, but there are so many choices at each step of the way that that's
- 1:03:33a challenge, right?
- 1:03:34There's the t-shirt, I learned Python in a weekend.
- 1:03:37It was, I learned Python.
- 1:03:38It was a great weekend, right?
- 1:03:40Like that's funny and also kind of true at the language level.
- 1:03:42But I don't know about how you feel, Sebastian.
- 1:03:44I'm still learning Python after so many years and spending all day in it.
- 1:03:48Yeah, same here and like tools come and go.
- 1:03:50I bet in like five years, this list will be completely different than it is now.
- 1:03:55So it's definitely important to spend some time trying to figure out which tool you should
- 1:04:01use.
- 1:04:01Because as you say, with Python, you can mix and match different tools.
- 1:04:05And sometimes there are like no tutorials explaining how to do things.
- 1:04:09Sometimes the tool might get popular, but then it's abandoned and it's no longer maintained.
- 1:04:15So yeah, I mean, a lot of tools to choose from.
- 1:04:18Yeah, I guess we'll leave with that.
- 1:04:20There's a lot of tools to choose from and we've covered a bunch of options and a lot of trade
- 1:04:24ops here.
- 1:04:24So Sebastian, it's been great to chat with you about that.
- 1:04:27Thanks for coming on the live stream.
- 1:04:28Thank you.
- 1:04:28Likewise.
- 1:04:29It was great to talk with you.
- 1:04:30Yeah, you as well.
- 1:04:31And thank you everyone for all the questions, those who emailed them in previously and the
- 1:04:35live ones.
- 1:04:36It was a great conversation.
- 1:04:37See you around next time.
- 1:04:38Bye guys.
- 1:04:39This has been another episode of Talk Python To Me.
- 1:04:42Our guest in this episode was Sebastian Witwowski.
- 1:04:45And it's been brought to you by 45 drives and us over at Talk Python training.
- 1:04:49Solve your storage challenges with hardware powered by open source.
- 1:04:54Check out 45 drives storage servers at talkpython.fm/45 drives and skip the vendor lock-in
- 1:05:01and software licensing fees.
- 1:05:02Want to level up your Python?
- 1:05:04We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:05:08Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:05:13And best of all, there's not a subscription in sight.
- 1:05:16Check it out for yourself at training.talkpython.fm.
- 1:05:19Be sure to subscribe to the show.
- 1:05:21Open your favorite podcast app and search for Python.
- 1:05:23We should be right at the top.
- 1:05:25You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:05:30and the direct RSS feed at /rss on talkpython.fm.
- 1:05:34We're live streaming most of our recordings these days.
- 1:05:37If you want to be part of the show and have your comments featured on the air,
- 1:05:41be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:05:46This is your host, Michael Kennedy.
- 1:05:47Thanks so much for listening.
- 1:05:48I really appreciate it.
- 1:05:50Now get out there and write some Python code.
- 1:05:52I'll see you next time.
- 1:06:12Thank you.