Metadata-Version: 2.4
Name: wkutils
Version: 0.1.6
Summary: Useful utilities for python
Author: Werner Kruger
Author-email: <python@wkruger.com>
Keywords: python,utilities,financial,calculator
Classifier: Development Status :: 1 - Planning
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Description-Content-Type: text/markdown
Requires-Dist: numpy_financial
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: keywords
Dynamic: requires-dist
Dynamic: summary

# wkutils
Utilities for python

## Usage

Import the package and call helpers directly from `wkutils`.

```python
import wkutils
```

### Mortgage helpers

Run a full mortgage simulation (returns a pandas DataFrame):

```python
import wkutils as wk
from datetime import date

df = wk.simulate_mortgage(
    principal=1_500_000,
    annual_rate=0.0435,
    years=30,
    gross_annual_income=276_000 * 1.08,
    woz_value=1_000_000,
    use_30_ruling=True,
    ruling_until_date=date(2028, 2, 8),  # use date, not string
)

print(df.head(12))  # first 12 months
```

`simulate_mortgage` returns data; it does not print a table. Use `print(df)` or `df.head()` to inspect results.

Create a summary table and average tax benefit for the first N months:

```python
import wkutils

df, table, avg_tax_benefit = wkutils.run_mortgage_scenario(
    principal=1_500_000,
    annual_rate=0.0435,
    years=30,
    gross_annual_income=250000 * 1.08,
    woz_value=1_000_000,
    months=36,
)

print(table)
print(avg_tax_benefit)
```

`prettytable` is only required when building/printing tables (`build_mortgage_table` or `run_mortgage_scenario`).

### KNSB rating helpers

Calculate a new rating after a series of games:

```python
import wkutils

new_rating, rows = wkutils.calculate_knsb_rating(
    old_rating=1486,
    opponent_ratings=[1424, 1227, 1476, 1750, 1485, 1505, 1389],
    results=[1, 1, 1, 0, 1, 1, 1],
)
```

Build a summary table with opponent names:

```python
import wkutils

new_rating, rows, table = wkutils.run_knsb_rating_scenario(
    old_rating=1486,
    opponent_ratings=[1424, 1227, 1476, 1750, 1485, 1505, 1389],
    opponents=["Joris", "Vedang", "Kaushik, Shashank"],
    results=[1, 1, 1, 0, 1, 1, 1],
)

print(table)
print("New rating:", new_rating)
```

`prettytable` is only required when building/printing tables (`build_knsb_rating_table` or `run_knsb_rating_scenario`).

## Publishing to PyPI

### Prerequisites

Install the build and upload tools:

```bash
python -m pip install --upgrade build twine
```

### PyPI token

Store your PyPI API token in `.secrets` on the first line. This file is gitignored and must never be committed.

```text
pypi-...
```

### Build and upload

Just run 
```
./scripts/release_pypi.sh
```

### Or manually:


0. If not installed:
python -m pip install --upgrade pip build twine

1. Bump the version in `setup.py`.
2. Remove old build artifacts (prevents local `build/` folder shadowing `python -m build`):

```bash
rm -rf build dist
```

3. Build the distribution:

```bash
python -m build
```

4. Upload to PyPI using the token from `.secrets`:

```bash
export TWINE_USERNAME=__token__
export TWINE_PASSWORD="$(head -n 1 .secrets)"
python -m twine upload dist/*
```

To upload a specific version only:

```bash
python -m twine upload "dist/wkutils-<version>*"
```

Replace `<version>` with the version you set in `setup.py`, for example `0.0.9`.

