Margaret Cavendish was an anomaly. Born into an aristocratic family in 1623, in an era when women’s writing was vanishingly rare and usually anonymous, she put her name to poetry, plays and philosophy, scientific observations and fantastical romances. She was also unashamedly, publicly ambitious, in a way still discouraged in women today: well aware that her sex barred her from public and intellectual life, she nonetheless insisted that “though I cannot be Henry the Fifth, or Charles the Second, yet I endeavour to be Margaret the First”.

And she was: the first woman to be invited to a meeting of the Royal Society (and the last, for 200 years), in Restoration London she got the fame she wanted – but as celebrity, rather than thinker. Crowds ran after her carriage, calling her “Mad Madge”, marvelling at her extravagant dress sense (in an early work, she nicely describes clothes as “the Poetry of Women”). Samuel Pepys dismissed her as “a mad, conceited, ridiculous woman”; it was widely assumed that her books were written by her husband. Women artists in centuries to come would get used to similar reactions.

Now she is a fascinating footnote, her 21 volumes little read. For Virginia Woolf, she was the victim of a system that wouldn’t educate or guide her, with a “wild, generous, untutored intelligence [that] poured itself out, higgledy-piggledy, in torrents”, as she “frittered her time away scribbling nonsense and plunging ever deeper into obscurity and folly”. “The crazy Duchess,” Woolf concluded, “became a bogey to frighten clever girls with” – effort, ambition and talent twisted out of shape by isolation and disappointment.

It is through a small miracle of imaginative sympathy and judicious sampling that Danielle Dutton, founder of the American feminist small press Dorothy, has compressed the essence of the capacious and contradictory duchess into 160 pages. She splits the novel in two, giving us Margaret’s inner thoughts on her coming of age, marriage and first writings, then taking a third-person perspective for her more public life after the Restoration. Margaret’s own words are threaded through the text, with a vividly charged effect similar to Ruth Scurr’s exhilarating 2015 biography of her contemporary John Aubrey, constructed as a diary from his own words.

Margaret lived in interesting times. With the civil war raging, she joined the court of Queen Henrietta Maria and followed her into exile in France, where she met and married the much older William Cavendish, Duke of Newcastle. They lived in slightly embarrassed circumstances in Paris and Antwerp, before the coronation of Charles II brought them back to England. Her husband was her greatest supporter, and through him Margaret came into contact with many of Europe’s leading thinkers; but she was bashful and awkward in society, even as her desire to be “a meteor, singly, alone”, ascending “Fame’s Tower”, burned through her writing.

Dutton gives us the child Margaret, imagining whole “Bubble-worlds” in the foam of a stream, stitching together little books with yarn, then catapulted into womanhood by her first period. “It is nobler to be a boy, I thought – and looked back with nostalgia, as if I just had been.” She is excellent on the domestic detail of the period: the rooms aristocratic ladies were bounded by, the cuisine, the hideous medical interventions Margaret must submit to in many unsuccessful attempts to conceive (a poultice of ram’s dung on the belly, drinking steel shavings and fern roots steeped in wine – “a drench that would poison a horse”).

Her books are woven into the novel, too – along with the “‘outrage, wonder and scorn” they met with. The fantastical journeys of The Description of a New World, Called The Blazing-World, an extraordinary piece of utopian science fiction featuring talking bears and rivers of crystal, are intercut with the disappointing comings and goings of the real world. Her Orations burn with protofeminist rage: “Men would fain Bury us in their Houses or Beds, as in a Grave; the truth is, we Live like Bats or Owls, labour like Beasts, and die like Worms”.

A literary distillation of Cavendish would be worthwhile in itself: Dutton also uses her staccato structure to illuminate from within individual moments of frustration and inspiration, as well as Margaret’s needy, uncomfortable relationship with fame and her struggle to articulate things that nobody expected her to attempt. (“It is against nature for a woman to spell right,” is her smart rejoinder to complaints about her grammar and style.) Dutton tenderly draws a portrait of a long marriage, and the efforts and costs of maintaining the lineaments of the self in the face of a sceptical or hostile world.

Like Blake, Cavendish could see a world in a grain of sand: inspired by the contemporary excitement over microscopes, she proposed unseen universes in a peach pit, a ball of snow, an earring ... She created multiple realms in her many manuscripts; and there is a whole blazing world in this warm, witty portrait of a visionary who was both passionately engaged with her time and strikingly ahead of it.

• Margaret the First is published by Scribe. To order a copy for £10.65 (RRP £12.99) go to bookshop.theguardian.com or call 0330 333 6846. Free UK p&p over £10, online orders only. Phone orders min p&p of £1.99.