DEV Community

Cover image for Speedup python cli projects using Cookiecutter
Joris Conijn for AWS Community Builders

Posted on • Originally published at binx.io

Speedup python cli projects using Cookiecutter

Use our python-cli-tool cookiecutter project. Get an python cli project up and running in a few steps. In my previous speedup-event-driven-projects blog. I wrote how you could use cookiecutter to spin up an event driven project for AWS. In this blog post I will show you how you could do this for python cli projects.

For this blog post I assume that you have the following installed:

  • python3
  • cookiecutter
  • poetry

Lets create an cli project

We will begin with executing the cookiecutter command:

cookiecutter gh:binxio/python-cli-tool
Enter fullscreen mode Exit fullscreen mode

Screenshot of the commands being executed

Cookiecutter will create a folder based on the project_name. In this folder you now only need to install the dependencies. You can use the following command:

make install
Enter fullscreen mode Exit fullscreen mode

The install target of the Makefile will:

  • Perform a poetry init, this will create the pyproject.toml file.
  • Create git repository and install the pre-commit hooks.
  • Perform a poetry install. This will install all project dependencies based on the pyproject.toml file.
  • Adds extra configuration to the pyproject.toml file.
  • Commits everything to the git repository.

You will end up with something like this:

Screenshot of the project tree structure

The project itself has unit testing in-place:

Screenshot of the tests running

And you can test your cli tool as well by executing the commands through poetry:

Screenshot of the CLI tool in action

Now it's time to configure your remote GitHub repository:

git remote add origin git@github.com:binxio/my-example-cli.git
git branch -M main
git push -u origin main
git checkout -b develop
git push --set-upstream origin develop
Enter fullscreen mode Exit fullscreen mode

We pushed the main branch to the remote and created a develop branch as a working branch.

The project itself contains the following workflows:

  • Continuous Integration, checks when you push to main or open a pull request to develop.
  • Create Release, creates an release for you when you merge to main and uploads it to PyPi.org. (You need to configure a PYPI_API_TOKEN secret in GitHub for this to work)
  • Release Notes, creates a proposal for your release notes. This is based on your merged pull requests. So make sure you use correct messages.

Conclusion

By using the python-cli-tool cookiecutter project you will speedup your python cli project!

And you can focus on what matters! Your business logic!

Photo by Ekaterina Belinskaya

Top comments (1)

Collapse
 
Sloan, the sloth mascot
Comment deleted