Speedup python cli projects using Cookiecutter
Tags: cookiecutter, cli, tools, python
Published: 2023-02-02 09:58:31

Use our [python-cli-tool](https://github.com/binxio/python-cli-tool) [cookiecutter](http://cookiecutter.io/) project. Get an python cli project up and running in a few steps. In my previous [speedup-event-driven-projects](https://binx.io/2022/10/11/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:

```bash
cookiecutter gh:binxio/python-cli-tool
```

![Screenshot of the commands being executed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4xhug8qi2pji5ruq7d42.png)

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:

```bash
make install
```

The `install` target of the [Makefile](https://binx.io/2021/09/27/make-your-life-easier-using-makefiles/) will:

* Perform a `poetry init`, this will create the `pyproject.toml` file.
* Create git repository and install the [pre-commit](https://pre-commit.com) 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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o31nqxjqfb110y2ceom7.png)

The project itself has unit testing in-place:

![Screenshot of the tests running](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z31ooetq8kgqahkmu3cz.png)

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

![Screenshot of the CLI tool in action](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f4wj13qmu9co6l1vuce2.png)

Now it's time to configure your remote [GitHub](https://github.com) repository:

```bash
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
```

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](https://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](https://binx.io/2022/02/10/commit-messages-done-the-right-way/).

## Conclusion

By using the [python-cli-tool](https://github.com/binxio/python-cli-tool) [cookiecutter](http://cookiecutter.io/) project you will speedup your python cli project!

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

Photo by [Ekaterina Belinskaya](https://www.pexels.com/photo/carton-box-on-yellow-lines-of-an-asphalt-road-4744757/)