Skip to main content

A class-based Python utility package for arithmetic, geometric sequences, and trigonometry

Project description

mathlib-evanjjh

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 the Arithmetic class only.

Features

  • Class-based API — Store two operands in an Arithmetic instance and call methods for each operation.
  • Basic operations — Addition, subtraction, multiplication, and division.
  • Safe division — Raises ValueError when dividing by zero.
  • Zero runtime dependencies — Works with Python 3.8+ only.
  • Tested — Unit tests with pytest.

Requirements

  • Python 3.8 or newer (development uses Python 3.13)

Installation

From PyPI

pip install mathlib-evanjjh

From source

git clone https://github.com/dschloe/mathlib-evanjjh.git
cd mathlib-evanjjh
pip install -e .

With uv:

uv sync

Quick Start

from 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...

Division by zero

Arithmetic(5, 0).divide()  # raises ValueError

API Reference

Arithmetic(a, b)

Create 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 — When b is 0 in divide().

Project Structure

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.

Development

1. Initialize the project (first-time setup)

This project was bootstrapped with uv:

uv init .
mkdir -p src/mathlib_evanjjh
touch src/mathlib_evanjjh/__init__.py
mkdir tests
touch tests/__init__.py

2. Install dev dependencies

uv sync --group dev

Dev dependencies (defined in pyproject.toml):

  • pytest>=8.0 — test runner
  • twine>=6.1.0 — PyPI upload tool

3. Run tests

uv run pytest tests/test_arithmetic.py -v

All five tests should pass:

  • test_add
  • test_subtract
  • test_multiply
  • test_divide
  • test_divide_by_zero

Publishing to PyPI

This section documents the workflow used to publish mathlib-evanjjh to PyPI.

Prerequisites

  1. Create a PyPI account.

  2. Generate an API token at https://pypi.org/manage/account/token/.

  3. Bump the version in pyproject.toml before 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.0 was published first; 0.1.1 was published after bumping the version.

Step 1 — Run tests

Always verify tests pass before building:

uv run pytest tests/test_arithmetic.py -v

Step 2 — Build distribution files

uv build

This 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 build

Step 3 — Configure PyPI credentials

Choose one of the following methods.

Option A: Environment variable (recommended for CI and local use)

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 publish

When prompted, enter:

  • Username: __token__
  • Password: your API token (or rely on UV_PUBLISH_TOKEN)

Option B: ~/.pypirc file

Create ~/.pypirc in your home directory:

[pypi]
username = __token__
password = pypi-<your-api-token>

Never commit API tokens to version control. Both .env and .pypirc are excluded via .gitignore.

Step 4 — Upload to PyPI

Using uv (built-in publish)

uv publish

Using twine (alternative)

Install twine as a dev dependency (already included):

uv add --dev twine

Upload with:

uv run twine upload dist/*

Use uv run twine rather than calling twine directly, 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>/

Release checklist

  1. Update version in pyproject.toml.
  2. Run tests: uv run pytest -v
  3. Build: uv build
  4. Upload: uv publish or uv run twine upload dist/*
  5. Verify on https://pypi.org/project/mathlib-evanjjh/
  6. Install and smoke-test: pip install mathlib-evanjjh==<version>

Roadmap

Planned additions (from the package description):

  • Geometric sequence utilities
  • Trigonometry helpers

License

This project is licensed under the MIT License.

Author

EvanJJHjhjung@dschloe.com

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mathlib_evanjjh-0.1.5.tar.gz (64.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mathlib_evanjjh-0.1.5-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file mathlib_evanjjh-0.1.5.tar.gz.

File metadata

  • Download URL: mathlib_evanjjh-0.1.5.tar.gz
  • Upload date:
  • Size: 64.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for mathlib_evanjjh-0.1.5.tar.gz
Algorithm Hash digest
SHA256 42a100b568b56d1c26209e5f2faa81dc121a437bb56ecc5ef75e3f648417ae1a
MD5 d7c668bfc4839564dfc74ffffd6c17da
BLAKE2b-256 f8cf5cf1960800883e370b0bfb52ac4d6b8cf57c35c1fc84b47806dec31082e5

See more details on using hashes here.

File details

Details for the file mathlib_evanjjh-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for mathlib_evanjjh-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 0fe84482b72ef18536ec0577c524a1ce7effdf60a5b4c8e09c2093dc00fba15f
MD5 1ab4a838e09a18eb21daac1a012ef0ac
BLAKE2b-256 3bd2576caf05f9347c5108557070930f0ec02fc8a2a5d56805f1795c62214eb8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page