Locking rotation for bones using python?

Is it possible to use python to lock 2 of the rotation axis of a bone. I want to use “hinge joints” for the knees and the elbows of a cartoon character i’m working on. I’d like it to be a “fire and forget” scipt, i’m a Python noob so if its realy complicated chances are I wont be able to use is.