Skip to main content

A notepad calculator that evaluates expressions in text files

Project description

calced

A notepad calculator that evaluates math expressions in plain text files. Available as a CLI tool and a web app — both use the same syntax and are validated against the same test suite.

Web

Open the web app in a browser — no install required.

CLI

calced <file>           # evaluate and update file in place
calced -s <file>        # print result to stdout (don't modify file)
calced -w <file>        # watch for changes and auto-update
calced -w -s <file>     # watch and print (clears screen on change)

Installation

Requires Python 3.9+.

# With uv (recommended)
uv tool install ./python

# Or just run the script directly
python python/calced.py <file>

How it works

Write math anywhere in a plain text file. Results are appended inline as # => result comments. Non-math lines are left untouched.

rent 1500                               # => 1_500
groceries 200 + 150                     # => 350
utilities 80 + 45 + 30                  # => 155
total                                   # => 2_005

Results are aligned and updated in place each time you run the CLI (or automatically in watch mode), or live as you type in the web app.

Features

Basic arithmetic

2 + 3                                   # => 5
10 * (4 + 6)                            # => 100
2 ^ 10                                  # => 1_024
17 % 5                                  # => 2

Variables

income = 5000                           # => 5_000
tax_rate = 22%                          # => 0.22
tax = income * tax_rate                 # => 1_100
after_tax = income - tax                # => 3_900

Percentages

50% of 300                              # => 150
200 + 15%                               # => 230
200 - 10%                               # => 180

SI prefixes

1k                                      # => 1_000
1M                                      # => 1_000_000
1.5G                                    # => 1_500_000_000
500n * 2                                # => 0.000001

Supported: k/K (kilo), M (mega), G (giga), T (tera), P (peta), E (exa), m (milli), u/μ (micro), n (nano), p (pico), f (femto), and more.

Unit conversions

5 km in miles                           # => 3.11
100 C in F                              # => 212
1 gib in mib                            # => 1_024
60 min in hr                            # => 1
1 gal in l                              # => 3.79

Supported dimensions: length, mass, temperature, data, time, volume. Use in or to.

Functions

sqrt(16)                                # => 4
round(3.14159, 2)                       # => 3.14
min(5, 2, 8)                            # => 2
max(1, 9, 3)                            # => 9
log10(1000)                             # => 3
sin(0)                                  # => 0

Available: sqrt, abs, floor, ceil, round, log, log2, log10, sin, cos, tan, asin, acos, atan, exp, min, max

Constants

pi * 2                                  # => 6.28
e ^ 1                                   # => 2.72

Totals

The total (or sum) keyword sums all numeric results since the last # heading or start of file.

rent 1500                               # => 1_500
groceries 350                           # => 350
utilities 155                           # => 155
total                                   # => 2_005

Blank lines are ignored in the total; headings reset it.

Number formats

Numbers can be written with commas or underscores as separators (1,000 or 1_000), in hex/binary/octal (0xFF, 0b1010, 0o77), or in scientific notation (1.5e3).

Trailing annotations

Parenthetical notes after an expression are ignored:

celo_price = 0.08 (see http://coinmarketcap.com)  # => 0.08

Format directives

Control output formatting with @format and @separator directives. These apply to all subsequent lines until changed.

1000000                                 # => 1_000_000
@format = fixed(2)
1000000                                 # => 1_000_000.00
@format = scientific
1000000                                 # => 1.00e+06
@separator = comma
@format = minSig(3)
1000000                                 # => 1,000,000

Project details


Download files

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

Source Distribution

calced-0.1.0.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

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

calced-0.1.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file calced-0.1.0.tar.gz.

File metadata

  • Download URL: calced-0.1.0.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for calced-0.1.0.tar.gz
Algorithm Hash digest
SHA256 aaf0f509703621a72a9c9b8d63b6fd1926b8a3e00fa2af26223076ec46a3d985
MD5 b0cf8abd63632da248da1b3b698b250a
BLAKE2b-256 13e26aa37807142223ded952c69f9bbd18a07aec1a617b357b250ccbc27b417a

See more details on using hashes here.

File details

Details for the file calced-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: calced-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for calced-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30ad4ae18775dcfdc55de61eb53acd33ac2ede32b854ea1bba83b546a056190f
MD5 eb5e79dc4f2644aede84184d9e69c2bb
BLAKE2b-256 afa5914f2e920986017e602aa9f5c6c8560dcbf91c96d2d5d90975fe60ea4cf9

See more details on using hashes here.

Supported by

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