os.path.ismount
Four questions about a path that go beyond file or directory. ismount works everywhere; isjunction and isdevdrive (3.12+) exist on every platform in 3.13 but can only be True on Windows; isreserved (3.13+) exists only on Windows, where os.path is ntpath.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| path | str | bytes | os.PathLike | yes | The path to test. ismount, isjunction and isdevdrive look at the file system; isreserved only looks at the string. |
Return value
bool — True when the path has the property; False otherwise, including when the path does not exist (ismount, isjunction).
Common patterns
import os def mount_point(path): path = os.path.abspath(path) while not os.path.ismount(path): path = os.path.dirname(path) return path
import os isreserved = getattr(os.path, 'isreserved', lambda path: False) if isreserved('report.txt'): raise ValueError('reserved file name on Windows')
import os for root, dirs, files in os.walk('.'): dirs[:] = [d for d in dirs if not os.path.isjunction(os.path.join(root, d))]
import os cache = r'D:\cache' if os.path.isdevdrive('D:\\') else os.path.expanduser('~/.cache/build')
Examples
Pitfalls
import posixpath posixpath.isreserved('NUL')
import os isreserved = getattr(os.path, 'isreserved', lambda path: False) isreserved('report.txt')
import os os.mkdir('data') os.path.ismount('data')
import os os.mkdir('data') os.path.isdir('data')
When to use
- Stopping a directory walk at file-system boundaries (ismount)
- Not following NTFS junctions on Windows (isjunction)
- Checking a user-supplied file name before creating it on Windows (isreserved)
- Existence checks → os.path.exists / isdir
- Symlinks → os.path.islink (junctions are not reported as links)
- Bind mounts on Linux → ismount cannot reliably detect them
Notes
FAQ
ismount works everywhere. isjunction (3.12+) exists everywhere but is always False outside Windows. isdevdrive is on every platform from 3.13 (Windows-only in 3.12) and is always False outside Windows. isreserved (3.13+) has "Availability: Windows" in the docs: it is defined in ntpath only, so os.path.isreserved raises AttributeError on Linux and macOS. That is why the examples avoid calling isreserved and isdevdrive and the page has no live demo.