A modern engineering calculator built with FastAPI and a responsive static web UI.
- Degree, radian, and gradian angle modes
- Arithmetic, powers, percentages, logarithms, trigonometric functions, roots, factorials, and engineering constants
- Calculation history and memory keys in the browser
- Safe expression evaluation without Python
eval - JSON API at
POST /api/calc
Create and activate a virtual environment, then install the dependencies:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\\Scripts\\activate
python -m pip install -r requirements.txtStart the server:
uvicorn calculator:app --reloadOpen http://127.0.0.1:8000 in your browser.
Send an expression to the calculation endpoint:
curl -X POST http://127.0.0.1:8000/api/calc \
-H "Content-Type: application/json" \
-d '{"expression":"sin(30) + sqrt(16) * 2","angle_mode":"DEG"}'Response:
{
"expression": "sin(30) + sqrt(16) * 2",
"result": 8.5,
"formatted": "8.5",
"angle_mode": "DEG"
}The request supports DEG, RAD, and GRAD angle modes. Previous results can be supplied using the ans field.
Functions include sin, cos, tan, asin, acos, atan, log, log10, ln, sqrt, cbrt, abs, exp, floor, ceil, factorial, hypot, sinh, cosh, and tanh where applicable.
Constants include pi, e, tau, phi, and ans. The UI also provides quick-access values for the speed of light and standard gravity.
calculator.py FastAPI app and safe calculation engine
Calculator.py Compatibility entrypoint
static/index.html Calculator interface
static/styles.css UI styling
static/app.js UI behavior and API client
requirements.txt Python dependencies
✌️