The amount of integral field spectrograph (IFS) data has grown considerably over the last few decades. The demand for tools to analyze such data is therefore bigger now than ever. We present a flexible Python tool for Three-Dimensional Optimal Spectral Extraction (TDOSE) from IFS data cubes. TDOSE works on any three-dimensional data cube and bases the spectral extractions on morphological reference image models. By default, these models are generated and composed of multiple multivariate Gaussian components, but can also be constructed with independent modeling tools and be provided as input to TDOSE. In each wavelength layer of the IFS data cube, TDOSE simultaneously optimizes all sources in the morphological model to minimize the differen...