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