Sit in the background and use some library to parse python code. See: parso https://parso.readthedocs.io/en/latest/docs/usage.html