RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Your first service
Lecture: Creating the web app

Login or purchase this course to watch this video and the rest of the course contents.
0:02 It's time to create our web app so we can host our services there. Now, I've changed into this folder that is in our github source code repository,
0:13 so anything you see me do here I'm going to check that into github and you should be able to get to that when you watch this video.
0:20 So the thing that we need to do to get started working with Pyramid
0:23 regardless of really how we're using it, is to install this thing called cookiecutter.
0:29 Now, traditionally Pyramid has used its own internal project generator thing and they've switched to a more general one called cookiecutter.
0:37 First thing we got to do is make sure that we have cookiecutter installed, I'm going to do the --user to install it just locally for me.
0:48 Alright, it looks like I already have that installed, that's great; the next thing we can ask is which cookiecutter, just so you can find it,
0:55 sometimes I found that the path to the bin folder where this gets installed sometimes doesn't make it into your path, and then if you try cookiecutter
1:05 it gives you an error like command not found, so you might have to add this, the user name
1:11 and maybe change the back slashes to forward slashes for windows adapt that your system, you might have to add that to your path for this to work.
1:20 Ok, so once you've got cookiecutter set up and it's in your path, then you are ready to use it, so we just type cookiecutter
1:27 and it's going to tell us hey you have to give us a template, now where do we get this template- well from github of course,
1:32 so over here you can see in the Pylons project which is a grouping for Pyramid and other stuff
1:39 they've got a Pyramid Cookiecutter starter, so let's go with that. We're going to go over here and we'll say cookiecutter run from this template,
1:46 now if you've already run this command, you could just type that but if you don't have the template installed and downloaded
1:53 then you've got to give it the full path, so we'll run it like this,
1:56 notice I've already done it so it's going to say do you want to get a fresh version, I'll say yes this will be our First Auto Service.
2:03 Now it's going to suggest a pretty decent name first_auto_service this has to be a Python package name,
2:10 so it's got to match some of the rules around package names. Now, this is good, but I'm going to use svc1_first_auto_service
2:19 and then that way we can have service 2, service 3, it will be more easy to find the various versions that we've built
2:25 throughout the class in the course repository. So let's call this, it will ask us what kind of templates
2:31 you can choose which one of the three you like, I think Chameleon is best so I'm going to pick that, it doesn't really matter so much.
2:37 All right, it looks like it worked, it says welcome to Pyramid, sorry for the convenience, now, it gives us a little bit of guidance here,
2:45 it says okay we can create we can cd over to where the files are; the next thing it says, you should create a virtual environment,
2:53 it's true, we should create a virtual environment, you don't have to but this allows you to have a separate clean copy of Python
2:59 to run and manage the dependencies of this project, so let's go ahead and I will do that, I'm not going to call it env
3:07 I'm going to call it . env, so it's hidden and it also matches some rules that make a few things easier later. I'm also going to add a --copies here,
3:17 this only matters if you are on Mac and you care to use PyCharm, but taken together there is something about the way symlinks get set up
3:23 that without the --copies don't quite work right, so you need this to basically use it in PyCharm. We'll wait a second- everything is ready to go,
3:32 so notice now here we have a little setup, the last thing to do is set up and basically install Pyramid,
3:37 install all the dependencies of Pyramid in this project as well as these Pyramid packages themselves behave as Python packages
3:46 and so the set up here provides another step in that it registers the website in the Python executable environment, the virtual one we just created.
3:57 Well, before we can do that we actually have to activate this, so we could say source, or we could just say . env /bin/activate
4:06 notice my prompt changes, if I'm on Windows you don't need the first . ( dot ) and this is scripts, and it's activate. that,
4:17 so unfortunately those are not the same, but whatever it's not hard to adapt to either.
4:22 So now, if we ask which Python, on Windows the command is where, notice we're running the one out of our little virtual environment we just created,
4:30 that's cool, so we can come over here we can run Python and don't just run it by itself, there's really two decent options here
4:39 we could install and now we copy it to the runtime for Python and run it, but we want to be able to continue to work on it and edit here,
4:47 so we're going to use develop, so we run that, it installs all the dependencies it takes just a moment, and then we'll be ready to go.
4:53 Alright, it looks like it installed, everything we can do a quick pip list and you'll see Chameleon, Pyramid,
5:02 Waitress the dev server, things like that got installed, including our little project itself got registered as a package.
5:08 So the last thing we need to do is just to run this, and it comes with a command p serve, which got installed during that setup step,
5:16 it came along with the install of Pyramid there and we can give it either development.ini, production.ini, we can make up another configuration file,
5:24 but we give it a configuration file here, we run it, it's serving up right on the localhost. So now we can have a look and see what we got-
5:35 ta - da, here's our Pyramid starter project, and you can see it's got the little name that we gave it, and all sorts of stuff.
5:40 It doesn't do much yet, it's just a blank site, there's no API section or anything like that, because we haven't created it yet
5:48 but that's what we're going to do next, we're already ready to go, we've got our site created all the dependencies installed and it's up and running.

Talk Python's Mastodon Michael Kennedy's Mastodon