The invention relates to aminopyrimidopyrazole / pyrrole derivatives, a preparation method and application thereof, and belongs to the field of medicine. The present invention provides the compound represented by formula I, its optical isomer, and the pharmaceutically acceptable salt of the compound or its optical isomer. Biological experiments have proved that the compound of the present invention can not only significantly inhibit the proliferation of breast cancer, lung cancer, colorectal cancer, gastric cancer, bile duct cancer, urothelial cancer and other cancer cells, but also has a broad-spectrum anti-cancer effect, and has a broad-spectrum anti-cancer effect. The proliferation of cells and hepatic stellate cells also showed inhibitory effect, and could inhibit tumor growth in vivo, providing a new option for the development of anti-tumor and anti-fibrotic drugs.