Add programmatic API

Detail are in the doc. 

@arikon @scf2k 
state should be skipped