Skip to main content

Useful utilities for python

Project description

wkutils

Utilities for python

Usage

Import the package and call helpers directly from wkutils.

import wkutils

Mortgage helpers

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

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:

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:

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:

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:

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.

pypi-...

Build and upload

Just run

./scripts/release_pypi.sh

Or manually:

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

  2. Bump the version in setup.py.

  3. Remove old build artifacts (prevents local build/ folder shadowing python -m build):

rm -rf build dist
  1. Build the distribution:
python -m build
  1. Upload to PyPI using the token from .secrets:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD="$(head -n 1 .secrets)"
python -m twine upload dist/*

To upload a specific version only:

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

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

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

wkutils-0.1.6.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

wkutils-0.1.6-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file wkutils-0.1.6.tar.gz.

File metadata

  • Download URL: wkutils-0.1.6.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wkutils-0.1.6.tar.gz
Algorithm Hash digest
SHA256 70e322f942d2325dd444c86ca6f6cd97ba021fbd9fa82ef0b636b797a266d6d0
MD5 77e1d300b97c0a57c55000389710c7d5
BLAKE2b-256 106b68aef36dcced31903c3b64f73ff568096cedc49352849d685820ff4c6fbd

See more details on using hashes here.

File details

Details for the file wkutils-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: wkutils-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for wkutils-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 40f567653d155b9d4bd23d3fa734f53eead18369bd4dcf63ee50ee2db32c480b
MD5 4857340705376a1e7d2bd816d26ebc9b
BLAKE2b-256 f6d228353aa338712857bb45f63ffebfb720286cebc9535672eaa67cd8cb8b08

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