my_template
is a template for python package.
- Template for python package.
- Other features...
- Python (>= v3.7)
- PyPi (>= v21)
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
- Download
.whl
or.tar.gz
file from releases - https://github.com/bybatkhuu/module.python-template/releases - 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}"
To use my_template
, import the MyBase
class from the package:
from my_template import MyBase, BaseConfig
my_base = MyBase()
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
To run tests, run the following command:
# Install python test dependencies:
pip install -r ./requirements.test.txt
# Run tests:
python -m pytest -sv
You can use the following environment variables inside .env.example
file:
# ENV=development
# DEBUG=true
- Python Packaging User Guide - https://packaging.python.org
- Python Packaging Tutorial - https://packaging.python.org/en/latest/tutorials/packaging-projects