Apple Health doesn't store sleep data separately from other health data. This script parses all of the data and creates a sleep dataset.
If you prefer another XML parser, that probably works too.
Go to the Health app on your iPhone, press your profile picture in the top right corner, scroll down and press Export All Health Data. Put export.zip onto your computer and unzip it. Look for export.xml and put that in the project repository.
Get rid of my name and put your name. The source has a weird apostrophe and an \xa0 so leave those.
and you should get sleep_clean.csv. I analyzed it with ChatGPT, you can analyze it how you wish.