How to program motion sensor using python api

I’m planning to build a rat / rodent catcher using my flotilla dock and my raspberry pi.
When the rat go to my trap and sense by the motion sensor, the box door will close but I don’t know how to program it using python api.
Please help me :)