Data scientists often develop analysis scripts incrementally, inspecting the results and re-running after making a small edit. Computational notebooks persist the Python state to aid exploration by avoiding recomputation between runs. However, since they rely on the user to re-execute individual cells, notebooks allow their state to silently diverge from the code.
We introduce Pync, which incrementally executes Python scripts correctly at the function level. \sys efficiently traces function calls by instrumenting the script to record dependencies and side effects. On subsequent executions, Pync restores expensive function calls from its cache. On two sample data science benchmarks, Pync achieves $1.6\times$ and $4.8\times$ speedups on re-execution with only $1.2\times$ and $1.04\times$ overhead on the first run.