Gods, Demons and Imaginary Friends

How was all of the "stuff" that went along with the study of magic first derived? I wanted to understand the
nature of the gods and goddesses from books and esoteric lore that I had come
to love and find a pantheon within my own life and experience.