This study was to explore the diversity of rhizosphere and endophytic microbial communities and the correlation with soil environmental factors of Stipa purpurea on the Qinghai-Tibetan Plateau. The bacterial phylum of Proteobacteria, Firmicutes and Bacteroidota, and the fungal phylum of Ascomycota, Basidiomycota and Zygomycota were dominant in microbial communities of S. purpurea in all three sampling sites. Multiple comparison analysis showed that there were significant differences in the composition of microbial communities in the roots, leaves and rhizosphere soil. Whether it is fungi or bacteria, the OTU abundance of rhizosphere soils was higher than that of leaves and roots at the same location, while the difference among locations was not obvious. Moreover, RDA analysis showed that Zygomycota, Cercozoa, Glomeromycota, Chytridiomycota and Rozellomycota possessed strongly positive associations with altitude, dehydrogenase, alkaline phosphatase, neutral phosphatase, available kalium and available phosphate, while Ascomycota was strongly negatively associated. Changes in ammonium nitrate, alkaline phosphatase, polyphenol oxidase, total phosphorus, and altitude had a significant impact on the bacterial communities in different habitats and altitudes. Taken together, we provide evidence that S. purpurea has abundant microbial communities in the alpine grassland of the Qinghai-Tibetan Plateau, whose composition and diversity are affected by various soil environmental factors.