Clean looking engineering calculations for IPython
Project description
ipycalc
Simple Engineering Calculations in Jupyter
Turn the contents of a Jupyter cell into a formatted calculation by following the steps below:
- Install
ipycalcusingpip install ipycalc - Use
from ipycalc import calcto bringipycalcinto your notebook's namespace. - Use
%%calcas the first line of a cell to indicate that you want to runipycalcon the contents of a cell.
The basic calculation syntax is:
Variable Description: variable_name = python_expression -> result_decimal_places*result_unit # Reference Text
Here's a simple example that calculates the flexural strength of a concrete beam:
Key components of the ipycalc syntax are:
:(required) The description must come before this character.=(optional) Used to assign a python expression to a variable name. Omit this if you simply want to reprint a previously defined variable.->(optional) Separates the python expression from the results formatting rules.*(optional) Indicate the number of decimals you want to see in the result to the left of the*, and the units you want to see in the result to the right.#(optional) Indicates reference text to the side of the calculation - handy for equation references or code references.
Here are a few useful things to keep in mind when using ipycalc:
- Subscripts can be added by using the
_character to indicate the start of a subscript. - Greek characters included in the
python_expressioncan just be written out (e.g.epsilon). To include greek characters in the Variable Description or the Reference Text, you can use Jupyter's Markdown Latex tags (e.g.$\epsilon$). Note that the greek characterpsiis ambiguous with the unit psi (pounds per square inch), so for that character specifically you'll need to use\grpsito tellipycalcyou want the greek character rather than the unit. - To stack fractions place the numerator and denominater in parentheses: (num)/(denom) yields $\dfrac{num}{denom}$.
ifstatements andelsestatements are available using python's inlineifstatement (terniary) notation.- Square roots can be displayed using
sqrt. - Prime characters can be displayed using
^prime. - If text gets to lengthy to fit on one line, you can add
\\to force a line break anywhere in a line. This can help your calculations fit within the page's print margins. ipycalcassists you with printing your notebooks. It has a built innbconverttemplate calledipycalcthat works just like thewebpdftemplate, except it fixes the the bad margins in thewebpdftemplate, and avoids page breaks right after headers. Any cells tagged withhide_cellwill not be rendered. Any cells tagged withhide_inputwill only show the output upon printing. You can select it from the file menu via "File -> Save and Export Notebook As... -> Ipycalc"
Sharing Variables Between Notebooks
ipycalc can save variables from one notebook and import them into another. This is useful when a project spans multiple notebooks (e.g. a loads notebook feeding into a beam design notebook).
Saving variables:
from ipycalc import save_vars
save_vars('my_notebook.ipynb')
This writes all user-defined variables — including pint quantities with units — to a sidecar file at .ipycalc_vars/my_notebook.json in the same directory as the notebook. The notebook file itself is never modified.
Importing variables:
from ipycalc import import_vars
import_vars('my_notebook.ipynb') # import all saved variables
import_vars('my_notebook.ipynb', 'P', 'L') # import specific variables only
Both functions are also available directly inside a %%calc cell without any import statement.
Variables are saved and loaded by filename only. Both notebooks must be in the same working directory.
IPycalc is still in development. There could be bugs, so be cautious and validate the answers it gives you. A special thanks to @connorferster for his project handcalcs which inspired this project. A link to handcalcs is here: https://github.com/connorferster/handcalcs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ipycalc-1.0.0.tar.gz.
File metadata
- Download URL: ipycalc-1.0.0.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5999f410cd6cb225fcf67cdf53444c9fa9da7a37ea2802bf89c97cf1b4be5b44
|
|
| MD5 |
0a4543b2a9ba3cdf5ee95dc83657489b
|
|
| BLAKE2b-256 |
420a9f4f92197bbf6400d065aefe22037dea1331c068af1a0dbcb46b4a967072
|
File details
Details for the file ipycalc-1.0.0-py3-none-any.whl.
File metadata
- Download URL: ipycalc-1.0.0-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9197424560c5f6e09f6949b3f2647fe6bb76f1c5e55d1537f2720b1119a9b77a
|
|
| MD5 |
3fbdc389de006623408e6ec11bffe6df
|
|
| BLAKE2b-256 |
c34cc2ee16c26899b8f2744d4313161bb186bb947c45b01a940aeb37613e07b9
|