Skip to content

bybatkhuu/module.python-template

Repository files navigation

my_template

MIT License GitHub Workflow Status GitHub release (latest SemVer)

my_template is a template for python package.

Features

  • Template for python package.
  • Other features...

Installation

1. Prerequisites

  • Python (>= v3.7)
  • PyPi (>= v21)

2. Install my-template package

Choose one of the following methods to install the package [A ~ F]:

A. [RECOMMENDED] Install from PyPi

# Install or upgrade package:
pip install -i https://test.pypi.org/simple -U my-template

B. Install latest version from GitHub

# Install package by git:
pip install git+https://github.com/bybatkhuu/module.python-template.git

C. Install from pre-built release files

  1. Download .whl or .tar.gz file from releases - https://github.com/bybatkhuu/module.python-template/releases
  2. Install with pip:
# Install from .whl file:
pip install ./my_template-[VERSION]-py3-none-any.whl
# Or install from .tar.gz file:
pip install ./my_template-[VERSION].tar.gz

D. Install from source code by building package

# Clone repository by git:
git clone https://github.com/bybatkhuu/module.python-template.git my_template
cd ./my_template

# Install python build tool:
pip install -U pip build

# Build python package:
python -m build

_VERSION=$(./scripts/get-version.sh)

# Install from .whl file:
pip install ./dist/my_template-${_VERSION}-py3-none-any.whl
# Or install from .tar.gz file:
pip install ./dist/my_template-${_VERSION}.tar.gz

E. Install with pip editable development mode (from source code)

# Clone repository by git:
git clone https://github.com/bybatkhuu/module.python-template.git my_template
cd ./my_template

# Install with editable development mode:
pip install -e .

F. Manually add to PYTHONPATH (not recommended)

# Clone repository by git:
git clone https://github.com/bybatkhuu/module.python-template.git my_template
cd ./my_template

# Install python dependencies:
pip install -r ./requirements.txt

# Add current path to PYTHONPATH:
export PYTHONPATH="${PWD}:${PYTHONPATH}"

Usage/Examples

To use my_template, import the MyBase class from the package:

from my_template import MyBase, BaseConfig

my_base = MyBase()

Simple

main.py

import sys
import logging

from my_template import MyBase


logging.basicConfig(stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger(__name__)


if __name__ == "__main__":
    _my_base = MyBase(item="item-01")
    logger.info(f" My item => {_my_base.item}")

Run the examples/simple:

cd ./examples/simple

python ./main.py

Output:

INFO:__main__: My item => item-01

Running Tests

To run tests, run the following command:

# Install python test dependencies:
pip install -r ./requirements.test.txt

# Run tests:
python -m pytest -sv

Environment Variables

You can use the following environment variables inside .env.example file:

# ENV=development
# DEBUG=true

Documentation


References