This is a cookiecutter template for generating simple Python command-line interface (CLI) applications and utilities.
The primary audience is data science and data processing teams, however, the template is generic enough to find a good fit in other places.
Please, refer to the project's article to get more info.
The template provides essentials for creating, packaging, and managing CLI applications. Among them:
- Config and params passing, overriding and validating:
- Define and validate config structure in
jsonschemaformat. - Define config defaults.
- Optionally read configs from JSON or YAML files.
- Optionally override config values using args defined via
argparseorclick. - Optionally override config values using env vars.
- Define and validate config structure in
- Logging setup:
- Support of microsecond resolution.
- Support of UTC or local time zone in log records.
- Log records format.
- Optionally inject hostname into log records.
- Optionally format log records as JSON.
- Definition of an installable package with executable commands.
- Linting support via
flake8. - Optional testing via
pytest. - Helpful
makecommands.
As this is a cookiecutter's template, make sure it's installed:
pip install cookiecutterDefault usage is the same as for any other cookiecutter templates:
call cookiecutter and pass template's URL as a param:
cookiecutter https://github.com/oblalex/simple-python-cli-app-templateor a GitHub repo name via gh shortcut:
cookiecutter gh:oblalex/simple-python-cli-app-templateNext, follow cookiecutter's questions to set up params and get a minimal
working application. Refer to the following section to see which params are
available.
NOTE: Please, refer tocookiecutter's documentation regarding.cookiecutterrcfile and--no-inputargument in case user-prompt is unwelcome.
The template accepts several parameters to configure a project being created. Parameters have default values. The full set of template's params is listed below.
project_nameName of a project (
string). Used in documentation. Defaults of several other params are calculated from it.Default value:
"Simple Python CLI App".package_nameName of Python package to create (
string).Default value is calculated from
project_namevia slugification.Example value:
"simple_python_cli_app".executable_nameName of an executable file to create during package installation (
string).Default value is calculated from
project_namevia slugification.Example value:
"simple-python-cli-app".class_name_prefixPrefix used for package class names (
string).Default value is calculated from
project_namevia slugification.Example value:
"SimplePythonCliApp".env_var_name_prefixPrefix used for names of env vars (
string). Used to override config values.Default value is calculated from
project_namevia slugification.Example value:
"SIMPLE_PYTHON_CLI_APP".project_short_descriptionShort description of the package being created (
string). Used in documentation.Default value:
"Simple Python CLI application".project_urlProject's URL (
string).Default value:
""(empty string).versionProject's version (
string).Default value:
"1.0.0".author_nameName of package's author or owning team (
string).Default value:
"John Doe".author_emailEmail of package's author or owning team (
string).Default value:
"[email protected]".author_usernameUsername of package's author or owning team (
string).Default value:
"john.doe".create_author_fileWhether to create or not
AUTHORS.rstfile (boolean).Default value:
y.command_line_interfaceCommand-line parser to use (
integeras a choice number ofstring's).Choices:
argparseclick
Default value:
1.config_file_formatConfig file format to use (
integeras a choice number ofstring's).Choices:
YAMLJSONno config file
Default value:
1.logging_time_zoneTime zone to use in timestamps of log records (
integeras a choice number ofstring's).Choices:
utclocal
Default value:
1.logging_include_hostnameWhether to include hostname into log records or not (
boolean).Default value:
y.logging_format_jsonWhether to format log records as json or not (
boolean).Default value:
n.use_pytestWhether to use
pytestas test runner or not (boolean).Default value:
n.
This template includes a Makefile with commands useful to perform
common duty tasks:
clean- Remove all build, test, coverage and Python artifacts.
clean-build- Remove build artifacts.
clean-pyc- Remove Python file artifacts.
clean-test- Remove test and coverage artifacts.
lint- Check style with
flake8. test- Run tests quickly with the default Python.
dist- Builds source and
wheelpackage. install- Install the package to the active Python's site-packages.
install-e- Install the package into the active Python's site-packages
in editable mode via
pip. dev-deps- Install development dependencies via
pip. test-deps- Install testing dependencies via
pip.
As cookiecutter uses Jinja2 as a template engine and as certain
functionality provided by this template is optional, resulting files may
contain extra newlines or be missing them.