I acquire an analog waveform and I expect it to have some local flatness (post-filtering). The waveform's exact shape is unknown but some rough characteristics (peak amplitude, duration, rise time, etc.) can be assumed to be known. The rough shape of the waveform can be assumed to be known (excluding any information about a flat region). Below you can find a simulated waveform, without any noise, etc.
Ideally, I would like to measure the flatness of any set of points on the waveform. However, I am very new to DSP so I do not know if that is feasible at all. I need to know where the flat region is, and "how flat" it is. Ideally, I would like to have a library for python because I currently simulate and analyze everything in Python. But I can also implement something from scratch if need be, I just need to understand what would be the most feasible way to approach this problem.
Also, since it has been asked in related questions: I do know the expected length of this flat region, but I do not know where exactly it would surface or with what level of error/tolerance. Taking into account uncertainties such as component degradation, we can assume I will not have much information about the quality and location of the flat region.