Latest / Talk Python To Me / #373: Reinventing Azure's Python CLI
Transcript
- 0:00Deploying and managing your application after you create it can be a big challenge.
- 0:04Cloud platforms such as Azure have literally hundreds of services.
- 0:08Which ones should you choose? How do you link them together?
- 0:11In this episode, Anthony Shaw and Shane Boyer share a new CLI tool and template
- 0:17they've created for jump-starting your use of modern Python apps and deploying them to Azure.
- 0:22We're talking FastAPI, Beanie and MongoDB, Async and Await, Bicep DevOps,
- 0:27Automated CI and CD pipelines and more.
- 0:30Plus, we also get to catch up on other Python work happening that Anthony is involved with.
- 0:35If you're interested in deploying or structuring modern Python applications,
- 0:39you'll find some interesting takeaways from our conversation.
- 0:42This is Talk Python To Me, episode 373, recorded May 12, 2022.
- 0:48Me too.
- 0:48Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:04This is your host, Michael Kennedy.
- 1:06Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past episodes
- 1:11at talkpython.fm and follow the show on Twitter via at Talk Python.
- 1:15We've started streaming most of our episodes live on YouTube.
- 1:19Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified
- 1:24about upcoming shows and be part of that episode.
- 1:27This episode is brought to you by Sentry and their awesome error monitoring product,
- 1:32as well as NordVPN.
- 1:34What you do on the internet belongs to you, not ad companies.
- 1:38Keep your connection private and safe with Nord.
- 1:40Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:45Do you need a great automatic speech-to-text API?
- 1:47Get human-level accuracy in just a few lines of code.
- 1:50Visit talkpython.fm/assemblyai.
- 1:53Anthony, Shane, welcome to Talk Python To Me.
- 1:56Hey, how are you?
- 1:57I'm doing well.
- 1:58It's great to have you here.
- 1:59Yeah, yeah.
- 2:00I'm excited to talk about this re-envisioning how Python works on Azure as a developer story
- 2:07that you all are working on.
- 2:09And from the really quick preview I've seen, it looks really exciting.
- 2:11You must be excited to share it.
- 2:13Yeah, it's been an adventure to figure out what's the fastest way to get a developer
- 2:17kind of up and running on Azure and in the cloud without having to learn a whole set of new things.
- 2:23That's kind of the goal here.
- 2:24Sure.
- 2:25And Shane, you and I, when we first started talking, we were reminiscing back to Azure in
- 2:31the early days when there were only a couple of services.
- 2:34Right.
- 2:35Yeah.
- 2:35Back in Silverlight.
- 2:36It ran on.
- 2:37Silverlight.
- 2:38It ran on.
- 2:38Silverlight.
- 2:39Right.
- 2:39Silverlight.
- 2:40Oh, my goodness.
- 2:41Right.
- 2:41Those were the days.
- 2:42What was that?
- 2:432008-ish?
- 2:44Maybe a little earlier even?
- 2:46Yeah, that sounds about right.
- 2:47Yeah, we had Silverlight.
- 2:49I think we had three actual products, and this is long before I started at Microsoft,
- 2:54and SQL Server was its own portal.
- 2:57So it had its own little space.
- 2:59And now we're like, I don't know, well over 100 different things that we can do in the portal.
- 3:03Yeah.
- 3:04I don't know how many folks who are listening have actually gone to the portal and pulled
- 3:10it up and sort of just browsed it.
- 3:12But between Azure and AWS, it's just like a paradox of choice.
- 3:16There's just layers of, oh, my gosh, the screen is full of icons.
- 3:19Oh, I opened up one, and that was a subsection of now we have like deploy features that fill
- 3:24the screen, right?
- 3:25It's quite the challenge to get up and going, right?
- 3:27Yeah.
- 3:27I think if you ask any web developer, hey, you've got code.
- 3:32How do you run this on the cloud?
- 3:33And it's like, it depends, truly takes full meaning, you know, when it comes to that.
- 3:39And, you know, before it was, you know, maybe it was just a slider bar for scaling,
- 3:45right?
- 3:45Like, oh, I want maybe two or three.
- 3:47And now it's like, oh, well, it's based on CPU and this and how the moon is moving.
- 3:50And like, there's just so many different ways that, you know, we can scale a web app or any
- 3:55part of our architecture now.
- 3:56And so many areas in which the pressure might be exerted that it needs to scale rather than
- 4:00just CPU.
- 4:01Yeah, totally.
- 4:02Before we get to it, though, just like quick introduction for you.
- 4:04I guess, Anthony, people know you.
- 4:07You've been on the show so many times.
- 4:08It's fantastic to have you back.
- 4:10Yeah, it's great to be here again.
- 4:11Yeah, for sure.
- 4:12It's always good to have you on the show.
- 4:13And when you're not on the show, we're often talking about you, about some project that
- 4:16you're doing, some pet that lives in your IDE or some comic sans font using, all sorts of
- 4:22fun things.
- 4:23Yeah.
- 4:23Rumors of a golden jacket somewhere.
- 4:25Yeah.
- 4:26Well, I didn't realize how close you were to the golden jacket.
- 4:28That's amazing.
- 4:29We have to work on that.
- 4:30So just give us a quick catch up and then Shane, you can introduce yourself.
- 4:34What have you been up to?
- 4:35Anthony?
- 4:35Have we spoken?
- 4:36Yeah.
- 4:36Anthony, have we spoken since you moved to Microsoft?
- 4:38I think we have.
- 4:40I can't.
- 4:40I'm not 100% sure, but let's assume we haven't.
- 4:42Tell people about what you're up to these days.
- 4:44Yeah.
- 4:44So I'm kind of working on advocating for Python within Microsoft and then working on advocating
- 4:51Python outside of Microsoft as well.
- 4:53So I'm still doing a lot of open source work, but then within Microsoft, I guess, trying to
- 4:57integrate Python more into our products and stuff like that.
- 5:01And also get the Python community and things like that more into how we work and find out
- 5:07more about how Python is being used across the company and how we can do better as well.
- 5:12So I've been focused on performance and security.
- 5:16They're kind of two things I'm always interested in, but also like modern Python applications and
- 5:21how they kind of come into play as well.
- 5:23So yeah, so many things I couldn't possibly list them all over the last, the first year I've
- 5:28been at Microsoft for over a year now.
- 5:30And I made less than it was like 50 things I think I'd done in the first year.
- 5:33But yeah, it's been a whirlwind, but really fun.
- 5:36It has.
- 5:37And you just came back from PyCon.
- 5:38I want to give us a quick report from being on the scene.
- 5:42Did I see you on the big screen, big stage giving a talk there?
- 5:45Yeah, it's my first time doing that.
- 5:47That was fun.
- 5:47Awesome.
- 5:48Congratulations.
- 5:49Yeah, it's terrifying.
- 5:50Yeah, so I gave a short update on behalf of Microsoft.
- 5:54I was also in the diversity and inclusion.
- 5:57I'm on the diversity and inclusion work group at the PSF.
- 6:00And we had like a panel discussion on the stage.
- 6:03And then I also gave a talk, like a full talk at PyCon.
- 6:06What was your talk on?
- 6:06It was on performance anti-patterns.
- 6:09Yeah.
- 6:09And that's it from your Perf Lint project?
- 6:12Yeah.
- 6:12So I basically gave background to the performance Lint project that I've been working on and
- 6:17what things I'm looking for in code and why they slow it down.
- 6:20And then just trying to demonstrate what the difference is to people on 3.9 or 3.10.
- 6:25So like a simple one line code change can make 60% difference in terms of how quickly the code runs.
- 6:32And then you can get into the debate again with people that no list comprehensions are just loops.
- 6:36They don't make it any faster.
- 6:37You're like, okay, can we run the benchmarks again?
- 6:40And let's have another.
- 6:41Yes, that's great.
- 6:42So that's good work.
- 6:43Last thing, what's the status of Perf Lint?
- 6:47Is it a thing people are using already?
- 6:49Is it still under development?
- 6:50Yeah, it's definitely very early beta.
- 6:52It raises a lot of false positives at the moment.
- 6:54But it's raised some really interesting things on production code bases that I've run it against.
- 6:59So for example, our serverless platform is Azure Functions.
- 7:03That's all.
- 7:04The Python serverless is all written in Python.
- 7:07And it uses gRPC for communication.
- 7:10So I'm actually running the performance linter against that code base to look at ways that we can make it faster.
- 7:16And there's a list of stuff that I'm working through with the engineering team.
- 7:20So yeah, trying to put that to proof instead of just making it theoretical.
- 7:24That's a really good test case, actually.
- 7:25And performance, if you can improve performance of the fabric of the cloud,
- 7:30then you've made it better for everyone, right?
- 7:32Yeah.
- 7:32So there's a couple of loops I was looking at,
- 7:35which probably get executed hundreds of millions of times a day.
- 7:38So I'm like, okay, what if I can improve that by like 10%?
- 7:41Then that's going to make a big difference.
- 7:42Yeah, absolutely.
- 7:43Awesome.
- 7:44Well, it seems like you're having a good time there.
- 7:46I'm happy to see you've found a new home.
- 7:48Yeah.
- 7:48Yeah, indeed.
- 7:49Shane, welcome to the show.
- 7:50Tell people about yourself.
- 7:51Thanks.
- 7:51It's a hard act to follow.
- 7:53I know.
- 7:53I did perf at my last job.
- 7:54So I appreciate any perf improvements.
- 7:57So yeah, I've been at Microsoft now six years.
- 8:00It'll be six years in the summer.
- 8:02So in about a month or so.
- 8:03And it feels like some days it's six days.
- 8:06Some days it feels like 60 days.
- 8:07Others it's 60 years.
- 8:08So yeah, what do I do at Microsoft?
- 8:10I run an end-to-end and developer experiences team for Azure inside of DevDiv.
- 8:16We do work closely with Anthony and other folks on his team too around just finding out what is hard about running Python and the other languages on Azure, on our tools, VS Code, Visual Studio, and how to get your code on the cloud and all the things that come along with it.
- 8:35Everything from docs to the actual components, the services, and what's that full story and kind of where are those pain points.
- 8:43And then working with those service teams to find out what makes sense to you, what feels like a Python developer should feel.
- 8:51One of the early things that Anthony brought forward was, these are great.
- 8:56It's great that we have logs, but it's not how I want to see logs, right?
- 8:59So I think that, you know, that makes sense.
- 9:01And that's the, again, like you talked earlier, that's the fabric of, you know, a developer.
- 9:06Like I want to, when something goes wrong, we want to fix, you know, fix what it should look like so I can find that problem fast.
- 9:12And those are types of things that we dig into and report up and help solve on our team.
- 9:16Yeah, there's this story of when Scott Guthrie was put in charge of Azure.
- 9:21Scott Guthrie being the guy at Microsoft, who was really responsible for a lot of the developer experience and took a bunch of the people on the team and had them all sit down and say,
- 9:29okay, get an app on Azure.
- 9:31And it was apparently a real struggle.
- 9:33A lot of the people didn't succeed.
- 9:34And it was like, this is the problem.
- 9:36We need to fix this.
- 9:37And I think that made it a lot better in some ways.
- 9:40But it sounds to me like you're kind of doing a microcosm of that with Python, with the two of you.
- 9:45Yeah.
- 9:45And we do it for many, you know, for every type of developer, every language stack in Python is important to us for, you know, the very reasons that like Anthony mentioned, like some of our core components are actually written in Python, right?
- 9:57And we want the, we appreciate that part of what we're doing and how those applications are written.
- 10:03And again, the perf.
- 10:05And that's a very classic story that you bring up because it's often referenced and probably a core reason why my team exists now does because we still have, you know, we have to solve those problems.
- 10:15Yeah, sure.
- 10:16Well, it's like we said, it's fabric, right?
- 10:18And if the fabric is scratchy or itchy, you don't want to wear it.
- 10:21And that's a really big problem, right?
- 10:23You want to make this as smooth and seamless for people to get it right without bouncing off the walls too badly.
- 10:29Yeah, for sure.
- 10:29For sure.
- 10:30Now, we're going to talk about this project that you all are working on, which is super exciting about structuring Python applications and deploying them to Azure.
- 10:38Before we do though, you know, there's some other interesting folks working with you at Microsoft these days.
- 10:45A lot of core developers, like Microsoft's doing a lot of stuff with Python these days in terms of the number of core developers.
- 10:51I mean, obviously, you know, taking over GitHub is like a big step into the whole open source steps that you're all taking.
- 10:59But, you know, the sort of the direct contribution to Python is super interesting.
- 11:02And the most significant one, I guess, that we could talk about is when was this?
- 11:07A little while ago, we had this big announcement that back in 2018, Guido Van Rossum retires as BDFL.
- 11:16And that was it.
- 11:17The steering council was created.
- 11:19Governance thing was up in the air, but then figured out and seems to be really nailed.
- 11:23And then hung out at home for a while.
- 11:25COVID hit.
- 11:26You couldn't really travel, do too much.
- 11:27He's like, you know what, I kind of want to go back and do some interesting stuff.
- 11:30So now Python creator Guido Van Rossum joins Microsoft and, you know, talk to him about that some and whatnot.
- 11:37But still, very interesting.
- 11:38You guys are working with him.
- 11:40Most recently, I spoke to him and Mark Shannon about the Shannon plan and making CPython five times faster.
- 11:47So, you know, Anthony, you want to give us sort of an update on the stuff you see going on?
- 11:51I mean, I know you might not be like directly involved.
- 11:54Yeah, we were actually testing.
- 11:56And doing some of the PyCon.
- 11:58So at the Microsoft booth, so the team that they're talking about, so Guido, Mark Shannon, there's now seven people on that team.
- 12:06All core developers are working full time.
- 12:09Apart from Guido, Guido is part time.
- 12:11But all the others working full time on the Shannon plan and a whole bunch of other concepts.
- 12:15And what they're doing is basically making changes to see Python core to make it faster.
- 12:21Targeting Python 3.11, which will be out in October this year.
- 12:263.12 and 3.13.
- 12:29Some of the ideas are actually penciled for 3.13.
- 12:32Right.
- 12:32This is like a five-year plan that Mark had laid out of.
- 12:34If we could make it 1.5x better each year, compounding is good and we'll get fast.
- 12:40Yeah, exactly.
- 12:40So some of the fruits of that are actually coming out in 3.11.
- 12:44So we were actually doing some live benchmarks and stuff at PyCon on different workloads and things like that.
- 12:50I'm seeing 25% performance gain on most workloads, which is awesome.
- 12:55And in some cases up to 60%.
- 12:57So it depends very much on what your workload is.
- 13:00But yeah, that's 3.11.
- 13:02But I think some of the bigger changes are coming in 3.12.
- 13:05So basically, there's a core team of people working full time now on CPython itself.
- 13:11And not a fork of CPython, they're working directly on CPython with the core development team.
- 13:16Right.
- 13:16As amazing as the stuff that was done over, say, like Cinder and Instagram, right?
- 13:21Really interesting stuff, but it was kind of like, we forked it.
- 13:24Here's a sort of interesting thing we built.
- 13:26Take it or leave it.
- 13:27Take some ideas.
- 13:28Off it goes.
- 13:28It's really different to say where like the next time you just apt upgrade or brew, upgrade your Python, it just gets better.
- 13:36Chocolatey upgrade, however you do it, right?
- 13:37Yeah, definitely.
- 13:38So yeah, the 3.11 changes already, I think, could benefit everybody.
- 13:42And getting people onto the newest version of Python is definitely going to help everyone in the long term anyway, because it's got a list of other cool features.
- 13:48It's pretty remarkable that after 30 years, you can make one of these big step changes of that significant of a performance improvement.
- 13:57Yeah, definitely.
- 13:57Yeah, it's great to have a dedicated team working on this, but I mean, they're not the only people working on it.
- 14:02There are engineers from all over and other core developers working on contributions and stuff like that.
- 14:07But it's good that we can sponsor a full-time team to work just on this specific area.
- 14:12So Guido is kind of coordinating that.
- 14:15And a lot of the ideas come from Mark Shannon's plan that was on the podcast last year.
- 14:20Do you know any of the story around like the no-gil type of stuff?
- 14:24Yeah.
- 14:24There was Eric Snow's sub-interpreters.
- 14:27There was like Sam Gross' actual no-gil stuff.
- 14:30Yeah, there was actually an open space at PyCon on that specific topic and performance in general.
- 14:37And Sam Gross is there, as well as the Cinder team, the team that works on Pyodide, and a lot of other core developers.
- 14:47And that was discussed in detail.
- 14:49I know that from what I've heard, I think Sam Gross is still working on his no-gil branch and trying to break it down into smaller chunks that can be merged, like smaller pieces that can be merged individually.
- 15:01Because there's quite a number of changes in order to get that whole thing done.
- 15:05But it's still carrying on because it was targeted against what was now an older version of Python than as Python continues.
- 15:12Like 3.8 or something like that.
- 15:13Yeah.
- 15:13So Cinder, I think, was 3.8 and they're trying to get it to 3.9.
- 15:17But yeah, as Python continues to march forward, it gets harder and harder to upstream those things.
- 15:22Yeah.
- 15:22Still very exciting.
- 15:24Yeah.
- 15:24So the reason I ask is, you know, the work that Vito and Mark and team are doing is sort of orthogonal to that no-gil work, right?
- 15:31Like this is, a lot of stuff he's working on is just make it run faster single core.
- 15:35And then if you could unlock it for multi-core and each core, like it's a really nice multiplicative thing.
- 15:41You could easily see Python 20, 40 times faster if you could say, well, you can scale it across 10 cores.
- 15:47And it got four times faster.
- 15:48Yeah.
- 15:49So Eric's still working on his sub-interpreters.
- 15:51Mark is conceptually looking through a JIT specification.
- 15:55And they're working through specialized compilation as well at the moment, which is partially coming out in 3.11, but then more of that coming out in 3.12.
- 16:02Amazing.
- 16:03So yeah, it's going to just leaps and bounds, I think, in terms of performance difference.
- 16:07That's so exciting.
- 16:08Last thing to ask on this topic, and then we'll get to the main topic.
- 16:11Pidgin.
- 16:12Pidgin is somewhere involved in this performance thing, your JIT thing that we've had you on the show before to speak about.
- 16:17And so is that involved in any way, or is it sort of a parallel story?
- 16:21Yeah, I'm sharing some of that with the team.
- 16:23So things that I learned in Pidgin that worked, what made a difference, and especially in the JIT, like where there were gains to be made.
- 16:31My desire, really, is that the learnings from Pidgin can be part of the future of CPython, and then Pidgin isn't required.
- 16:38So if CPython gets its own JIT, and if some of the other stuff that Pidgin could do was part of CPython, then I think that's a win-win, because you don't have to install something separately.
- 16:48If you just get the performance gains out of the box, then that's a win for everyone.
- 16:52Yeah, absolutely.
- 16:53Cool.
- 16:54Well, that's really encouraging to hear all those improvements coming.
- 16:58Awesome.
- 16:58Thanks.
- 16:58Well, let's start off our conversation here by just talking about deploying to the cloud, right?
- 17:05I mean, your goal really is to make deploying to Azure awesome.
- 17:09Yeah.
- 17:10But let's just take a step back and talk about deploying to the cloud.
- 17:14You know, when people talk about deployment, well, let's just say they have a FastAPI, Flask Django, whatever app has a database, they've developed it.
- 17:21And usually it's a huge gap to go from.
- 17:24Well, I got it to work on my machine using SQLite and the tutorial.
- 17:28Now I need it to run.
- 17:30And it all said, well, you need to learn about SSL and servers and Nginx and all these things.
- 17:35You're like, whoa, whoa, whoa.
- 17:36I don't even know Linux.
- 17:38This is like a big step to take.
- 17:42This portion of Talk Python To Me is brought to you by Sentry.
- 17:45How would you like to remove a little stress from your life?
- 17:47Do you worry that users may be encountering errors, slowdowns, or crashes with your app right now?
- 17:53Would you even know it until they sent you that support email?
- 17:56How much better would it be to have the error or performance details immediately sent to you,
- 18:01including the call stack and values of local variables and the active user recorded in the report?
- 18:07With Sentry, this is not only possible, it's simple.
- 18:10In fact, we use Sentry on all the Talk Python web properties.
- 18:14We've actually fixed a bug triggered by a user and had the upgrade ready to roll out as we got the support email.
- 18:20That was a great email to write back.
- 18:22Hey, we already saw your error and have already rolled out the fix.
- 18:26Imagine their surprise.
- 18:27Surprise and delight your users.
- 18:29Create your Sentry account at talkpython.fm/sentry.
- 18:34And if you sign up with the code talkpython, all one word, it's good for two free months of Sentry's business plan,
- 18:41which will give you up to 20 times as many monthly events as well as other features.
- 18:45Create better software, delight your users, and support the podcast.
- 18:50Visit talkpython.fm/sentry and use the coupon code talkpython.
- 18:57How do you guys, Shane, how do you think about sort of the spectrum of options and how people are doing it?
- 19:04It's interesting because when you're creating that, you know, on your own machine, that's the environment, right, that you have to worry about.
- 19:11And even when we are deploying to on-prem machines, at least we could walk over and touch the, you know, for you rack that was there.
- 19:19We knew kind of what it was running on.
- 19:21Right.
- 19:21And a lot of times you plugged into, somebody had a database for you.
- 19:24Yeah.
- 19:25You ask them to create the database.
- 19:27Right.
- 19:28They ask you, you plead for a database to be set up and they give you a connection string and then that's that, right?
- 19:34You know, here's your connection string and you're on your way.
- 19:37I think the thought of now is, you know, how do I set this?
- 19:41How do I provision it?
- 19:42How do I deploy my code to the stuff that I've now provisioned there?
- 19:48How do I make all the connections between my front end and my middle tier and my, my backend stuff?
- 19:55How do I secure that with all of my environment variables and connection strings and, you know, monitoring is there.
- 20:02I mean, then how do I just, you know, as a developer for me, I go, that's a great, I want to do that one time.
- 20:08And then really, I just want to change my code and check in my code.
- 20:11Right.
- 20:11I just kind of want it to run.
- 20:13Yeah.
- 20:13That's for me.
- 20:14That's, I want to get to that point.
- 20:16And I think if, even if I have a very few amount of components, I've had meetings at companies that lasted three or four weeks, just talking about how are we going to set all this stuff up?
- 20:26You know?
- 20:27And the promise of the cloud is, hey, we can do this super fast.
- 20:30And sometimes that's not so much true.
- 20:32You know, it's still very challenging.
- 20:34Yeah.
- 20:34Previously it was, I need a server in our data center to be provisioned and we got to order it from Dell or wherever and wait for it to go.
- 20:42And now it's really easy to go to the cloud and get it, but there's a lot of decisions to make.
- 20:47Is it, are we getting VMs?
- 20:49And then it's my job to run shell scripts to set up Nginx and other things.
- 20:54How do I scale?
- 20:55What's the topography of that?
- 20:57How do I set that up for possibly what if we need to scale the web end or whatever?
- 21:01Maybe we use Docker, maybe we use a platform as a service, right?
- 21:05Like that could be a long conversation because ultimately it's somebody's responsibility.
- 21:09If it doesn't, if it doesn't work out right, they're going, you know, you're going to have to come in on the weekend and fix it.
- 21:15Yeah.
- 21:16Or be at least responsible to make sure it keeps running.
- 21:18Right.
- 21:18Yeah.
- 21:18Who do I call when it breaks?
- 21:19Yeah, exactly.
- 21:20Okay.
- 21:21So where are you seeing people who you're talking to a lot going?
- 21:25I mean, we've got, I think on one far end, like at the very far end, like if you turn it to either negative one or 11,
- 21:31depending on which side you consider this to be on, bare metal.
- 21:34That's very rare these days, but VMs and then Docker, Kubernetes, platform as a service, maybe, maybe some more functions.
- 21:42Yeah.
- 21:42Yeah.
- 21:43Functions live in there.
- 21:44Yeah.
- 21:44VMs.
- 21:44Usually 100% alone, but.
- 21:45I think VMs are still very popular with, with some companies who are just trying to get to the cloud.
- 21:51Right.
- 21:52It's very easy to kind of park your car in somebody else's garage.
- 21:55Right.
- 21:55I think that's okay.
- 21:57It's there.
- 21:57Well, it's, yeah, it solves the biggest problem is how do I get a reliable internet connection that's fast and a server and network infrastructure that I don't have to take care of.
- 22:05Yeah.
- 22:05I think those are still, it's still very, it's a very viable option for some folks.
- 22:10The PaaS option is, again, most companies can still run a very sophisticated system on PaaS.
- 22:18The one thing that I'm seeing right now is that companies are wanting to, in small, even small companies, or even they hear Kubernetes, they hear the promise of it.
- 22:28It's scalability, it's responsive, it's self-repairing.
- 22:30Zero downtime.
- 22:31Yeah, no downtime.
- 22:32Scale to zero.
- 22:33Like all the, all the buzziness that comes with it.
- 22:37And, you know, there's the memes that go around with, you know, the tiny box on a tractor trailer.
- 22:42Like I put my blog on Kubernetes.
- 22:44You don't need it, but everybody wants it and they're not sure why.
- 22:48And then it's just cost prohibitive in both manpower and management and cognitive load and all of the things.
- 22:56So there's that aspect of it.
- 22:58We want to find a place that is somewhere in between.
- 23:00Like what if I could have all the promise of Kubernetes, but not have to learn Kubernetes, right?
- 23:05And that's another thing that we're talking about with things like Azure Container Apps.
- 23:09Right.
- 23:10And being able to have kind of best of both worlds.
- 23:13Right.
- 23:14And looking forward, I don't want to get into it yet, but just to give people a preview is you guys have built a CLI tools for Python and some templates that kind of help people realize that goal.
- 23:24Much more quickly than just, all right, well, I guess I'm going to set up a Kubernetes cluster and nodes and all that kind of stuff.
- 23:31Yeah.
- 23:31Yeah.
- 23:32Okay.
- 23:32Well, Docker is an interesting one, right?
- 23:35To do Kubernetes, you got to do Docker, right?
- 23:37Or you got to do containers at least.
- 23:39There's the look how easy it is to run Docker.
- 23:42I just, you know, get the image, Docker run, off it goes.
- 23:47Unless you've got multiple tiers like many apps do, right?
- 23:51I've got like a database layer and maybe a background worker service for like emails and other long running jobs.
- 23:58And then all of a sudden coordination that becomes really hard.
- 24:01Yeah.
- 24:01I'd say that like kind of where people start off with containerization is the Python app itself.
- 24:08So the Python code, whether that's in like a Whiskey application or using ASCII or something.
- 24:15So that's like Django, Flask, FastAPI.
- 24:18So like running that in a container is a great place to start.
- 24:22But hardly ever is that the whole application.
- 24:24You know, just Flask and Django alone, you need some sort of web app at the front end, like a HTTP server, like Nginx or something.
- 24:32And then you need the distribution to Whiskey.
- 24:35So you need Gunicorn or Yuvicorn or Hypercorn or one of the other corns to connect between the HTTP front end and the back.
- 24:43And then once you've got that in place, you're like, okay, I need to configure my SSL certificates and my DNS and stuff.
- 24:50So you can do that.
- 24:52But I think people start to try and try to jam everything into one container.
- 24:56Yeah.
- 24:57And that's where it kind of gets.
- 24:58Until it absolutely explodes.
- 25:00You're like, all right, it just won't take it anymore.
- 25:01Right.
- 25:02But preserve that.
- 25:03Just call run on it as long as you can.
- 25:05Right.
- 25:05Yeah.
- 25:06People I imagine are trying.
- 25:07Yeah.
- 25:07Yeah.
- 25:07And they're not supposed to be persistent.
- 25:09Like, you know, containers are supposed to be immutable, but you can attach storage to them, which is where it gets tricky with databases.
- 25:16Because really running something like Postgres and Docker, you can, but like, it's not going to be particularly fast.
- 25:24And you've got all these extra challenges of if the image stops, then what did you just lose?
- 25:30So, yeah, I think containerization is great to get some of the Python environment complexities.
- 25:36Like, you know, you've got a virtual environment to configure.
- 25:39How is that installed?
- 25:40What version of Python?
- 25:41So, there's like all the bits of Python that are specific to getting the Python app running consistently in one place and another.
- 25:47So, Docker is great for that.
- 25:49Containerizing is great for that.
- 25:51But you often find yourself needing more than one container, which is where things start to get complicated.
- 25:56Because then it's like, okay, I've got Redis in there.
- 26:00I've got, I want to run Nginx in one container.
- 26:03I want to run my app in another.
- 26:05So, then how do you like coordinate all that stuff?
- 26:09Right.
- 26:10And just how do I keep them connected, right?
- 26:13Because in regular non-Docker world, you just say my Redis string connection string is this.
- 26:19My database connection string is that.
- 26:21Nginx says I route traffic over either this Unix socket or through this HTTP socket.
- 26:28But those are not stable as these Docker images come and go separately, right?
- 26:34It gets tricky to connect them still.
- 26:35Yeah, there's a connection and the coordination of it.
- 26:38And things like Docker Compose, I think, helps with that there.
- 26:42Anthony mentioned a very valid point around databases and containers.
- 26:47I think when container development started to kind of hockey stick a little bit, I can't tell you how many times I answered the question, should I run my database in a container?
- 26:55And I was like, well, no.
- 26:57And then it was like, well, why not?
- 27:00And I was like, okay, here's the 15 reasons why you should never do that.
- 27:03Yeah.
- 27:03And I go to my framework and write in the tutorial that shows me how to run Postgres.
- 27:07Yeah, it was more of a like, what happens when it dies?
- 27:11You know, and they go, oh, no, I mean, I lose my data.
- 27:14Yes.
- 27:14It says don't do that.
- 27:16But they serve very well for, you know, emulating those big cloud managed services like Redis and like, you know, Postgres and stuff like that.
- 27:25They would typically run in a managed service instead of trying to have your entire world, if you will, running on your local machine.
- 27:32And then the other part of that is how many is too many?
- 27:35If you, you know, the microservices type of, you know, scenario of are you going to run 200 individual containers on your local machine?
- 27:44There is a cap where it's just too much, you know?
- 27:48Yeah, yeah, for sure.
- 27:49And we're even seeing some sort of swinging of the pendulum, I guess you would call it, back to articles like, give me my monolith back.
- 27:58Life just got too hard.
- 28:01Now, you know, my personal philosophy, and I'm not suggesting anyone else has to adopt it.
- 28:06But when I think about these things like microservices versus monoliths and Docker and Kubernetes versus more simple things is I try to keep the complex parts in the areas that I'm really good at and not push them to areas that I have a little experience with.
- 28:20Like, I don't have a great DevOps background, so I don't want to push tons of the complexity to DevOps and keep the code simple because I can handle complex code, but I can't handle complex DevOps.
- 28:29Yeah.
- 28:29Not right now anyway, you know?
- 28:31So for me, I kind of try to think of the balance of like, what works for me, you know?
- 28:34I literally saw an example where somebody was saying, I manage all of my configuration in its own repo, and then that sucks into my DevOps pipeline.
- 28:44I was like, what is happening?
- 28:45I'm not even going to talk about that.
- 28:49You know, I'm sure that works for you.
- 28:51But like you said, unless you really understand that level of, you know, complexity, you know, it's no thanks.
- 28:58If you specialize in that area, then maybe that's exactly your secret sauce.
- 29:03Yeah, yeah.
- 29:03But if you don't, don't like see someone else be doing that and go, I should just do that because it's working for them.
- 29:09Like maybe, but it's not a clear, I should just go that way, I think is the story.
- 29:13Yeah, and I think just like in a coding world, like we can use things like, you know, interfaces and polymorphism to the nth degree.
- 29:20And for a simplistic programmer, you know, examples, they're going, why are you doing that?
- 29:25Because I can just do it in a single file.
- 29:27Thanks.
- 29:28Exactly.
- 29:29Why do we have like dependency injection registries when it's 50 lines long?
- 29:33Like I really just don't.
- 29:34Yeah.
- 29:34It's just not.
- 29:35It's hello world, man.
- 29:36Yeah, exactly.
- 29:37Exactly.
- 29:38It's just a manuscript script.
- 29:39Right.
- 29:39All right.
- 29:40So maybe that probably sets the stage a little bit for the work that you two have been doing in this project we're going to talk about.
- 29:46But one more predecessor, bit of history.
- 29:49So one of the notable things about the Azure CLI, that is the CLI that everyone uses when they're not working in the crazy, belated, very full management portal, is built in Python, right?
- 30:02Yes, it is.
- 30:03Yes.
- 30:03But it's not that that actually makes any difference for Python people.
- 30:06It's just an interesting detail.
- 30:08But that one is not focused as much on helping developers get their code out as maybe helping IT DevOps side of the world, DevOps on Azure.
- 30:18Right.
- 30:18I would say its primary goal is referred to as kind of a management ops plane functionality.
- 30:25There is some capabilities in there for, you know, pushing up simplistic, you know, web applications.
- 30:31There's a web app command where I can kind of get a simple page up.
- 30:36And there's some static web apps capabilities within that command.
- 30:39But when you get into, you know, a full kind of job to be done for a developer focused type of activity that does not serve that type of persona.
- 30:50Sure.
- 30:50All right.
- 30:51Well, that brings us to your project.
- 30:53Does your project have a name?
- 30:55Just so people know, at the time of us talking about this, this is not yet released.
- 30:59Yeah.
- 30:59But at the time people are going to be listening to it, it will be released.
- 31:03And so.
- 31:03Yeah, sure.
- 31:04I'm kind of behind the scenes.
- 31:05Maybe I can pull up your screen here and start from there.
- 31:09We'll call it the like lowercase Azure developer CLI.
- 31:13Okay.
- 31:14Because if it's uppercase, I think that means it has a name.
- 31:16So we'll say it's the lowercase Azure developer CLI.
- 31:20It's a standalone install.
- 31:21Command is AZD or AZD, depending on where you're from.
- 31:26Don't don't alienate Anthony.
- 31:28Yeah.
- 31:28Much of the other rest of the English speaking world.
- 31:31Yeah.
- 31:31Everywhere but the US.
- 31:33And its primary goal is to, you know, make it easy for developers to get up and running
- 31:40with both infrastructure and code, you know, in Azure based on at least initially, we've
- 31:46got some out of the box templates to help establish kind of a getting started kind of to do app,
- 31:54which at least in this particular example, we have a to do application that's got a Python
- 32:00FastAPI middle tier with a React JS front end.
- 32:06And then the back end is supported with Azure Cosmos DB with Mongo API.
- 32:12Right.
- 32:12So the way it's going to go now is it will have the Mongo API, but Mongo, the Mongo API can be pointed
- 32:19at Cosmos DB, your document database in Azure, right?
- 32:22Correct.
- 32:22Correct.
- 32:23Correct.
- 32:23Let me ask another really quick question on that.
- 32:26What's the interaction with the Mongo API?
- 32:30Like, is there an ODM they're using?
- 32:31Is it just PyMongo or rather motor or something like that?
- 32:34Yeah.
- 32:34This app was built within ODM.
- 32:36It was built with Beanie.
- 32:37I love Beanie.
- 32:38I've, I converted the talk Python.fm and Python bytes.fm over to it.
- 32:42The really big one left for me is the training site, which is massive, but it's, it's getting
- 32:47some Beanie on it as well.
- 32:48Yeah.
- 32:48So for like a fully async ASGI app on FastAPI, Beanie is a great option because it's
- 32:54like async from end to end and it uses the async motor client for talking to Mongo.
- 32:59Yeah.
- 33:00So yeah, it's super fast.
- 33:01So that's what we've built for the to-do app, which is like the demo application.
- 33:08This portion of talk Python to me is sponsored by NordVPN.
- 33:11I've been a pain and happy NordVPN customer for over a year now.
- 33:16So when they approached us to become a sponsor of the podcast, I was excited because it's
- 33:21a product I've already been recommending.
- 33:23I use NordVPN almost universally throughout the day on all my devices, whether it's my
- 33:28Mac, my iPhone, or my iPad, I enable the auto connect feature and Nord keeps my connection
- 33:34protected and ad free.
- 33:36I'm sure you've heard that VPNs can keep your traffic private on public networks.
- 33:41And that's true.
- 33:42But let me tell you why I use NordVPN.
- 33:44Privacy and malware protection.
- 33:46First, privacy.
- 33:47Ad companies are slowly eroding our privacy.
- 33:50Shadow profiles are being built for you and being built for me by combining tracking scripts,
- 33:55ISP data, and through data brokers.
- 33:57If these were just being used for commercial ads, it'd be one thing.
- 34:01But we've all heard stories about how groups have been targeted to affect negative social
- 34:06outcomes.
- 34:07Think Cambridge Analytica.
- 34:09With Nord's built-in network-wide ad blocking and IP hiding, you'll limit the data that all
- 34:15of these players get to collect on you.
- 34:16What's so sweet about using Nord for this is it works across all of your apps.
- 34:20Not just a browser plugin, but even native apps on your phone can't contact or load most
- 34:26ads.
- 34:27These same ad networks have been hijacked to deliver malware.
- 34:30Nord also includes network-level malware protection as an added layer of safety.
- 34:35And Nord has a great offer for you.
- 34:36Use talkpython.fm/NordVPN to get a massive discount on a two-year plan that includes a free
- 34:43month.
- 34:43Nord is also risk-free.
- 34:45There's literally no risk to you with their 30-day money-back guarantee.
- 34:49Give it a try.
- 34:50And if, like me, you love it, great.
- 34:52If you don't, they'll issue a refund and you can pretend the entire situation never happened.
- 34:57Say no to being manipulated by ad companies and enjoy the free and open internet on all of
- 35:03your devices.
- 35:04Visit talkpython.fm/NordVPN to get your subscription started today.
- 35:09Yeah.
- 35:11So let me see if I can summarize this for folks before we dive into more detail.
- 35:15Basically, you guys have built this full stack-ish.
- 35:19I guess full stack fits.
- 35:20Full stack, FastAPI, document, database, JavaScript front-end app that sort of natively integrates
- 35:28in the ways that you would expect it to in Azure.
- 35:31Not just you can get it up there and get it to run, but it's got different sections.
- 35:36It uses a hosted database.
- 35:38It integrates with CI/CD.
- 35:40It has tests that plug into all those kinds of things and so on.
- 35:43And so you can take that and sort of publish that to Azure.
- 35:46But then, of course, you can just use it as a prototype to say, well, we don't need to do,
- 35:50we need this other thing.
- 35:51So we'll swap out, whatever.
- 35:53Yeah.
- 35:53Right?
- 35:53Something like that.
- 35:54Yeah.
- 35:54I would say there's a couple of key components.
- 35:57You know, we do all of our commands.
- 35:59Again, it's command line based.
- 36:01We focus on a CLI first approach to this for a couple of reasons.
- 36:05A, it feels natural for a lot of developers who kind of are on a terminal constantly, but
- 36:11also allows if VS Code wants to build an experience on top of it, if PyTorch wants to build an experience
- 36:17on top of it, they can, you know, because they just call into those same hooks.
- 36:21But also...
- 36:22Can we consume the CLI as a Python library?
- 36:26Well, that's a good question because we are also looking at making this an extension inside
- 36:33of the core Azure CLI.
- 36:35So we have actually wrapped this as a Python extension.
- 36:38Okay.
- 36:39For them.
- 36:39Interesting.
- 36:40Yeah.
- 36:40I mean, you can always sub process it around all day you want, but...
- 36:43It's written in Go.
- 36:44Okay.
- 36:45Got it.
- 36:45Yeah.
- 36:45So it's A, it's super lightweight.
- 36:47It's like five and a half megs.
- 36:49It's really small.
- 36:50And once you have the binary, you have it.
- 36:53That is one of the true beauties of Go.
- 36:56Yeah.
- 36:56Yeah.
- 36:56The other parts of it, like you mentioned, if there's pieces of this that, of the app,
- 37:01if I back up one section here, is that a lot of the samples that we come across, they are
- 37:07a hello world.
- 37:08They're a very simplistic app.
- 37:10And once you kind of go through the process, when you're all done with it, you're like, okay,
- 37:15this is great.
- 37:15I built my hello world app.
- 37:17Now what?
- 37:18Right.
- 37:18This is an opinionated structure that allows you to swap out components, build upon it.
- 37:25Like I can take out the FastAPI if I want to use Flask or Django or whatever.
- 37:29I can swap that out and do it.
- 37:31Swap in Postgres if I'd like.
- 37:33We have an infrastructure as code.
- 37:35Right now we're using Bicep to do that.
- 37:37And in the future we'll support things like Terraform and other IAC providers.
- 37:41And that's just how we would swap out any of the infrastructure.
- 37:44Right.
- 37:45This particular sample, we are targeting the Azure container apps as a host, as our target
- 37:51host.
- 37:52But we do support paths.
- 37:53And in the future also things like Kubernetes.
- 37:56Yep.
- 37:56And also in terms of the, how cloud native is it?
- 38:00If you don't scroll away just yet, come back.
- 38:02Okay, sorry.
- 38:02Yeah, no worries.
- 38:04In terms of just how cloud native it is, like how much does it reach into all those things?
- 38:09Basically for areas that are interesting.
- 38:12Azure container apps, right?
- 38:14So you've got, Anthony, let me know what this sounds like.
- 38:16You've got maybe an Nginx type of container.
- 38:19And then you've got one that runs uvicorn, FastAPI, Workers.
- 38:25Yeah.
- 38:25There's two containers in this example.
- 38:27But like, yeah, Azure container apps is more where you've got a collection of containers that
- 38:32form an application.
- 38:33Like if you put that in a Docker Compose or something.
- 38:35Yeah.
- 38:36And then we kind of spin those up for you and manage that for you.
- 38:39So you don't have to think of or plan about things like Kubernetes.
- 38:42And it does SSL certificates and DNS and everything else for you.
- 38:47So nice.
- 38:48So you don't have to worry about let's encrypt and stuff.
- 38:50Yeah.
- 38:50Yeah.
- 38:51Does all that for you.
- 38:51So nice.
- 38:52And then that hosted Cosmos DB.
- 38:55Yeah.
- 38:55So Cosmos DB is the document database on Azure.
- 38:59And when you deploy it, you can choose which API you want it to have.
- 39:03You can pick the Cosmos API or you can pick a Mongo API.
- 39:06So if you pick the Mongo API, then you can use your existing Mongo tools and clients with it.
- 39:12Like Beanie and so on.
- 39:14Yeah.
- 39:14Exactly.
- 39:14And that would just work.
- 39:15Okay.
- 39:16And then monitoring.
- 39:17Azure Monitor.
- 39:19This is like Sentry type stuff, right?
- 39:21Like is it up?
- 39:22Is it running into errors?
- 39:23Does it also do performance or just sort of error?
- 39:26Yeah.
- 39:26It will do all of your calls.
- 39:28Basically it does tracing between all of the different containers or different components
- 39:32of the app.
- 39:33You can look at telemetry between those calls.
- 39:35You know, how long is a call taking to the database?
- 39:38You know, you can look at the individual calls, see where the errors are, trace those down to
- 39:42like it was a get call on, you know, the to-dos collection and actually look at those and
- 39:49then introspect those inside of Azure Monitor.
- 39:51So it's pretty detailed.
- 39:52Yeah.
- 39:52That's really nice.
- 39:53Yeah.
- 39:53I use that stuff all the time for my sites, you know, if I run into a problem, probably
- 39:58the first place I go is the actual log.
- 40:00But if it's not super clear right away, I'm like, all right, let's go to the monitoring and
- 40:03see the local variables and see what was going on for real.
- 40:07And then the last one is secrets.
- 40:09Like it is nice to just check in your API keys into Azure and to GitHub.
- 40:15I don't understand why I heard you're not supposed to.
- 40:17No, I understand why you're not supposed to.
- 40:21Yeah.
- 40:21Yeah.
- 40:22The Key Vault is really great in the sense of, yeah, this is kind of, it is the sauce, if you will, where we keep the connection string for the Mongo database.
- 40:31And then within the actual FastAPI app, we can then connect to the Key Vault to pull that out securely.
- 40:39And then really the nice thing about Key Vault is if we need to change it, we can just change that one key and not have to kind of redeploy all the other apps.
- 40:46It's just great.
- 40:46It's just great.
- 40:47And then from a local development story there, we use environment variables to have that locally as opposed to passing it around or keeping it in a GitHub repo, of course.
- 40:59Got it.
- 41:00The apps kind of like built in a way that we said, if we were building a production app, this is how we do it.
- 41:07So like Shane said, it's, it's the example app is opinionated because we've picked how we've configured Python version environments and how I've done the testing and how the ASCII configuration works and stuff like that.
- 41:18But it's done in a way that it's okay.
- 41:20This is a production style web app that we put together.
- 41:24And here's how you would deploy it using this new, the new AZD CLI.
- 41:28So the new Azure Dev CLI.
- 41:30And the other important thing is that you don't have to learn all these new concepts.
- 41:34So it's not like we've said, okay, we've got our own configuration language that we're going to throw at you.
- 41:40And we've got our own, you know, like here's a hundred YAML files you need to write or stuff like that.
- 41:46It's try to keep it as native as possible.
- 41:48So in the Python application, in the web app, then there's a Docker file and there's a pyproject.toml.
- 41:55And, you know, if you want to run the Docker file locally, you can do that.
- 41:59One of the opinions that you're, you're choosing is like use poetry, for example, right?
- 42:02Yeah.
- 42:02Yeah.
- 42:03Yeah.
- 42:03So using poetry to manage the dependencies and make those, I guess, pinning dependencies and making them between creating things like lock files.
- 42:11But also if you work on the repo, the demo repo in VS Code, you know, you can run and debug the app locally as well.
- 42:19So you don't have to figure out all the extra complexity.
- 42:21So, yeah, we kind of really thought, okay, let's write, you know, a production type application using all the normal tools we would use,
- 42:29which is like Docker files and pyproject.toml requirements files.
- 42:33And then on the front end app, like, you know, it's in React.
- 42:37So we've got our normal project and Node.js configuration and stuff.
- 42:41Right.
- 42:41All the npm stuff.
- 42:42Yeah.
- 42:42And then what would the, what would the developer need to describe that in a way that then can be deployed up to the cloud and trying to make that as simple as possible?
- 42:50Sure.
- 42:51Yeah.
- 42:51So Shane, you spoke about Bicept.
- 42:54Right.
- 42:54As a way to get your things up.
- 42:55And I think it might be worth touching a little bit on the Bicept story.
- 42:58Sure.
- 42:59I mean, that's usually arm wrestling for me, but I'm thinking, no, no.
- 43:03Bicept, Bicept is, it's like Ansible or Terraform.
- 43:06Yeah.
- 43:07But it's, it's one of these, it's kind of a Azure native thing, right?
- 43:11For DevOps.
- 43:12Most Azure DevOps folks would understand if we said, hey, what's your arm template look like?
- 43:18Azure resource manager.
- 43:19Management template.
- 43:20Yes.
- 43:21Yeah.
- 43:21Management.
- 43:21Lots of JSON, a lot of JSON, thousands of lines of JSON.
- 43:26Not easy to write, read, or kind of understand.
- 43:29Bicept is a simpler format and kind of self-describing almost.
- 43:34So we use that right now to describe the resources that we're going to provision and deploy our app to.
- 43:41And in this particular case, in this template, we have a number of templates, but in this template,
- 43:46we're putting together a container registry.
- 43:49We're provisioning the container apps environments, you know, the web apps, the Mongo database, a lot of things that, you know, if you did those individually, it would take a lot of time to do.
- 43:59So we're doing that all as a part of the one single line command to do that.
- 44:04So we're looking at implementing, you know, other IAC providers like Terraform and Pulumi as well.
- 44:11And, you know, if that makes you happy in your place, you know, we're not hiding anything in what we're doing.
- 44:18We're more of an orchestrator of the tools instead of hiding some secret commands to make all this happen.
- 44:25We like folks to kind of see what the steps are to do it.
- 44:29We're just going to do the steps for you in a single press of the button, press the easy button, you know?
- 44:33Yeah.
- 44:33Yeah, absolutely.
- 44:34Right.
- 44:35That's great.
- 44:35So maybe, Anthony, it would be a good time for you to sort of talk us through some of the code and the projects,
- 44:41because I think that'll give people a sense of what they're getting in terms of what this app looks like.
- 44:47Yeah.
- 44:47So the demo app that we put together has got two main containers on the front end, which is the React.js web app,
- 44:55which is all running under Node 16, and then a FastAPI API, which does basically the middleware between the front end and the database in the back end.
- 45:05So the React.js one is an app that we wrote to demonstrate a lot of functionality and to-do management app, basically.
- 45:14But in terms of the FastAPI app, that...
- 45:17The canonical example that people may try.
- 45:19Yeah, exactly.
- 45:20And the FastAPI one is the one that I worked on with the team.
- 45:24And that's really kind of looking at, okay, if we did a modern Python application, how would we write it and how would we deploy it?
- 45:31And like I said, using poetry for requirements management and stuff.
- 45:35But you could use whatever.
- 45:36This is an example.
- 45:38You don't have to use poetry.
- 45:39But I'm just showing the latest approach and the latest design with the application.
- 45:45And then if you want to swap out or change bits of it, obviously you can do that.
- 45:49So yeah, the project itself has got a pyproject.toml.
- 45:52We're using FastAPI, Uvicorn, and then Beanie is the ODM.
- 45:56And then a nice package...
- 45:58Maybe just tell people real quick about just what Beanie is, just so that...
- 46:02I've had Rumin on the show before, but maybe not everyone knows.
- 46:06Yeah, so if you're working with FastAPI, often you would describe models that the API reads or writes or reflects using something like Pydantic.
- 46:16So these are kind of your data classes.
- 46:18So Beanie basically allows you to write Pydantic style models, data classes, and then read and write those from a Mongo database.
- 46:29So this app is basically written in a way that the to-do list items, the tasks and stuff like that, are all reflected in a models file.
- 46:37And then Beanie does the work of actually putting those in a database.
- 46:41So we have a to-do list.
- 46:43We can also do things like to-do items.
- 46:46And each of those are a document, but they're written in a way that's very similar, basically identical to how you'd write a Pydantic model.
- 46:53Beanie also allows you to...
- 46:55Right, just slightly different base class.
- 46:56Yeah, Beanie also allows you to lazily reflect Beanie models into Pydantic models.
- 47:02So when you're working with FastAPI, you can get all that nice functionality of using Pydantic, but you get a lot of the performance of basically trying to keep it as close to the actual document in Mongo as possible.
- 47:14So yeah, that's one big challenge people have to overcome when they use stuff like Pydantic, which is like, when do you put stuff into Pydantic models?
- 47:25Like if you're reading a thousand rows from the database and you're just going to give that straight to the user, there's no point in reflecting all that into Pydantic and then sending it back out again.
- 47:34Right, doing all the conversions or whatever craziness.
- 47:36Yeah.
- 47:36Yeah, or just slow it down.
- 47:37Yeah, okay, cool.
- 47:38And so this is a really good choice because it matches the native MongoDB API and it matches FastAPI on at least two levels.
- 47:46Pydantic models are all about driving the data exchange and the open API specification, which is fantastic.
- 47:52But then also Beanie is an async ODM.
- 47:56So what you do, it allows you to fully leverage the scalability of FastAPI.
- 47:59I think it's a great choice.
- 48:01It's a nice configuration and it's nice to run as well.
- 48:03It's pretty responsive.
- 48:04And then what we did on the app itself, so in FastAPI, a couple of things that you have to do are configuring cores, which is always fun.
- 48:13And then we've put tracing in the app as well.
- 48:16I just ran into a cores error on just an HTML file I opened.
- 48:21I'm like, there is no server.
- 48:22I can't do cores.
- 48:23Please don't do this.
- 48:24Yeah, it becomes a bit of a challenge.
- 48:27It does.
- 48:28So on FastAPI, we've been doing a lot of work over the last year on a project called OpenTelemetry.
- 48:33It's a cross-company open source collaboration to create basically a tracing and eventing framework across multiple languages.
- 48:44So you can use OpenTelemetry in Go, Rust, Python, and basically install.
- 48:50Does it connect into the thing that Shane was talking about with the Azure monitoring?
- 48:54Yeah, it does.
- 48:55And it also connects into a whole bunch of other monitoring tools.
- 48:58It's not the Azure monitoring library for Python.
- 49:01It is an agnostic library.
- 49:03Nice.
- 49:03Which is, it's got support for FastAPI.
- 49:05It also has support for lots of other Python components.
- 49:10So when you get the actual logging data, for example, if your app crashed or somebody made a request which gave a 500 error, in Azure Monitor, you get the full stack trace and you get all the events that led up to that as well.
- 49:23So it's not just a log file, basically.
- 49:25We're actually putting stuff in the Python app to get all the tracing information.
- 49:28You can also use it to see like performance regressions and like slow pages or slow requests.
- 49:35So in Azure Monitor, you can actually go and see what are like the slowest requests I've had to the application and what was the cause of that.
- 49:41Yeah.
- 49:41And none of that stuff is proprietary.
- 49:43It's all basically using OpenTelemetry, which is open source.
- 49:46But we have a special source is the exporter.
- 49:49So we export OpenTelemetry events to Azure Monitor.
- 49:53Okay.
- 49:53Yeah, this all looks super nice.
- 49:55And the reason I wanted you to talk through this is the project looks really nice.
- 49:59It looks like an app that I would like to use as a starting place for my final destination rather than just, oh, cool.
- 50:07There's a main.py or app.py.
- 50:09It's all just jammed in there.
- 50:11And like, you know, it feels like a good starting point.
- 50:14Yeah.
- 50:14And then, like I mentioned, like debugging is set up already.
- 50:18So yeah, in VS Code, you can either debug the React app or the API, the FastAPI app.
- 50:25And that will run the whole application locally.
- 50:27Does that run just on your local machine or does that like fire up the containers?
- 50:32It just runs on your local machine.
- 50:34So it would run FastAPI locally.
- 50:36I give that a thumbs up.
- 50:37Yeah, yeah.
- 50:38So if you wanted to, for example, debug the front end and it needs to get, just go start the back end and then go debug the front end.
- 50:44Something like that, right?
- 50:45Yeah.
- 50:45Just trying to keep it super simple.
- 50:46Yeah, no, that's good.
- 50:47And then we also wrote tests for both components.
- 50:50So yeah, the ToDo app comes with its own unit tests for FastAPI and then for the front end as well.
- 50:58And then all of that's set up in VS Code.
- 51:01Well, it's all, they're all pytest tests.
- 51:03So if you just want to run pytest over it, then you can.
- 51:05But yeah, asynchronous FastAPI tests are a bit fiddly to set up the first time.
- 51:11So we've done all that as a demo as well.
- 51:12Yeah, this is great.
- 51:13And one area that we haven't talked about yet, Shane, when you deploy this, and we can talk about how to do that in just a second, is that it automatically sets up, at least with one of those CLI commands, CI, CD, continuous integration and continuous delivery or deployment.
- 51:29And these tests that Anthony's talking about, these automatically just like start running on check-ins for you, right?
- 51:36Like that whole lifecycle is connected here.
- 51:39Yeah, it's, Anthony, I don't know if you could maybe scroll up and touch on the GitHub actions that are included there.
- 51:46So with every template that we're providing out of the box, we include the GitHub actions in order to run those.
- 51:54So on the builds, we'll actually provision, deploy, and we would include the test run as well as a part of the container build.
- 52:03If it's targeting containers or if it's paths, we would have the test command, which is not in this particular one.
- 52:09But it would be like AZD test would be the command that would run.
- 52:13It would run through all the testing that are in there depending on the platform.
- 52:17Yeah, that's great.
- 52:17So yeah, it gets us to that point.
- 52:19Like I said, as a developer, I just want to check in code and know that my tests are going to run.
- 52:25If they pass, it deploys to the environment that's specified.
- 52:28And it gets me to a happy place as a developer, you know?
- 52:32Right, right, right.
- 52:34You don't have to know about this stuff.
- 52:35And, you know, to some degree, that might not be 100% true, right?
- 52:38Like if your code is running somewhere, you need to have some level of understanding, even if you don't have to directly touch it.
- 52:45But I think one of the big benefits is for a lot of people, you can start running there and you can kind of grow into a better, deeper understanding.
- 52:52You don't have to like swallow the whole, I learned all of the Linux configuration all in one shot just to get it to even start, you know?
- 52:59Yeah.
- 52:59And I think it's important to mention a couple of times is that even though we have a command, like in order to get this whole architecture that Anthony just walked through,
- 53:09if I wanted to get this into Azure, I would just run AZD up and then pass in the name of the template repo, you know?
- 53:18And it would then deploy all of that and run it for me.
- 53:22Yeah, yeah.
- 53:23Let's talk about like, we've got the app.
- 53:25Anthony talked about running and developing it locally.
- 53:27Right.
- 53:28Now what?
- 53:28Like I actually want to get it up and running.
- 53:30I want CI, CD.
- 53:31I want all the things.
- 53:33Yeah.
- 53:33So if I started from nothing, if I was just opened up, you know, VS Code or my command line or whatever I'm in in a terminal,
- 53:40I could just run AZD up and then pass in a --template.
- 53:44And in this particular case, it would be like to do dash Python, ACA dash Mongo.
- 53:50Right.
- 53:51And that would clone that repo.
- 53:53It would then start to provision those resources on Azure, you know, based on your login to Azure and then use the BICEP infrastructure definitions to create that target host if it's PaaS or Azure container apps.
- 54:07And then build and deploy, you know, the API, the front end, and then make all those connections and so on as we walk through how that's all put together.
- 54:16Right.
- 54:16And so it's worth thinking about that, those BICEP DevOps commands and configuration, if you want a slight variation of what this gives you, you change the BICEP and then AZD up just uses your slight variation, right?
- 54:29Well, yeah, exactly.
- 54:30And, you know, one of the services that is very common to use, you know, in our, in our apps nowadays is Redis.
- 54:35Like if I want to add Redis and make a couple of changes, I could just put that definition in my BICEP code, add in the environment variables that are necessary to, you know, expose in my app and call up.
- 54:47And then we would then push them into Key Vault, you know, provision the service, redeploy the code.
- 54:53And hopefully if we typed it all right, it would happen right.
- 54:56Right.
- 54:56So that would be the way to do that for sure.
- 55:00If I run the AZD, you know, pipeline command and help that establish my GitHub repo and kick off those workflows in the GitHub actions.
- 55:09At that point, I could just make those changes to the BICEP files and check those in.
- 55:14And then the workflow would kick off that process for me.
- 55:16That's cool.
- 55:16Can I start from code and then do this?
- 55:19Or do I do the template to create the code and the GitHub repo?
- 55:22Like if I already have a GitHub repo, for example.
- 55:24Yeah, that's a good question.
- 55:25And we have some documentation and walkthroughs on how to, what we call Devify your project.
- 55:32And basically it will walk you through how to set up that an infra folder.
- 55:37That infra folder will contain the BICEP definitions.
- 55:41And we've got an Azure.yaml file, which will hold a couple of the kind of naming structures that we have as an opinionated way to name things.
- 55:50And then also set up that target host.
- 55:52Again, it's that PaaS or is it, you know, app service or is it container apps or AKS?
- 55:57So a little bit of setup.
- 55:58And then you can start using AZD up or AZD deploy.
- 56:02You just want to deploy the app to then, you know, take your code and push it onto the platform.
- 56:08Okay.
- 56:09That sounds really good.
- 56:10What about the, talk about the continuous delivery part.
- 56:14So I've got this created.
- 56:15I've got a GitHub repo.
- 56:16It's up and running.
- 56:17How do I associate a domain name, by the way, first?
- 56:20Well, the domain name, we would push it onto the, obviously onto Azure and then create that.
- 56:25Like your app.
- 56:26Yeah.
- 56:27Do it UID.Azure or something like that.
- 56:29Blah, blah, blah.
- 56:30Azure websites.net slash la, la, la.
- 56:32Yep.
- 56:32Then that would be part of that configuration inside of Azure portal or through the management
- 56:39plane where you'd actually kind of go through of associating your domain name with whatever
- 56:45your entry point is.
- 56:45In this case, it's going to be the React front end, right?
- 56:48So I would go into that particular app service and set that up with your DNS and such there.
- 56:53Yeah.
- 56:53You probably want to, you probably want the API if you want to surface an API out of fast
- 56:58API.
- 56:58Yeah.
- 56:59And then you want the React front end, obviously, for most people.
- 57:02Yeah.
- 57:02And you could add, if you want to get into things like that, one of the pieces you could
- 57:06add is things like Azure front door or, you know, API management or something like that
- 57:11in front of those components too.
- 57:13Okay.
- 57:14Well, that step is like a separate step.
- 57:16Yeah.
- 57:16You go in there and you configure it because how often do you really want to have a thing
- 57:20messing with your DNS?
- 57:21Yeah.
- 57:21As little as possible.
- 57:23It's a one-time shot.
- 57:24That's all I want to do with.
- 57:25Yeah.
- 57:25Please wait 24 to 48 hours for this to propagate.
- 57:28Like, no.
- 57:29You know, it's funny.
- 57:30I haven't had a DNS chain, knock wood.
- 57:33I haven't had a DNS chain to take longer than a few minutes nowadays, but.
- 57:37Yeah.
- 57:38It is a lot better than it used to be.
- 57:39I've done it.
- 57:40I just changed all of our email and stuff around and there's been a lot of MX records and the
- 57:46like verification keys and yeah, it's.
- 57:48No matter how many times you do it, you're sure you did it wrong.
- 57:51Yep.
- 57:51That's for sure.
- 57:52Yeah.
- 57:53All right.
- 57:53So back to my original train of thought.
- 57:55I was like, let's just sort of kind of wrap this up with the continuous delivery.
- 57:58I've got the app up.
- 57:59Now we know how to get the domain associated with it and whatnot.
- 58:02You know, presumably go and buy a domain wherever you buy domains.
- 58:05Point it at it.
- 58:06Let it map over.
- 58:08But then I make some changes and I git push a thing.
- 58:11What happens now?
- 58:12Yeah.
- 58:13If you set up your, your CI CD pipeline, it would then run through that same process.
- 58:17And we showed it in the GitHub actions here and talk through it.
- 58:20It would run your test, do the deployments.
- 58:23We do support multiple environments.
- 58:25So we can help set up a, like a dev or a QA environment as well, other than just a single.
- 58:32Like a staging.
- 58:32Yeah.
- 58:33Sort of thing that people can.
- 58:34Yeah.
- 58:34And then you could set up some processes, you know, within Azure, like, hey, this passes,
- 58:39let me do a, an IP switch or however you manage that in, in a platform based on your scenario.
- 58:45But yeah, we get to that point where we're just checking in code and having a positive track.
- 58:48Okay.
- 58:49And do you, what's the branching structure look like?
- 58:51If I just push domain, is that going to go live and I got to work on a dev branch to not
- 58:56do that?
- 58:56Or is there like a prod branch or?
- 58:58Yeah.
- 58:59You can set that up in your GitHub action.
- 59:00Right.
- 59:01Okay.
- 59:01Right now we have, the template is just going to work.
- 59:03If I don't do anything, what happens?
- 59:05It's main branch.
- 59:06Main branch goes straight to production.
- 59:08That's right.
- 59:08I love it.
- 59:09Y'all are just carefree to test for it.
- 59:12Do it live.
- 59:13The users are the testers.
- 59:14Let's go.
- 59:15Do it live.
- 59:16No.
- 59:17Okay.
- 59:17Got it.
- 59:17So you would just tweak your GitHub action Yable file and change your branch name or something?
- 59:22Yeah.
- 59:22You could set some conditionals in the GitHub action based on the environments that are coming
- 59:26in.
- 59:26Cool.
- 59:26Anthony, what were you going to say?
- 59:28Yeah.
- 59:28It assumes a single branch strategy, but I mean, or you can tell it to generate the template
- 59:33for you and you can put that template wherever.
- 59:35It's pretty easy nowadays to say with GitHub, you know, which branch and stuff this should
- 59:41apply for, or this pipeline should only run on pull requests.
- 59:45Or my recommendation to people is that you keep main highly protected.
- 59:49You don't let people push directly to main and it can only be merged into, and then it has
- 59:54to be reviewed and stuff.
- 59:55I think keeping a clean main branch is good strategy anyway.
- 1:00:00You can have a feature branch or release branch separately to that.
- 1:00:05So probably the main branch would be your dev, your sort of live dev environment.
- 1:00:09And then maybe you want a feature branch or release, so main release branch separately
- 1:00:14to that, but using the same templates.
- 1:00:16So all you're really changing is the targeted environment names.
- 1:00:19Yeah.
- 1:00:19Okay.
- 1:00:20That sounds like good advice.
- 1:00:21All right, guys.
- 1:00:21Well, we're getting a little short on time now.
- 1:00:23This looks like a really interesting project.
- 1:00:25I love the technical choices on the backend, you know, that you've made to sort of create
- 1:00:31building blocks for people.
- 1:00:32I guess we could wrap it up real quickly with, we've got this more DevOps-y management,
- 1:00:37IT-like CLI that people have used previously.
- 1:00:40If they're doing Python stuff and they kind of want this container-hosted world, this is
- 1:00:45probably the recommended way, at least from you all.
- 1:00:47Yeah.
- 1:00:47Yeah.
- 1:00:48If you want to get started and...
- 1:00:50Fantastic.
- 1:00:50All right.
- 1:00:51Anything else you want to add about this?
- 1:00:52I'd like to call it a show.
- 1:00:53No, nothing from my side.
- 1:00:56A template that you can kind of build upon.
- 1:00:59Shane is frozen.
- 1:00:59Something that you want.
- 1:01:00Oh, no.
- 1:01:00Shane is frozen.
- 1:01:01A production-style app.
- 1:01:02This is a great way to get started.
- 1:01:03I thought he was just getting tired because it's late where he is, but no.
- 1:01:06All right.
- 1:01:07Well, Anthony, I'm sure this is not going to come as a big surprise given all of your current
- 1:01:12work and stuff.
- 1:01:13But I'll ask you the final two questions first, and then we'll hopefully get Shane
- 1:01:16back shortly.
- 1:01:17Good to write some Python code?
- 1:01:18What editor are you using these days still?
- 1:01:20Definitely VS Code.
- 1:01:21But tell people about the font.
- 1:01:23Comic Sans Mono.
- 1:01:25So it's a Comic Sans font, but in Mono space.
- 1:01:29Awesome.
- 1:01:29Is it a nerd font?
- 1:01:30There is.
- 1:01:31I think there's a nerd font flavor of it.
- 1:01:32I haven't configured my terminal to use Comic Mono yet because I think that'd be going
- 1:01:36a bit far.
- 1:01:37It actually looks...
- 1:01:38It'd be madness.
- 1:01:39It looks better than you think.
- 1:01:40It looks good.
- 1:01:41It looks way better than you would think Comic Sans looks.
- 1:01:44And it's really readable.
- 1:01:44I would totally be down to it.
- 1:01:46I had to make a DNS joke.
- 1:01:47You did.
- 1:01:49You took yourself offline, but you're back.
- 1:01:51And just in time to answer the question, have you written some Python code?
- 1:01:55What editor are you using these days?
- 1:01:56I use VS Code.
- 1:01:57Right on.
- 1:01:58I don't know.
- 1:01:58I use VS Code for taking notes.
- 1:02:00I mean, it's just...
- 1:02:01Yeah.
- 1:02:01It's Markdown or if it's in Mark...
- 1:02:03Everything's in Markdown or whatever code, so...
- 1:02:06Yeah.
- 1:02:06All my notes these days are in Markdown.
- 1:02:08If not like a Google Doc, Zoho Doc, something like that.
- 1:02:11It's definitely in Markdown.
- 1:02:12It was like...
- 1:02:13I think it was like three years ago.
- 1:02:14I was in a meeting with Chris Diaz, who's the kind of owner of VS Code.
- 1:02:18And he pulled up his screen and he started taking notes in VS Code.
- 1:02:21And I was like, I'm an idiot.
- 1:02:23I should be doing that.
- 1:02:25Yes.
- 1:02:25Just go to the bottom right.
- 1:02:26Change that little language to Markdown.
- 1:02:28You're good to go.
- 1:02:29That's right.
- 1:02:29Absolutely.
- 1:02:30Notepad.
- 1:02:31Notepad is dead to me.
- 1:02:32Yeah.
- 1:02:33The problem I have at the moment is I've probably got too many extensions.
- 1:02:36I just realized this morning I have 99 now.
- 1:02:38So I'm nearly at three figures.
- 1:02:42There might not be room at the UI to just display that number.
- 1:02:47It might stop at two digits.
- 1:02:49Just kidding.
- 1:02:49Yeah.
- 1:02:50That's awesome.
- 1:02:51I tell you, I didn't even...
- 1:02:52The first bit of...
- 1:02:54Here's some irony.
- 1:02:54The first time I ever wrote Python was...
- 1:02:57It feels like 100 years ago, but...
- 1:02:59Was actually to write a Sublime add-in to enable .NET IntelliSense for .NET Core.
- 1:03:08So I was on the OmniSharp team to write the add-ins for that.
- 1:03:12So completely like not Python related, but I was using Python to enable .NET and Sublime back in the day.
- 1:03:18That's cool.
- 1:03:19Yeah.
- 1:03:19So very meta.
- 1:03:21Yeah.
- 1:03:21Using the editor to write the editor.
- 1:03:22All right.
- 1:03:23And then notable PyPI package.
- 1:03:25Anything you want to give a shout out to?
- 1:03:26I mean, we definitely mentioned a bunch of fun ones, but...
- 1:03:29Yeah.
- 1:03:29I'd say Beanie Perflint, which is one of mine.
- 1:03:32But yeah, check out Perflint if you want to.
- 1:03:34And check out Beanie as well.
- 1:03:36It's a really nice approach to document databases in asynchronous front ends.
- 1:03:42Yeah.
- 1:03:42Especially if you're doing FastAPI.
- 1:03:44I was going to say, I used to struggle with document databases and Pydantic and Beanie made my life a whole lot better.
- 1:03:52Yeah.
- 1:03:52I think we all concur.
- 1:03:53Beanie.
- 1:03:54Definitely a good one.
- 1:03:56Good call.
- 1:03:56Cool.
- 1:03:56Yeah, absolutely.
- 1:03:57All right, guys.
- 1:03:58Final call to action.
- 1:03:59People want to get started with this.
- 1:04:01Once it's out, what do they do?
- 1:04:03When they're listening to this, it'll be out.
- 1:04:04So not to confuse folks.
- 1:04:06I've got a link that folks can go and check this out.
- 1:04:09It'll obviously be in the show notes.
- 1:04:11It's a short link.
- 1:04:12It's an aka.ms and it's try-aca-python.
- 1:04:17Right on.
- 1:04:17And they can see the project template, sign up for our preview, check out the repos, et cetera.
- 1:04:23Cool.
- 1:04:23Yeah, it looks like you need a project.
- 1:04:24And definitely people are doing Azure.
- 1:04:28It supercharges you into a ton of best practices.
- 1:04:31Yeah, for sure.
- 1:04:32Well, nice work.
- 1:04:33And thanks for joining me to talk about it.
- 1:04:34Yeah, I appreciate the time.
- 1:04:35Thanks.
- 1:04:35Yeah, you bet.
- 1:04:36Bye.
- 1:04:36This has been another episode of Talk Python To Me.
- 1:04:40Thank you to our sponsors.
- 1:04:42Be sure to check out what they're offering.
- 1:04:44It really helps support the show.
- 1:04:45Take some stress out of your life.
- 1:04:48Get notified immediately about errors and performance issues in your web or mobile applications with
- 1:04:53Sentry.
- 1:04:53Just visit talkpython.fm/sentry and get started for free.
- 1:04:58And be sure to use the promo code talkpython, all one word.
- 1:05:02Say no to being manipulated by ad companies and enjoy the free and open internet.
- 1:05:08Get NordVPN on all your devices.
- 1:05:10Set auto-connect and relax.
- 1:05:12Visit talkpython.fm/NordVPN to get your risk-free subscription started today.
- 1:05:19Want to level up your Python?
- 1:05:20Want to level up your Python?
- 1:05:21We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:05:25Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:05:30And best of all, there's not a subscription in sight.
- 1:05:33Check it out for yourself at training.talkpython.fm.
- 1:05:35Be sure to subscribe to the show.
- 1:05:37Open your favorite podcast app and search for Python.
- 1:05:40We should be right at the top.
- 1:05:41You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:05:47and the direct RSS feed at /rss on talkpython.fm.
- 1:05:52We're live streaming most of our recordings these days.
- 1:05:54If you want to be part of the show and have your comments featured on the air,
- 1:05:58be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:06:02This is your host, Michael Kennedy.
- 1:06:04Thanks so much for listening.
- 1:06:05I really appreciate it.
- 1:06:06Now get out there and write some Python code.
- 1:06:08I'll see you next time.