import grp
import pwd
import os
stat_info = os.stat('/path')
uid = stat_info.st_uid
gid = stat_info.st_gid
print(uid, gid)
user = pwd.getpwuid(uid)[0]
group = grp.getgrgid(gid)[0]
print(user, group)
How to get the owner and group of a folder with Python on a Linux machine?