Using and Mastering Cookiecutter Transcripts
Chapter: Programmatic Cookiecutter: Using the API
Lecture: Why the API?
0:01 Cookiecutter is a very powerful in its own right.
0:04 We've seen the pre and post generation hooks,
0:06 the dependent properties in the cookiecutter.json, and so on,
0:09 so there is quite a bit we can do just within Cookiecutter itself,
0:12 but, there are many times we want more control over this,
0:15 or we wanted to feel more native or we don't want to tell people
0:19 hey you have to use Cookiecutter, just say use our application,
0:22 run this command and you'll get started,
0:24 but we of course don't want to do all that file management, projects,
0:27 text juggling that Cookicutter does for us.
0:30 So, we can wrap the Cookicutter API in our own application,
0:34 be that Python, .Net, Java whatever, and we can use that
0:39 to interact with the user, but actually use the Cookicutter API
0:43 just like you've seen all the features we've seen creating the templates,
0:47 we can use that from the API to create our project in the end.
0:51 So, I'll give you two quick examples,
0:53 if I want to get a new project started in Pyramid, the web framework in Python,
0:57 there is a whole bunch of stuff
0:59 I've got to do really to get started, I've got to create the templates,
1:02 I've got to create the views and maybe even I want testing,
1:05 it's a Python package, so it's got to have a certain amount or structure put together
1:08 so that it represents that, there is a lot of things to do to get started.
1:12 And sort of just telling you to do that, they say
1:16 hey you can just run this command pcreate -s (for scaffold) starter
1:20 and the name of your app, and we'll go and create that for you,
1:23 so then you can just run it and have a working app to start from,
1:27 that's great; it turns out pcreate actually wraps the cookicutter API
1:31 and calls the started Cookicutter template from Pyramid
1:35 to do that, which is really cool.
1:37 You run this command, it asks you a few questions,
1:39 probably looks familiar, it doesn't have to though, because,
1:42 you can ask these questions in your app
1:45 and just feed the answers directly to Cookiecutter.
1:48 Another example might be django-admin,
1:50 maybe we want to create a new project called my site,
1:53 something like this, I don't think django-admin uses cookicutter,
1:55 it may, but it's just another example of here is some part of my app,
2:00 it helps you get started by generating a project
2:02 that could easily be a Cookicutter template.
2:05 Right, off it goes, it does whatever it does to create your project,
2:07 ideally that's with Cookicutter.