is there a python library that I can use instead of this code?