Pumpjacks are over-ground mechanical drives that convert the rotary motion of a motor to a reciprocating piston of a pump shaft in an oil well. They consist of a number of mechanical parts which are described in the image below.
Image credit: MIT
When torque is applied by a motor to the power shaft, the counterweights lift and apply mechanical energy to the walking beam, therefore submerging the rod and plunger. The corresponding upstroke raises the horse head and rod. The rod itself is connected to a subsurface pump which lifts oil to the surface well head.
A pumpjack's operation depends largely upon its design specifications, including the pump angle, weight of the counterweights, fluid weight and density, and stroke length.
A pumpjack in operation, showing the down- and upstroke of the subsurface pump.
Image credit: Britannica Online