This is a sample project for creating a package in Python. It demonstrates how to structure a simple Python project, add CLI support, write tests with pytest, and run it like a command-line tool.
calculator_package/
│
├── calculator/ # Package source code
│ ├── __init__.py
│ ├── core.py # Calculator logic
│ └── cli.py # CLI interface
│
├── tests/ # Unit tests
│ ├── __init__.py
│ ├── test_core.py
│ └── conftest.py # Adds package to PYTHONPATH for tests
│
├── main.py # Entry point (CLI executable)
├── pyproject.toml
├── requirements.txt
├── setup.py
└── README.md
python -m venv venv
source venv/bin/activatepip install -r requirements.txtMake main.py executable:
chmod +x main.pyNow run:
./main.py add 2 3
# Output: Result: 5.0Make sure you add PYTHONPATH or use conftest.py.
pytestadd(a, b)subtract(a, b)multiply(a, b)divide(a, b)→ raises error on divide by zero
pip install -e .Now you can use it anywhere in the virtual environment.
MIT License
This project is designed for learning and testing how to properly create and structure a Python package with CLI and tests.