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.

os.path functionPython 3 (isjunction, isdevdrive 3.12+; isreserved 3.13+, Windows only)
Common call
os.path.ismount('/mnt/usb')
Returns
True or False — never raises for a missing path
Replaces
Parsing /proc/mounts or the output of mount
Watch out
isreserved is missing outside Windows: AttributeError on Linux and macOS
os.path.ismount(path) / isjunction(path) / isdevdrive(path) / isreserved(path)
→ bool

Parameters

NameTypeRequiredDescription
pathstr | bytes | os.PathLikeyesThe 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

Find the mount point that contains a path
Walk up until ismount says yes.
import os

def mount_point(path):
    path = os.path.abspath(path)
    while not os.path.ismount(path):
        path = os.path.dirname(path)
    return path
Validate a file name for Windows on any OS
isreserved is only on Windows (3.13+). Fall back to "not reserved" elsewhere, or call ntpath.isreserved directly on 3.13+ to check names meant for Windows users.
import os
isreserved = getattr(os.path, 'isreserved', lambda path: False)
if isreserved('report.txt'):
    raise ValueError('reserved file name on Windows')
Skip junctions while walking (Windows)
Junctions are directory links that islink() does not report, so filter them explicitly.
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))]
Prefer a Dev Drive for a build cache (3.13+)
isdevdrive is always False outside Windows.
import os
cache = r'D:\cache' if os.path.isdevdrive('D:\\') else os.path.expanduser('~/.cache/build')

Examples

1. The file-system root is a mount point
import os os.path.ismount(os.path.abspath(os.sep))
Returns
True
2. An ordinary folder is not
import os os.mkdir('d') os.path.ismount('d')
Returns
False
3. A missing path gives False, not an error
import os (os.path.ismount('missing'), os.path.isjunction('missing'))
Returns
(False, False)
4. A normal directory is not a junction
import os os.mkdir('d') os.path.isjunction('d')
Returns
False
5. A file is never a mount point
import os open('f.txt', 'w').close() os.path.ismount('f.txt')
Returns
False
6. isreserved lives only in ntpath
import posixpath hasattr(posixpath, 'isreserved')
Returns
False

Pitfalls

1. Calling os.path.isreserved on Linux or macOS
posixpath has no isreserved, so portable code that calls it crashes outside Windows. Guard it with getattr.
posixpath.isreserved
import posixpath
posixpath.isreserved('NUL')
AttributeError: module 'posixpath' has no attribute 'isreserved'
getattr with a fallback
import os
isreserved = getattr(os.path, 'isreserved', lambda path: False)
isreserved('report.txt')
False
2. Using ismount as an existence check
ismount answers False for missing paths and for ordinary folders alike. Use exists()/isdir() to ask whether something is there.
ismount
import os
os.mkdir('data')
os.path.ismount('data')
False
isdir
import os
os.mkdir('data')
os.path.isdir('data')
True

When to use

Use it
  • 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)
Reach for something else
  • 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

CPython impl
posixpath.ismount compares os.lstat(path) with os.lstat(path/..): a different st_dev, or the same inode (the root), means a mount point. A symlink is never a mount point
Linux and macOS
ismount cannot reliably detect bind mounts on the same file system, and on Linux it always returns True for btrfs subvolumes
Windows
ismount: drive roots and UNC share roots are always mount points; other paths use GetVolumePathName. isjunction is implemented in C there (nt._path_isjunction). isreserved (3.13+, Availability: Windows) flags names ending in a space or dot, names with : * ? " < > | or control characters, and DOS device names such as NUL, CON, AUX, PRN, COM1, LPT1, also with an extension (nul.txt)
versions
isjunction and isdevdrive were added in 3.12; isdevdrive was Windows-only in 3.12 and exists on all platforms (always False outside Windows) since 3.13. Outside Windows isjunction always returns False

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.