RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Your first service
Lecture: Concept: Creating the site
0:01 Let's look at the steps that we had to take to create and run our web application.
0:06 Remember, the first thing we had to do was make sure
0:09 that we actually had cookiecutter itself installed
0:12 because pyramid is now switched to a cookiecutter template model
0:15 for all of their projects, so we need to run cookiecutter
0:17 against their template, that means we've got to have cookiecutter.
0:20 So we did a pip 3 the install--user cookiecutter
0:23 you may have to set the path depending on how is system setup,
0:25 it may just run, I've seen it sort of work both ways;
0:28 so we install cookiecutter, once we have cookiecutter working
0:32 you can pick a template, for the purpose here I think
0:36 the Pyramid cookicutter starter is totally fine.
0:40 There is one that you can pick that has sqlalchemy set up
0:43 but you'll probably want a lot of control over that anyway.
0:46 So we'll do that in the later section, and it will set up sqlalchemy,
0:49 the data access layer, but here we get pretty simple one page basic website,
0:54 so cookiecutter space the url to the github repository,
0:58 not the . git part, although I believe that would also work
1:01 but actually just the url to the github repo page.
1:04 Cookiecutter asks you a couple of questions before it actually creates the website
1:08 so here we gave it the name auto service api
1:11 and auto_service_api for the lower case name
1:15 and then we chose Chameleon, and it ran correctly
1:18 and gave us a few steps on hey here's what you might do next.
1:21 So you see the next thing it says it's to go into that directory
1:25 and create a virtual environment, we do almost that
1:28 we do create the virtual environment,
1:30 we give it a slightly different command.
1:32 So then we go into where the web app was created
1:35 to its primary directory, we create a virtual environment
1:38 and we use the . env rather than straight env, that makes it both hidden
1:43 but also PyCharm automatically detects and uses that,
1:46 which is very handy, and we give it the --copies at least on MacOS,
1:51 because the resolution of the symlinks doesn't quite work right in PyCharm,
1:57 and possibly other environments as well, this is the one reverend to issues
2:00 and copies fixes that, so we've now created our virtual environment,
2:04 but it's still not active, if we do pip or python is running the system one,
2:07 notice of the prompt is unchanged, so the next thing to do
2:10 is to activate the virtual environment,
2:12 so we say source or . env /bin/activate like I said,
2:17 on Windows it's scripts and activate that, source not required
2:20 and our prompt should change.
2:22 Then if you ask things like which or where Python,
2:24 it will pull up the actual path to the one
2:27 that's in that virtual directory, so you know it's working.
2:30 After that, we need to install Pyramid, all the dependencies of our web app
2:34 which depending on how the scaffold runs is often beyond just Pyramid itself,
2:39 things like pyramid debug toolbar and waitress and so on;
2:42 so to accomplish that as well as register the package itself,
2:45 remember, pyramid projects are python packages
2:48 we run python against the setup.py and we give it a developed argument
2:52 and that's going to tell it to install all the dependencies, and install it locally.
2:56 After this, we're ready to run, so we just use the p.serve command
3:00 which comes along as part of that setup process
3:03 when we install pyramid it comes with p.serve,
3:05 and t hen we can p.serve development.ini
3:08 that starts up our web app and we're off to the races.
3:11 We have a wonderful new website that we're ready to start adding a web services to.