In 1923, possibly, Lorca began to devise this play. At the end of 1925, he seems to have it practically finished and in January 1926, he sends a part (second scene of the third act) to Melchor Fernández Almagro. It is a work that is, therefore, created in the years of the Residencia de Estudiants (under the influence of the avant-garde environment and friendship with Dalí) and summers in Asquerosa (Disgusting).
It seems that he worked on it during his visit to Dalí in Cadaqués in the spring of 1925. During the fall of 1925 and the first months of 1926, he also worked on it in Granada, where he felt trapped at the time, as he said in a letter to Fernández Almagro.
The source of this work, as with The Shoemaker’s Prodigious Wife, are those hallelujahs (religious songs) that the author claims to have known in his childhood, stories that were told from a paper where vignettes appeared that told a story through drawings and words. It was popular literature. Federico knew the alleluia of Don Perlimplín in his childhood in Fuente Vaqueros or in Asquerosa. He must have heard it sung or recited by some comedian or puppeteer who came to town.