Skip to content

maekind/python-main-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

licence python_version size last_commit language

Python main template 🐍

Description

This project hosts a python template for a main program. It consists of the following:

  • main.py: A main skeleton with logging and arguments parse.
  • logger.py: A simple wrapper for the logging python package which setups and formats the logging output. By defualt, a logging file is created. Even thought, you can also setup the console logging passing an application argument. See Default application arguments for more details.
  • decorators.py: A set of usefull basic decorators for logging and time measurement.

Initial configuration

You can find TODO comments along the code. The main configuration should be:

  • Replace the PACKAGE_NAME folder name with your own. Make sure that your imports point to right package name.
  • Add more arguments if necessary to the main file and check for all of them which are meant to be mandatory.
  • Rename the MAIN_CLASS_NAME file with your own. Make sure that you also rename the class inside the file.

The rest of the TODO are informational.

Environment configuration

In order to setup the virtual environment, we can follow the next statements.

For pipenv installation:

$> pip install --upgrade pip && pip install pipenv

Then, you have to install the required packages.

$> pipenv install

To activate the virtual environment, exceute the following command:

$> pipenv shell

Default application arguments

A main.py file is provided in the root folder. The main program defines the following parameters by default:

  • -v / --verbose [optional]: flag to let know the application to show debug messages. By default, logging is configured in the INFO level. So, debug messages won't be shown.
  • -c / --console-logging [optional]: flag to let know the application to show logging messages in to the standard output. By default, logging is performed to a log file.

Decorators

Decorators print output messages using the logging package. To work properly, the class which uses the decorators needs to implement de _name class variable. This variable means to the name of the logger defined in to the main file and has to be passed in the default class constructor.

Contributors

Say hello!