Disclosed is a benzazepine derivative, a preparation method, a pharmaceutical composition and a use thereof. A compound of the formula (I), an isomer thereof, a prodrug, a stable isotope derivative or a pharmaceutically acceptable salt of the present invention has the following structure. The benzazepine derivatives of the present invention have a good regulatory effect on the TLR family and related signaling pathways, and particularly have a good regulatory effect on TLR8. The benzazepine derivatives can effectively treat, alleviate and/or prevent diseases mediated by TLR family and TLR-related signaling pathways, in particular, can effectively treat, alleviate and/or prevent various diseases mediated by TLR8, such as cancer, autoimmune diseases, infection, inflammation, transplant rejection, graft versus host disease, and the like.