Python for .NET Developers Transcripts
Chapter: Deploying Python web apps
Lecture: Configuring the Python code

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now you can use whatever file structure you want but here's something I like to use. I'm going to create a /apps folder and allow the app
0:10 to write logs and stuff like that. Create a couple of log directories like this. Let's just go run all of those over there.
0:20 We have tree, yes, we have tree. We have this simple structure so far. The rest of its going to be created by git itself.
0:28 So this is like so if you want to run this block we just did that. Now, we're going to create a virtual environment for our web app.
0:35 Yes, we could just mess up Python on the server, right? But let's have a dedicated isolated place for our Python code.
0:42 That way no matter what happens to the system, Python we're pretty much guaranteed to have everything running the way we want
0:48 So now we have that environment. Let's go and activate it. Remember, pip and setuptools are always installed and they're always out of date.
0:59 Let's test. Yup, they were out of date. We had version nine. Oh, guess what? Version 19 is out, only 10 versions out of date.
1:08 I don't know what's wrong with that. I really wish you would update itself. Then I want to setuptool, httpie, which is a great
1:13 it's like curl or wget, but it's much better for testing command line stuff. This way let's check of what our web servers responding to
1:22 that way we can like check uWSGI on local hosts without exposing it. Then glances is like Task Manager, or Process Explorer
1:29 or something like that, that lets us look at our server in a almost graphical way. Right, a bunch of stuff got installed
1:41 and now we can do things like run glances which will give us a really cool view. And if we make it bigger here, it's big as I guess it can be
1:49 a little progress bar up here and see the servers super efficient. We've been working on it and it's been running for a while
1:55 and it's even running this Python app and it still is only using 287 megs of memory including the operating system.
2:02 So yeah, thanks. It's pretty awesome like that. CPU levels super low and most of its just coming from glances. That's cool.
2:10 Here's our failed band server. Happens to be running on Python our monitoring agent from Digital Ocean and so on. We don't have Nginx or uWSGI
2:19 because we haven't set those up yet. But you know, we're getting there. Then for HTTP, we could do something like over here
2:27 and do a request and notice we get color coded HTTP response. Let me do that again and so I just go to the top.
2:36 You can get information about what the encoding is you know, headers and server like servers and Nginx. No surprise, because Nginx is awesome.
2:44 Alight, so this will let us test our setup, good. We have our virtual environment, and we have our logs but we don't have our code yet.
2:53 So we're going to get that from GitHub. But before we do it, let's also install uWSGI. Now, Nginx we did before but it is a system type
3:02 of package installed with aptitude with apt. But uWSGI is actually a Python thing we install with pip.
3:08 So I'm going to install that into our virtual environment that's why we waited until now for it. Actually takes a second to build and install
3:15 so we'll let it do its thing. Super, so we have uWSGI, we'll even be able to type that is a command. It's not going to run.
3:25 We haven't given it an app and so on. But it looks like that's up and running. Next, let's try to install our GitHub repo.
3:33 I'm going to notice I'm going to shorten this because this is a great long name, and that's annoying. So we're going to put it into app repo.
3:40 Very first time I have to enter my information here. Oh, it looks like I used the wrong name it's ended the organization not under my personal account.
3:55 There we go. Now we do our tree command. We can see that we have our app in our app repo. If we ignore our virtual environment
4:04 we can look a little bit further. Decent stuff about the structure. Okay, so we have our .NET version we have our Python version
4:13 there's the code that we're going to try to run and here are the config files that are now copied to the server that we get to work with. Perfect.
4:21 Now we're going to need to make sure our server has the Python requirements. So let's go over here we go and run, you know
4:30 and go to our Guitary and we can, I mean, no, it's not there sorry, it's back one. There we go. pip install-r requirements.
4:38 Now that's going to install a little bit extra because it's for the whole course. Normally, it wouldn't work like that
4:43 but whenever we're just going to let it run. Super how we have a lot installed there. We can check it out with pip List, it's all looking good.
4:54 It's time to get to our config files, so we're going to do those next, but what we're going to need to do
4:57 is basically copy the config files to the location where uWSGI and Nginx can pick them up. So it looks like our code is all set up.
5:06 I guess we could even try to run it couldn't wait, let's do that. It's pretty cool, We can even come down here and arrow around.
5:16 Love, love, Oh my zshell. All right, we come down here. Try to run this. You know this one, We didn't update it with that thing that path addition.
5:30 I believe we just did it right here. Let's look. Remember this? We didn't do it in this one. Let's update this one as well.
5:42 Let's see if this will work. I think we could do it like so if we go to the terminal. Yep, looks like it's going to work. Okay, so if we check that in
5:58 we come back over here and try our source, we got to get a git pull and then just run it. Beautiful. Now I can't interact with it in this terminal
6:11 because it's already blocked running. So let's just go back here and do an HTTP HTTP localhost Port 5000. That's where it's running right there.
6:26 That did not work because we did not activate our virtual environment. Now one option and be well, we need to activate it go over there and do that.
6:32 This is something I love to join my servers. So I'm going to go and edit my startup script here and I'm going to do an alias
6:42 not do an alias, I'll do a source. So what's that going to do? That means when we log back in, it's going
6:51 to automatically activate our web portal environment. This is so nice because you almost never want to change the system Python, you want
6:59 to change your app Python. So I do this in all my servers, it's really, really sweet. Now, let's try this again HTTP host. Oh, look at that jQuery
7:08 and our Bootstrap our Talk Python Training. All the magic. Here's our Guitary. So it looks like it's working. You can even see the successful git.
7:16 So we've got our code running here, but we need to get it running, not in just our dev server but in uWSGI, production uWSGI server instead.
7:25 But we're making it pretty far it's running right?


Talk Python's Mastodon Michael Kennedy's Mastodon