Skip to main content

KiwiCalc

Write mathematics naturally in Python.

CI Coverage PyPI version PyPI downloads Python versions License

KiwiCalc function examples

KiwiCalc is a Python mathematics library built around readable, math-like expressions. It combines symbolic expressions, equation solving, numerical methods, geometry, linear algebra, plotting, probability, sequences, and printable worksheets behind one approachable API.

Why KiwiCalc?

Python is excellent for numerical work, but sophisticated mathematical expressions can become difficult to read and manipulate. KiwiCalc lets you construct expressions with familiar notation, substitute values, simplify them, convert them to callable functions, solve equations, and visualize results.

import kiwicalc as kw

x = kw.Var("x")
expression = x**2 + 6*x + 8

print(expression)                         # x^2+6x+8
print(expression.when(x=2).try_evaluate())  # 24
print(kw.solve_quadratic(1, 6, 8))       # (-2, -4)

Installation

Install the latest published version from PyPI:

python -m pip install kiwicalc

KiwiCalc supports Python 3.8 and newer.

Quick tour

Expressions and functions

import math
import kiwicalc as kw

x = kw.Var("x")
wave = kw.Sin(x) + kw.Cos(x)

print(wave.when(x=math.pi).try_evaluate())

parabola = kw.Function("f(x) = x^2 + 2x + 1")
print(parabola(3))  # 16

Equations

import kiwicalc as kw

print(kw.solve_linear("3x + 5 = 8"))
print(kw.solve_quadratic(1, 6, 8))

system = kw.LinearSystem((
    "x + y = 5",
    "2x - y = 1",
))
print(system.get_solutions())

Linear algebra and geometry

import kiwicalc as kw

matrix = kw.Matrix([[1, 2], [3, 4]])
vector = kw.Vector([3, 4])
point = kw.Point2D(2, 5)

print(matrix.determinant())
print(vector.length())
print(point)

Plotting

import kiwicalc as kw

x = kw.Var("x")
(kw.Sin(x) + 0.25*x).plot(start=-10, stop=10)

What is included?

  • Symbolic monomials, polynomials, fractions, roots, logarithms, trigonometry, factorials, and composite expressions
  • Linear, quadratic, cubic, quartic, polynomial, and system solving
  • Numerical root-finding, integration, differentiation, and optimization methods
  • Callable functions, function collections, and function chains
  • Matrices, vectors, points, lines, circles, surfaces, and point collections
  • Two- and three-dimensional plotting with Matplotlib
  • Arithmetic, geometric, and recursive sequences
  • Probability trees
  • PDF exercise and worksheet generation
  • JSON serialization for supported expression types

Documentation and learning resources

Development

Create an isolated environment and install the project with its development tools:

python -m venv .venv
# Windows PowerShell: .\.venv\Scripts\Activate.ps1
# macOS/Linux: source .venv/bin/activate
python -m pip install --editable ".[dev]"
python -m pytest --cov=kiwicalc --cov-report=term-missing

Pull requests and pushes to main run the test suite on Linux and Windows. Published GitHub Releases are built, validated, and uploaded to PyPI through Trusted Publishing when the release tag matches the version in pyproject.toml.

Security note

KiwiCalc currently compiles some math-like expression strings into Python callables. Only evaluate expression strings from sources you trust; do not pass untrusted user input directly into the parser.

License

KiwiCalc is available under the MIT License.

Download files

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

Source Distribution

kiwicalc-1.0.1.tar.gz (117.9 kB view details)

Uploaded Source

Built Distribution

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

kiwicalc-1.0.1-py3-none-any.whl (141.6 kB view details)

Uploaded Python 3

File details

Details for the file kiwicalc-1.0.1.tar.gz.

File metadata

  • Download URL: kiwicalc-1.0.1.tar.gz
  • Upload date:
  • Size: 117.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kiwicalc-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1fd7aef34a761d6fed97b192b6f45d71c7c2c1883b0f7a60447e242938c6a585
MD5 23a2e515c1783927dceba83a75c23506
BLAKE2b-256 b4cf63d97d68a72d9797bb404e9f21c4da06249cf1a3271f206e3a8342e6bd97

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiwicalc-1.0.1.tar.gz:

Publisher: release.yml on jonaprojects/kiwicalc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kiwicalc-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: kiwicalc-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 141.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kiwicalc-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2791e1c7f20b22afae79c646e5ecb99c503c255d49c0587a294fb2828f028a5
MD5 58a3e947498f6fa2bb86e05d147aebc3
BLAKE2b-256 81948ac02b3015adeb9b7f779a663311a49cddc37bf1a3c5007015a86e4bbfae

See more details on using hashes here.

Provenance

The following attestation bundles were made for kiwicalc-1.0.1-py3-none-any.whl:

Publisher: release.yml on jonaprojects/kiwicalc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

0.21.3

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.2.3

2 files

0.2.0

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

Supported by

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