Skip to main content

calc_rs

A strongly typed, spreadsheet-style expression engine — currency, tonnage, percentages, dates, durations, and tables are distinct first-class types, not just decorated numbers. A Rust rewrite of Attica-oss/calc, usable as a CLI, a Rust library, or a Python extension module.

Install

CLI — a prebuilt binary, no Rust toolchain needed:

uv tool install calc-rust          # then run: calc_rs
uvx --from calc-rust calc_rs '$5.00 * 3'
pipx install calc-rust

or from source:

cargo install --path . --bin calc_rs

Python library (import calc_rs) — also ships the CLI as python -m calc_rs, for locked-down environments that block standalone executables but allow pip packages:

pip install calc-rs-lang
python -m calc_rs '$5.00 * 3'
python -m calc_rs                 # REPL

(The pure-Python front end has no line editing or syntax highlighting, but the same value formatting — tables and all — via calc_rs.render.)

CLI usage

calc_rs '$5.00 * 3'            # $15.00  (currency)
calc_rs                        # start the REPL
calc_rs --bare '1 + 2 * 3'     # 7        (value only, for scripts)

Statements are separated by ; or a newline, so scripts read naturally:

calc_rs $'let price = $12.50\nlet qty = 3\nprice * qty'   # $37.50

A newline inside an expression is insignificant (1 +⏎2 is 3), and the REPL keeps taking input while a line has an open (/[ or ends on an operator — so multi-line table(...) / sort(filter(...)) just work. Press Enter on a blank line twice to force-submit anyway and let the parser point at whatever's unbalanced.

Tab completes function names, plus the variables and fns you've defined this session (sel⇥ → select).

Editor support

calc_rs_lsp is a Language Server (diagnostics, completion, hover) — cargo install --path . --bin calc_rs_lsp --features lsp, then see docs/LSP.md for editor wiring.

Tables

Tables are ordinary values — build, edit, query, and persist them with functions, in the REPL or one-shot:

table("item:text, qty:int, price:currency")   # empty, typed
column("day", "Mon", "Tue")                    # a named column
table(column("x", 1, 2), column("y", 3, 4))    # from columns

append(t, "Bolt", 250, $0.08)     # add a row      (type-checked)
extend(t, "total", [qty] * [price])   # add a computed column
setcell(t, 0, "qty", 5)           # replace one cell
droprow(t, 2)  ·  rename(t, "price", "unit_price")

select(t, "item", "total")  ·  filter(t, [qty] > 100)
sort(t, [total], "desc")  ·  groupby(t, "item", "total", "sum")

open("sales.json")                # read a JSON workbench file
save(sort(open("sales.json"), [total], "desc"), "ranked.json")

Each verb returns a new table, so they compose. [col] inside filter / sort / extend refers to that column in the current row.

Python usage

import calc_rs

calc_rs.evaluate("$5.00 * 3")          # Currency($15.00)
calc_rs.evaluate("1 + 2 * 3")          # 7
calc_rs.check("$5.00 * 3")             # 'currency'  (no evaluation)

calc = calc_rs.Calculator()
calc.set("price", calc_rs.Currency("12.50"))
calc.eval("let qty = 3")
calc.eval("price * qty")               # Currency($37.50)
calc.get("qty")                        # 3

Currency, tonnage, percent, duration, and complex results come back as dedicated classes — Currency/Tonnage/Percent expose .amount, Duration exposes .months/.days/.seconds, Complex exposes .real/.imag. Numbers, text, booleans, and dates/times come back as native Python types. The wheel ships a type stub and py.typed.

Rust library

[dependencies]
calc_rs = { git = "https://github.com/Attica-oss/calc_rs" }

Everything the common cases need is re-exported at the crate root (or grab it in one line with use calc_rs::prelude::*):

use calc_rs::prelude::*;

// one-shot: an expression or a full `let x = 5; x + 1` script
let out = evaluate("$5.00 * 3")?;
assert_eq!(out.to_string(), "$15.00");
assert_eq!(out.ty.to_string(), "currency");

// a session that remembers variables and `ans`, like the REPL
let mut calc = Calculator::new();
calc.eval("let price = $12.50")?;
calc.eval("let qty = 3")?;
assert_eq!(calc.eval("price * qty")?.to_string(), "$37.50");

// type-check without evaluating
assert_eq!(calc.check("price * qty")?.to_string(), "currency");

evaluate and Calculator::eval return an Evaluated — value (a Value), ty (the inferred Type), bindings (every let the script made), assigned, and used_vars. For a custom function registry, drop to calc_rs::run_script(source, vars, functions).

Notebook

A marimo notebook backed by this engine lives in notebook/, replicating the expression-editor and table-builder workflow of the original Python project's notebook:

pip install -e '.[notebook]'
maturin develop --release
marimo edit notebook/calc_notebook.py

Development

cargo test                     # engine tests
maturin develop --release      # build + install the Python extension

License

MIT — see LICENSE.

Release files for calc-rs-lang 0.2.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 calc-rs-lang 0.2.0
File Size Uploaded
calc_rs_lang-0.2.0.tar.gz 215.2 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for calc-rs-lang 0.2.0
File
calc_rs_lang-0.2.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details
calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details
calc_rs_lang-0.2.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
calc_rs_lang-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 7.9 MB

Release files / calc_rs_lang-0.2.0.tar.gz

Download URL calc_rs_lang-0.2.0.tar.gz
Size 215.2 kB
Tags Source
SHA-256 checksum
How to use checksums
056c14bc0b92c81ebb2c13893777eaa9504709f610e3de116268629b6ea69790
BLAKE2b-256 checksum
How to use checksums
df9fb76a7479b8857cb490814d66a81b0b232910aa168c0d0ad9b7d31078bdfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / calc_rs_lang-0.2.0-cp310-abi3-win_amd64.whl

Download URL calc_rs_lang-0.2.0-cp310-abi3-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
118bd22979bcf7043dca2de4bb2deafcc5ab4b1c5f57f2670ab24cdf4d03683a
BLAKE2b-256 checksum
How to use checksums
d455ad4f63d95a81d545d078eee8ac956dbb99932048db968306605182bf7d7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
30cd9f00f1ae2307eab40237594d325c74d71d110f0369809e8069bea39b8218
BLAKE2b-256 checksum
How to use checksums
73f15f7d9f6ae3007b6199444133e1011d1be294462523abc07d647f3a0df8fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL calc_rs_lang-0.2.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
75aad7bcdcc74c5c7b1e5b99e3c22d69c8b49692bf417f75a69a025a11b45ff4
BLAKE2b-256 checksum
How to use checksums
82d0132d3fb03f8d9368db8fecc52c9b2b0170756b7e1f0db9754b1ab069ff7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / calc_rs_lang-0.2.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL calc_rs_lang-0.2.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6e33b001439541179cdaaffa68591a4b64a078f4303f7ce042c049f9c27ea087
BLAKE2b-256 checksum
How to use checksums
bccbf2ca414e9b299b5782b411bc932ee0d7d51b91c428a4a535160b6169cbdf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release files / calc_rs_lang-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL calc_rs_lang-0.2.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
ee0aa0dcc9ab51cb8b82827648aa4707997f0e688b0c175bc6721a07c650ea62
BLAKE2b-256 checksum
How to use checksums
c23061790aa4a25dfe130309b71899c8259e101c2248a09bac9c76bbceba90cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.1

6 release files

This release

0.2.0 This release

6 release files

0.1.0

1 release file

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