Modern Python Projects Transcripts
Chapter: Cookiecutter templates
Lecture: You can build your own template

Login or purchase this course to watch this video and the rest of the course contents.
0:00 So far, We saw how to use an existing cookie cutter template to generate the
0:04 project. But all those templates that we saw in the GitHub were created by
0:08 someone. So if you want,
0:10 you can create your own template to, why would you write your own template?
0:14 You might do this when none of the existing ones seems like a good choice.
0:18 If you're always building very specific projects,
0:21 maybe you need your own template from scratch.
0:23 Or maybe you like one of the templates.
0:25 But you want to change a few things.
0:27 For example, you want to use a different library here and there.
0:31 Or maybe you always remove the same feature from a given template,
0:34 and you would prefer to have a template without those features in the first place.
0:38 You can't change the template that belongs to someone else,
0:41 but you can always fork it,
0:43 make the necessary modifications and use that version instead.
0:47 So how do we write a cookie cutter template?
0:50 If you go to the documentation of the cookie cutter,
0:53 there is a section called Create a Cookie Cutter from scratch.
0:58 Unfortunately, it's very basic, and it has this to be continued sentence at the
1:02 end, so maybe by the time you're watching this,
1:05 it has much more detailed information.
1:08 But basically the simplest cookie cutter template is just a folder with this weird name.
1:14 Cookie cutter.project_slug In this double curly brackets.
1:18 You put some files inside that folder and you publish it on GitHub.
1:22 Now when you run cookie cutter command with GitHub URL,
1:24 It will replace this weird cookie cutter.projects_slug folder name
1:29 with a real name of your project,
1:31 and inside you will have the same files that you put on GitHub.
1:35 But of course, cookie cutter can do much more.
1:38 You can replace the content of some files or file names with variables that you provide
1:43 when generating the project. You can also remove some files.
1:46 For example, when the templates lets you choose between different database engines and you choose
1:51 MySQL instead of Postgres.. Then there is no point to keep the postgres setting
1:55 file, so you can safely remove them.
1:59 If you want to learn how to create your own cookie cutter template,
2:02 I can recommend you another course from the talk python catalog called using and mastering
2:07 cookie cutter. Apart from a very good explanation of different features of the cookie cutter
2:12 library, one of the chapters shows you step by step,
2:16 how to write your own template from scratch.
2:18 And as you can see, it takes over one hour,
2:20 so there's a lot of things that you can learn.