Skip to content

SimoneGuidi/pycalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyCalc — Web Calculator with Python & Flask

A single-page web calculator with a Flask backend and vanilla HTML/CSS/JS frontend. Mathematical expressions are evaluated server-side using Python's ast module — never eval().

Tech Stack

  • Python 3 + Flask — two-route backend (/ and /calculate)
  • AST-based safe evaluator — whitelist-only operator dispatch, no arbitrary code execution
  • Vanilla JS — event delegation, keyboard support, fetch API

Architecture

Browser  ──POST /calculate──▶  Flask (app.py)
         ◀──JSON { result }──

The frontend sends the expression as JSON; Flask parses it through safe_eval, which walks the AST and only allows nodes present in the SAFE_OPERATORS dispatch table. Any other construct (function calls, imports, attribute access) raises ValueError.

Run locally

cd pycalc
pip install -r requirements.txt
python app.py

Open http://localhost:5001 in your browser.

Why these choices

  • Flask over Django — two routes, no database, no auth; Django would be overkill
  • ast over eval() — prevents arbitrary code execution even in a local project
  • Server-side evaluation — the frontend only builds the string and displays the result

About

Calcolatrice web con Python Flask

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors