You can try starting with this book:
https://www.amazon.com/Black-Hat-Python-Programming-Pentesters-ebook/dp/B00QL616DW?language=en_US
I meant when you go looking for it online. The book is great. Nothing unsafe about learning it there. I meant that when I have reviewed this topic before I have found a lot of websites that touch on the topic that are unsafe.
https://www.amazon.com/Black-Hat-Python-Programming-Pentesters-ebook/dp/B00QL616DW
This book?