Python 3.3+shutilfunction
shutil.disk_usage()
system and environment
Reports the size of the disk holding a path: a named tuple total, used, free in bytes.
Syntax
shutil.disk_usage(path) -> usage(total, used, free)
used + free is usually less than total: on Unix free is the space available to an ordinary user, and the root reserve (often 5%) counts in neither. The numbers are bytes; divide by 1024**3 for gigabytes. The path must exist; on Windows a file works too since 3.8, not only a directory.
Examples
import shutil
u = shutil.disk_usage('.')
print(u) # → ? usage(total=..., used=..., free=...) — зависит от машины
print(f'{u.free / 1024**3:.1f} ГБ свободно') # → ? 12.3 ГБ свободно
print(u.used + u.free <= u.total) # → True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy