Jeez, didn't any of you guys ever watch "Wyatt Earp"? "Bonanza"? "The Rifleman"? "The Big Valley"? (And, to really date myself) "Wild Bill Hickok"? I started twirling when I was about eight years old and got my first cap gun. I never got extreme, but I could twirl forwards and backwards pretty good. I got out of guns for a few years, but the next time I tried it with a gun (many, many years later) I was pleased that I still had the knack, after I got used to the weight.
Start out with a fairly light pistol, like a brass-framed 1851 Navy, and just practice doing one backwards twirl (spin the gun so that the barrel twirls up towards you). Twirl the gun once, then catch it. Then twirl it again and catch it and so on until you get good at catching the gun on that one twirl. When you get one twirl down, Grasshopper, go on to two twirls, then three twirls, etc., etc. Just start out slow, and your speed will come as you develop your technique.
A forward twirl, where the barrel spins away from you and down, is a little more difficult; the grip is coming up into your hand as opposed to the more natural feel of the grip falling down into your hand. Just practice it the same way as described above.
Those fancy twirlers in the movies use eight ounce aluminum and plastic guns; they wouldn't be quite so sassy if they used a real two-and-a-half pound BP pistol! (and, yes, I did try spinning my Walker once. Just once).
Now if I could just get that trick down where they spin the gun into their holster, I would be a happy man...