1. Faster package development with templates
Great work so far, you've learned all the essential steps to build and publish a great package. In this chapter you'll learn some tips to make this whole process easier, and a few final things you can add to your package to make it more professional.
2. Templates
As you've seen in earlier chapters, a Python package has a lot of additional files you need to write.
Which means when starting from scratch there is a lot to remember, and fill in.
Fortunately, you can use templates to do a lot of this work for you.
3. cookiecutter
Cookiecutter is a command line tool which creates projects from templates. You can use it to create a basic, empty Python package, like this one.
These templates can create all of the additional files which your package needs, so you can focus more on the code, and won't need to worry you have forgotten something.
4. Using cookiecutter
You run cookiecutter from the terminal, and pass it the URL of the template you would like to use.
5. Using cookiecutter
The standard template for Python packages is this one.
But there are lots more templates you can use choose from.
6. Using cookiecutter
When you run this, it will ask you to fill in some details about the package you are creating.
The first field you must fill in is your full name. Each field has a default value in square brackets. In this case the default is the name of the template author.
7. Using cookiecutter
This value will be used to set the author name inside the package setup-dot-py file. You'll need to type yours, and press enter to continue.
8. Using cookiecutter
It will prompt you for some more details used to fill in the template.
This includes the package name and slug. The slug is just the name you want the package to be registered under. The package will be pip-installed with this name.
9. Using cookiecutter
The project description will go in the README file. You don't need to worry too much about what you write for this description. You can still manually edit the contents of the README file later.
If you are happy with the default arguments you can just press enter without typing to accept them.
10. Using cookiecutter
You should specify yes to use pytest, and no to the other two options. We haven't been able to cover these in this course.
11. Using cookiecutter
We also don't use a command-line interface, so we enter 3 to pick this option.
We will include an author file, which is just a list of the package authors.
12. Using cookiecutter
Finally, you can choose a license, if one of the options is appropriate for you. If not, you can choose not-open-source and add a license manually.
13. Template output
cookiecutter creates a new directory with your package name, and fills it with all the files we have covered. Each of these files has good default content. Even the setup-dot-py file has been completely filled out. However, you may still want to make some edits. For example, here the README is a restructured text file rather than markdown.
It also adds some extra files we will cover later, like the AUTHORS file, which lists the authors of the package and their contact details.
14. Template output
Finally, it adds some more files which we won't be using in this course. These can safely be deleted.
15. Let's practice!
Using templates is a really great way to start a package in the real world, so let's practice!