How can I create instruction for buying NFT?

I use python
Or maybe you could suggest a library

There’s the Solana-py library that would help, but you would still have to understand the binary protocol required to talk to the NFT marketplace that you want to communicate with. It’s not something that’s easy to do unless the marketplace you want to talk to provides an SDK for interacting with their platform.

I think you best chances are to pick an NFT marketplace and see if anybody has made an SDK for communicating with it from scripts.