A lightweight, class-based Python utility library for basic arithmetic operations. This package was created for educational purposes to demonstrate Python project structure, testing, packaging, and PyPI distribution.
PyPI: https://pypi.org/project/mathlib-evanjjh/
The package description mentions geometric sequences and trigonometry as future scope. The current release (
0.1.1) ships theArithmeticclass only.
- Class-based API — Store two operands in an
Arithmeticinstance and call methods for each operation. - Basic operations — Addition, subtraction, multiplication, and division.
- Safe division — Raises
ValueErrorwhen dividing by zero. - Zero runtime dependencies — Works with Python 3.8+ only.
- Tested — Unit tests with pytest.
- Python 3.8 or newer (development uses Python 3.13)
pip install mathlib-evanjjhgit clone https://github.com/dschloe/mathlib-evanjjh.git
cd mathlib-evanjjh
pip install -e .With uv:
uv syncfrom mathlib_evanjjh.arithmetic import Arithmetic
calc = Arithmetic(10, 3)
print(calc.add()) # 13
print(calc.subtract()) # 7
print(calc.multiply()) # 30
print(calc.divide()) # 3.333...Arithmetic(5, 0).divide() # raises ValueErrorCreate an instance with two numeric operands a and b.
| Method | Description | Returns |
|---|---|---|
add() |
Returns a + b |
int or float |
subtract() |
Returns a - b |
int or float |
multiply() |
Returns a * b |
int or float |
divide() |
Returns a / b |
float |
Raises
ValueError— Whenbis0individe().
mathlib-evanjjh/
├── src/
│ └── mathlib_evanjjh/
│ ├── __init__.py
│ └── arithmetic.py # Arithmetic class
├── tests/
│ ├── __init__.py
│ └── test_arithmetic.py # Unit tests
├── main.py # Entry script (placeholder)
├── pyproject.toml # Package metadata and build config
├── uv.lock # Locked dependencies (uv)
├── LICENSE # MIT License
└── README.md
The project uses the src layout: importable code lives under src/mathlib_evanjjh/, which keeps the installed package separate from the project root during development.
This project was bootstrapped with uv:
uv init .
mkdir -p src/mathlib_evanjjh
touch src/mathlib_evanjjh/__init__.py
mkdir tests
touch tests/__init__.pyuv sync --group devDev dependencies (defined in pyproject.toml):
pytest>=8.0— test runnertwine>=6.1.0— PyPI upload tool
uv run pytest tests/test_arithmetic.py -vAll five tests should pass:
test_addtest_subtracttest_multiplytest_dividetest_divide_by_zero
This section documents the workflow used to publish mathlib-evanjjh to PyPI.
-
Create a PyPI account.
-
Generate an API token at https://pypi.org/manage/account/token/.
-
Bump the version in
pyproject.tomlbefore each new release. PyPI does not allow re-uploading the same file name; attempting to publish an existing version returns:400 File already exists ('mathlib_evanjjh-0.1.0-py3-none-any.whl', ...)In this project, version
0.1.0was published first;0.1.1was published after bumping the version.
Always verify tests pass before building:
uv run pytest tests/test_arithmetic.py -vuv buildThis produces two files under dist/:
mathlib_evanjjh-<version>.tar.gz(source distribution)mathlib_evanjjh-<version>-py3-none-any.whl(wheel)
Example output:
Successfully built dist/mathlib_evanjjh-0.1.1.tar.gz
Successfully built dist/mathlib_evanjjh-0.1.1-py3-none-any.whl
If you need a clean rebuild, remove the old artifacts first:
rm -rf dist/
uv buildChoose one of the following methods.
Create a .env file in the project root (already listed in .gitignore):
UV_PUBLISH_TOKEN=pypi-<your-api-token>Then publish with uv:
source .env
uv publishWhen prompted, enter:
- Username:
__token__ - Password: your API token (or rely on
UV_PUBLISH_TOKEN)
Create ~/.pypirc in your home directory:
[pypi]
username = __token__
password = pypi-<your-api-token>Never commit API tokens to version control. Both
.envand.pypircare excluded via.gitignore.
uv publishInstall twine as a dev dependency (already included):
uv add --dev twineUpload with:
uv run twine upload dist/*Use
uv run twinerather than callingtwinedirectly, since twine is installed in the project virtual environment.
On success, PyPI returns a link to the release page:
https://pypi.org/project/mathlib-evanjjh/<version>/
- Update
versioninpyproject.toml. - Run tests:
uv run pytest -v - Build:
uv build - Upload:
uv publishoruv run twine upload dist/* - Verify on https://pypi.org/project/mathlib-evanjjh/
- Install and smoke-test:
pip install mathlib-evanjjh==<version>
Planned additions (from the package description):
- Geometric sequence utilities
- Trigonometry helpers
This project is licensed under the MIT License.
EvanJJH — jhjung@dschloe.com