Table of contents
- Cookiecutter Python package repo review
- Creating a Cookiecutter templated Python package
- Generating Cookiecutter templates from a GitHub template repo
- Generating Cookiecutter templates for AWS Lambdas
Creating new Python packages with best practices 'baked in'
The past handful of times I've made Python packages I have created a new repo, seen the "create from template" option and regretted that I never set this up, before proceeding to simply copy and paste an existing one and then edit it manually to fit my new package's name.
It's very important to streamline this process as if you grind to a halt then you can end up losing your drive to create that new side project library. Every extra minute of concentration it takes to set up your new library is another minute further from that moment of inspiration which got you making a new repo in the first place.
It may seem contradictory to get sidetracked from the act of making a package to go make a separate template package, but this abstraction of packaging from library code itself is a perfect example of slowing down to speed up. To phrase the problem of repeatedly fiddling with packaging for every package in the '3M' model (Lean Six Sigma-speak for the Agile devotees) it's a case of Muda:
Any activity that consumes resources without creating value
The blog posts herein detail the one weird trick to create a new package from a template.
The trick is to use the
to build a template. You can take this a step further by combining that with GitHub's
feature to avoid having to run the
cookiecutter library locally, instead running it through
Credit to Simon Willison (of the datasette library) and Glyph (of the attrs library) for discussing these approaches on Twitter, and especially to Simon's trick leveraging GitHub Actions to fill in the templating tag values through the GitHub API upon creating a new repo, then deleting this Action in what I refer to as a 'self-deleting installer' setup. See part 3 for a breakdown of how this works in more detail.
Happy packaging! 🚀