The idea is that you do not document programs (after the fact), but write documents that contain the programs. 
PyLit (Python Literate) provides a plain but efficient tool for literate programming: a bidirectional text/code converter.
The PyLit project is hosted at https://codeberg.org/milde/pylit
Usage, behaviour, and API are not fixed yet. Ideas and feedback welcome.
The PyLit source has a chapter on open questions and ideas.
© 2005, 2007, 2015, 2021 Günter Milde.
PyLit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
I am using PyLit in my daily work for more than ten years now without major problems. It works for me, but your mileage might vary.
Remember to back up your data. A version control system is recommended.