hc-migrate
Two conversions for Jupyter notebooks and handcalcs:
--to ipynb: update notebooks written for handcalcs v1 so they work with handcalcs v2. They stay notebooks.--to py(the default): turn notebooks, written for v1 or v2, into handcalcs v2 scripts (.py), ready to render or publish.
$ hc-migrate beam.ipynb --to ipynb --output beam_v2.ipynb
$ hc-migrate beam.ipynb --to py --output beam.py
$ hc-migrate calcs/ --to py --output scripts --report report.md
exported Concrete/Basic Beam Shear.ipynb -> Basic Beam Shear.py (5 changes, 0 warnings)
exported Wood/Nails in single shear.ipynb -> Nails in single shear.py (15 changes, 2 warnings)
...
6 notebooks exported, 6 warnings.
Wrote scripts
Report: report.md
Without --output, a script is written next to its notebook (beam.py), and
a converted notebook gets _v2 in its name (beam_v2.ipynb; a folder is
copied to <folder>_v2). Existing files are never changed, unless you
pass --force.
Notebooks to scripts (--to py)
A script renders as its notebook showed (with handcalcs beam.py,
HandCalcs(...)(path) or YMPrint's _hc block):
| In the notebook | In the script |
|---|---|
| A Markdown cell | Comment lines: prose, and headings at the same level |
A %%render cell |
Its lines; settings its commands changed are set back after it |
| Any other code cell | Its lines between # hc: -i and # hc: -s: run, not shown (--show-code shows them) |
%render lines, display(Markdown(f"...")), calls to @handcalc(display=True) functions |
Shown |
Magics, ! commands, front matter |
Dropped |
A notebook written for handcalcs v1 is converted to v2 first; v1 or v2 is told
from the source (--from v1|v2 decides).
hc-migrate joins two earlier tools, handcalcs-migrate and nb_pyexporter.
Install
hc-migrate needs Python 3.11 or later (and black, which comes with it).
$ pipx install hc-migrate # or: uv tool install hc-migrate
$ uvx hc-migrate calcs/ # or run it once, without installing
The scripts and converted notebooks need handcalcs 2.0.
pip install "hc-migrate[nbconvert]" adds jupyter nbconvert --to hcpy.
v1 notebooks to v2 (--to ipynb)
The same conversion runs before a v1 notebook is exported with --to py.
A .py file written for v1 is converted too.
| handcalcs v1 | handcalcs v2 |
|---|---|
import handcalcs.render, %load_ext handcalcs.render |
import handcalcs |
from handcalcs.decorator import handcalc |
from handcalcs import handcalc |
%%render 2 |
%%render with # hc: -f .2f |
%%render sci_not, %%render 3 sci_not |
# hc: -f .3e |
%%render long |
# hc: -m |
%%render params |
# hc: -g above each run of assignments (a parameter grid) |
%%render symbolic |
# hc: mode = "ass sym" |
%%render short |
%%render (the default) |
%%tex (printed the LaTeX source) |
%%source latex (prints it in v2) |
%%render sympy |
# hc: -y: a name = name line whose right-hand name holds a SymPy expression runs as that expression |
## text between equations |
# text (in v2, ## is a heading) |
a # comment line (v1 didn't show it) |
the same comment, wrapped in # hc: -i / # hc: -s so it stays hidden |
x = 1 # ignore |
x = 1 # hc: -i |
@handcalc(override="long", precision=2) |
@handcalc(LatexRenderer(), render_context={"format_code": ".2f", "multiline": True}) |
@handcalc(jupyter_display=True) |
@handcalc(LatexRenderer(), display=True) |
| a decorated function with a docstring | adds docstring=False (v1 didn't render docstrings) |
latex, value = f(...) for a v1-decorated f |
value, latex = f(...) (v2 returns the value first) |
set_option("display_precision", 2) |
set_option("format_code", ".2f") |
set_option("param_columns", 4) |
set_option("param_cols", 4) |
options v2 removed (latex_block_start, custom_symbols, ...) |
commented out, with the reason |
v1's %%render arguments are read exactly as v1 read them, including its
habit of accepting part of a word (%%render param is params).
What it asks you to check
Some v1 code has no direct v2 equivalent. It is converted as far as it can be,
and listed under warnings (in the terminal and in --report):
@handcalc(left=..., right=...)and@handcalc(record=True).- Uses of a decorated function's result other than
latex, value = f(...): v1 returned(latex, value)and v2 returns(value, latex). custom_symbols,custom_brackets,greek_exclusionsand other removed options.
Names also render a little differently in v2: x_a_b is xa,b (not
nested), and phiM is φM. --v1-names keeps the v1 look.
Options
-o, --output DEST where to write: a file, or a folder for a tree
--to {py,ipynb} py: notebooks become v2 scripts (default);
ipynb: v1 notebooks are converted to v2 and stay notebooks
--from {auto,v1,v2} the handcalcs the source was written for (default: auto)
-f, --force overwrite files (or DEST) that exist (also --overwrite)
-n, --dry-run report what would be written, and write nothing
--report FILE also write the report to FILE (Markdown)
--show-code scripts: show the code cells the notebook didn't render
--no-black scripts: don't format with black
--keep-v1-precision v1: 3 decimal places where v1 used its default
(v2's default is 5 significant figures)
--v1-names v1: keep v1's nested subscripts and Greek names
--clear-outputs --to ipynb: clear the outputs of converted cells
--exclude PATTERN skip matching files and folders (repeatable)
--only-converted with a folder DEST, write only notebooks and Python files
-q, --quiet report only files with warnings
.git, .ipynb_checkpoints, __pycache__ and .venv are always skipped.
python -m hc_migrate is the same command.
See the handcalcs guide, Coming from handcalcs v1, for everything that changed.
Development
$ uv run --group test pytest
The tests convert a v1 notebook and run the result with handcalcs v2 in an IPython shell, so every converted cell is checked to work, and render the script exported from it with handcalcs.
License
Apache 2.0.
Metadata
Release files for hc-migrate 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hc_migrate-0.2.0.tar.gz | 28.9 kB | With provenance | Details for hc_migrate-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hc_migrate-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for hc_migrate-0.2.0-py3-none-any.whl |
Total release size: 61.1 kB
Release files / hc_migrate-0.2.0.tar.gz
| Download URL | hc_migrate-0.2.0.tar.gz |
|---|---|
| Size | 28.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7543706fdee109191bfe1a6d5936637a9db8ae7791f76868230c4085ed1237b8
|
|
BLAKE2b-256 checksum How to use checksums |
efad4b16c15a7938cf000d3e074de04965a3af7f848792d2e1ef0cc48c9d6349
|
| 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 23, 2026.
Transparency logRelease files / hc_migrate-0.2.0-py3-none-any.whl
| Download URL | hc_migrate-0.2.0-py3-none-any.whl |
|---|---|
| Size | 32.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d48c5078d43b4affc9320a3209c1bb2bb64ce2ed7c5d5fea9a5121fcbfd7d6d
|
|
BLAKE2b-256 checksum How to use checksums |
45e548b5911b19129c61abebcb89f16040045d0d08f338af1ab54d556864322d
|
| 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 23, 2026.
Transparency logSecurity for hc-migrate 0.2.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.
Attestation for hc_migrate-0.2.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 23, 2026.
Transparency logA 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.