Packages
Programs that use the packages people work with: solvers, web apps, physics, data and machine learning. primopy's Python comes with several hundred packages built for the browser, numpy, pandas, matplotlib, scipy and scikit-learn among them, and installs any other package written in pure Python from PyPI when you ask for it. Each card opens its project in primopy with the packages it needs. Press Run, then change something and run it again.
For starters
First programs that draw, with turtle or on primopy's own canvas, and a run to step through and back.
turtleA spiral, step by step
A turtle walks and turns 120 times. Record the run and drag the tape back: the spiral un-draws.
▶Open in primopy
primopy drawA tree that draws itself
A recursive function draws a branch and two smaller ones at its end, 1023 in all. Record the run and drag the tape back: the tree shrinks.
▶Open in primopyOptimization
Write a problem down, and a solver finds the best answer and proves it.
Status: Optimal
white: 192.9 loaves
rye: 0.0 loaves
sourdough: 42.9 loaves
profit: 330.00 CHFhighspyA bakery's best plan
A linear program: how many loaves of each bread make the most profit with the flour, oven time and labour there is. Solved by HiGHS.
▶Open in primopy tent 2.2 kg usefulness 10
stove 0.8 kg usefulness 6
water 1.5 kg usefulness 9
rain jacket 0.5 kg usefulness 7
snacks 0.7 kg usefulness 5
first aid 0.3 kg usefulness 8
weight 6.0 kg, usefulness 45pulpPacking for a hike
A knapsack problem written the way it reads on paper, with PuLP: which items make the pack most useful within 6 kg. Solved by HiGHS.
▶Open in primopyScheduling jobs on machines
Google OR-Tools' CP-SAT orders five jobs on three machines so that all are done as early as possible, and draws the schedule.
▶Open in primopyLight or stiff: two goals at once
A genetic algorithm, NSGA-II, finds the beams where neither weight nor stiffness can improve without the other getting worse.
▶Open in primopyA hanging chain
CasADi states the chain's energy and its link lengths, and Ipopt, a nonlinear solver, finds the shape it hangs in.
▶Open in primopyWeb apps
An app the program serves opens live on the Plots tab, with no server anywhere: its sliders, forms and pages work there.
streamlitA savings plan
A Streamlit app with three sliders, a number that follows them and a chart of the money growing.
▶Open in primopy
shinyDice and the bell curve
A Shiny Express app: choose how many dice, and the histogram of their sums is drawn again.
▶Open in primopy
fastapiA notes service
A FastAPI service with a web page of its own that reads and adds notes with fetch(), as a page on a real server would.
▶Open in primopySimulation
Physics in 3D, and queues played through event by event.
mujocoChaos: two double pendulums
MuJoCo, the physics engine of robotics research, swings two double pendulums started a thousandth of a radian apart. For a few seconds they move as one, then each goes its own way. Turn the view with the mouse.
▶Open in primopyThe queue at the post office
SimPy plays through a day with two counters and customers arriving at random: how long does the line get?
▶Open in primopyData and plots
Read a table, sum it up and draw it, still or live.
How long is the day?
One formula for the hours of daylight, drawn twice with matplotlib: the year in four cities, with a shaded area and an arrow to the longest day, and the whole Earth as a map of colours with contour lines.
▶Open in primopyA year of weather
pandas reads a CSV of daily weather, groups the days by month, and matplotlib draws temperature and rain.
▶Open in primopyshape: (5, 3) ┌─────────┬──────┬──────────┐ │ name ┆ year ┆ top_wind │ │ --- ┆ --- ┆ --- │ │ str ┆ i64 ┆ i64 │ ╞═════════╪══════╪══════════╡ │ Allen ┆ 1980 ┆ 165 │ │ Dorian ┆ 2019 ┆ 160 │ │ Gilbert ┆ 1988 ┆ 160 │ │ Wilma ┆ 2005 ┆ 160 │ │ Irma ┆ 2017 ┆ 155 │ └─────────┴──────┴──────────┘polars
Fifty years of hurricanes
polars filters, groups and sums up the Atlantic storms since 1975, one method after the other: hurricanes per decade, and the five that blew hardest.
▶Open in primopyLonger flippers, heavier penguins
The Palmer penguins in layers, with ggplot2's grammar in Python: points, a fitted line for each species and a panel for each island.
▶Open in primopy
plotlyIncome and life expectancy
The Gapminder data as a live plotly chart: press play and watch 55 years go by, hover over a country.
▶Open in primopy
plotlyA volcano in 3D
The heights of Maunga Whau, a volcano in Auckland, as a live plotly surface: drag to turn it, hover to read a height.
▶Open in primopyWhen is the tea cool enough?
scipy fits Newton's law of cooling to measurements and integrates it to predict the moment.
▶Open in primopyMachine learning
Learn from data, then test on data the model has never seen.
Reading handwritten digits
A support vector machine learns 1347 handwritten digits and reads the other 450, and shows the ones it got wrong.
▶Open in primopyA decision tree you can read
A decision tree learns from 100 iris flowers which measurements tell the species apart, is tested on the other 50, and draws its rules.
▶Open in primopy