Skip to main content

Tests Code style: black PyPI version Python versions License Downloads

handcalcs cover art
Cover art by Joshua Hoiberg

handcalcs:
Python calculations,
as though you wrote them by hand.

handcalcs turns ordinary Python calculation code into a formatted calculation: the symbolic formula, then the formula with every value substituted in, then the result. Because the substitution step is shown, anyone can check the calculation by hand.

The same calculation can go to different renderers: Markdown and LaTeX for Jupyter and documents, HTML for web pages, ASCII text for terminals and logs, a live, formula-based Excel worksheet and Word documents. You can restyle the built-in renderers or write your own.

handcalcs 2.0

handcalcs 2.0 is a rewrite. If you're coming from 1.x, read Coming from handcalcs v1; to stay on 1.x for now, install "handcalcs<2".

Read the v2 documentation: getting started, every renderer, a cookbook of recipes, and how to customize or write a renderer.

Example

from math import sqrt   # hc: -i
## Hypotenuse of a right triangle
# Both sides are measured from the site drawings.
a = 2.5  # Side a, in m
b = 4.0  # Side b, in m
c = sqrt(a**2 + b**2)

In Jupyter this is typeset as maths. With the ASCII renderer it reads:

==============================
Hypotenuse of a right triangle
==============================

Both sides are measured from the site drawings.
a = 2.5 (Side a, in m)
b = 4 (Side b, in m)
c = √(a² + b²) = √(2.5² + 4²) = 4.717

Installing

pip install handcalcs

handcalcs needs Python 3.11 or newer. Extras add the Excel and Word renderers (handcalcs[excel], handcalcs[word]). See Installation.

Quick start

In Jupyter, import handcalcs once, then start any cell with %%render:

import handcalcs
%%render
a = 2
b = 3
c = 2*a + b/3

From a script, render a string or a .py file with any renderer:

import pathlib
from handcalcs import HandCalcs
from handcalcs.renderers import LatexRenderer

latex = HandCalcs(LatexRenderer())(pathlib.Path("beam.py"))

On a function, @handcalc(renderer) returns the result and the rendered calculation.

Renderers

Markdown (the Jupyter default), LaTeX, HTML, ASCII text, a live formula-based Excel workbook, and Word documents with native equations. Subclass one to change its look, or write your own. See Renderers.

Upgrading from handcalcs 1.x

handcalcs 2 is a rewrite around a parsed node tree and pluggable renderers. Most notebooks need only a few changes: import handcalcs instead of import handcalcs.render, and # hc: comment commands instead of %%render arguments. See Coming from handcalcs v1.

Gotchas

Jupyter cells can run out of order. handcalcs looks up values in the notebook's namespace, so if you re-use variable names, a cell run out of order can render a beautiful but completely incorrect calculation. Run your notebook top to bottom before you rely on it.

If you use handcalcs for any kind of reporting that may become a legal document (e.g. design engineering calculations), it is up to YOU to ensure that the results are what you expect them to be. handcalcs is free and open-source software, and the author(s) are not responsible for incorrect calculations that result from its use.

That said, the whole point of showing the substitution is to make calculations easy to check by hand.

YouTube tutorials

These cover handcalcs 1.x; the ideas carry over.

License

Apache 2.0. See LICENSE.

Metadata

Release files for handcalcs 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for handcalcs 2.0.0
File Size Uploaded Provenance Actions
handcalcs-2.0.0.tar.gz 200.2 kB With provenance Details for handcalcs-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for handcalcs 2.0.0
File Interpreter ABI Platform Actions
handcalcs-2.0.0-py3-none-any.whl Python 3 none any Details for handcalcs-2.0.0-py3-none-any.whl

Total release size: 425.3 kB

Release files / handcalcs-2.0.0.tar.gz

Download URL handcalcs-2.0.0.tar.gz
Size 200.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6f189c404c630c4e0117284d6de6ac357c5e2f074d49293c558d99f3dcb3764a
BLAKE2b-256 checksum
How to use checksums
7a4fad909f386fec25bc9034d2ca4f26fe9422f976ec2715c04c76b0aae5d55e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / handcalcs-2.0.0-py3-none-any.whl

Download URL handcalcs-2.0.0-py3-none-any.whl
Size 225.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4e25ab4bd3c2a9897a9dc5b4ad765b66b1632d1f07b2c8c6385f4a173862d9da
BLAKE2b-256 checksum
How to use checksums
cf6585a67390085518743e17ac1c4b80e562f3de7d92ff6474bbbd0689e83ac5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for handcalcs 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for handcalcs-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page