Python os Module
The os module provides a portable way of using operating system dependent functionality.
Use it to work with the filesystem, environment variables, processes, and more.
Members
Notes:
[Windows] = Available on Windows only.
[Unix] = Available on POSIX systems (Linux, macOS, etc.).
[Linux] = Linux-only.
Some functions exist on multiple platforms but may have limited behavior (marked in the description).
Member | Description |
---|---|
access() | Check user’s permissions for a path. |
add_dll_directory() [Windows] | Add a path to the DLL search path. |
chdir() | Change the current working directory. |
chmod() | Change the mode (permissions) of a path. |
chown() [Unix] | Change owner and group of path. |
close() | Close a file descriptor. |
closerange() | Close a range of file descriptors. |
cpu_count() | Return the number of CPUs in the system (may be None). |
ctermid() [Unix] | Return filename of controlling terminal. |
devnull | Path of the null device. |
device_encoding() | Return encoding for a file descriptor, or None. |
dup() | Duplicate a file descriptor. |
dup2() | Duplicate a file descriptor to a given fd. |
dup3() | Duplicate a file descriptor to a given fd (with flags). |
environ | Mapping object representing the process environment. |
execl() | Execute a new program (varargs form). |
execle() | Execute a new program with environment (varargs). |
execlp() | Execute a new program, searching PATH (varargs). |
execlpe() | Execute a new program with environment, searching PATH (varargs). |
execv() | Execute a new program, replacing the current process. |
execve() | Execute a new program with environment (low-level). |
execvp() | Execute a program, searching PATH. |
execvpe() | Execute a program with environment, searching PATH. |
extsep | Extension separator for the operating system. |
fchdir() [Unix] | Change working directory to the one given by an open file descriptor. |
fchmod() [Unix] | Change the mode of a file given by file descriptor. |
fchown() [Unix] | Change owner and group of a file given by file descriptor. |
fdopen() | Return an open file object connected to a file descriptor. |
fork() [Unix] | Fork a child process. |
fsdecode() | Decode a path-like or bytes object to str. |
fsencode() | Encode a path-like or str object to bytes. |
fspath() | Return the file system representation of a path-like object. |
fstat() | Perform a stat on an open file descriptor. |
ftruncate() | Truncate a file to a specified length. |
get_blocking() | Get the blocking mode of a file descriptor. |
getcwd() | Return the current working directory as str. |
getcwdb() | Return the current working directory as bytes. |
getegid() [Unix] | Return the effective group id. |
geteuid() [Unix] | Return the effective user id. |
get_exec_path() | Return the sequence of directories that will be searched for executables. |
getgid() [Unix] | Return the real group id. |
getgrouplist() [Unix] | Return list of group ids a user belongs to. |
get_inheritable() | Get the inheritable flag of a file descriptor. |
getlogin() [Unix] | Return the name of the user logged in on the controlling terminal. |
getpgid() [Unix] | Return the process group id of a process. |
getpgrp() [Unix] | Return the process group id of the current process. |
getpid() | Return the current process id. |
getppid() | Return the parent process id. |
getpriority() [Unix] | Get process scheduling priority. |
getsid() [Unix] | Return the session id of a process. |
get_terminal_size() | Return the size of the terminal window as columns and lines. |
getuid() [Unix] | Return the real user id. |
isatty() | Return True if the file descriptor is open and connected to a tty device. |
kill() [limited on Windows] | Send signal to a process. |
killpg() [Unix] | Send a signal to a process group. |
linesep | String used to separate (or terminate) lines on the current platform. |
link() | Create a hard link pointing to a path. |
listdir() | Return a list of entries in a directory. |
lseek() | Set the position of a file descriptor. |
lstat() | Like stat(), but do not follow symbolic links. |
makedirs() | Recursively create directories. |
memfd_create() [Linux] | Create an anonymous memory file. |
mkdir() | Create a directory. |
mkfifo() [Unix] | Create a FIFO (named pipe). |
mknod() [Unix] | Create a filesystem node. |
name | The name of the OS-dependent module imported. |
open() | Low-level OS open; returns a file descriptor. |
openpty() [Unix] | Open a new pseudo-terminal pair. |
path | Submodule for pathname manipulations. |
pathsep | String used to separate search path components (e.g., ';' on Windows). |
pipe() | Create a pipe, returning a pair of file descriptors (r, w). |
pipe2() [Unix] | Create a pipe with flags. |
posix_spawn() [Unix] | Spawn a process (POSIX, efficient). |
posix_spawnp() [Unix] | Spawn a process searching PATH (POSIX). |
pread() [Unix] | Read from a file descriptor at a given position. |
pwrite() [Unix] | Write to a file descriptor at a given position. |
putenv() | Set the value of an environment variable. |
read() | Read from a file descriptor. |
readlink() | Return the path to which a symbolic link points. |
readv() [Unix] | Read from a file descriptor into multiple buffers. |
register_at_fork() [Unix] | Register callables to be executed at process fork. |
remove() | Remove (delete) a file. |
rename() | Rename a file or directory. |
renames() | Recursively rename a file or directory. |
rmdir() | Remove (delete) a directory. |
scandir() | Return an iterator of DirEntry objects. |
sched_getaffinity() [Unix] | Get CPU affinity mask. |
sched_setaffinity() [Unix] | Set CPU affinity mask. |
sched_yield() [Unix] | Yield the processor. |
sep | Path separator for the current platform. |
set_blocking() | Set the blocking mode of a file descriptor. |
setegid() [Unix] | Set the effective group id. |
setenv() | Set an environment variable (if available). |
seteuid() [Unix] | Set the effective user id. |
setgid() [Unix] | Set the real group id. |
setgroups() [Unix] | Set the list of group ids for the current process. |
set_handle_inheritable() [Windows] | Set handle inheritable flag. |
set_inheritable() | Set the inheritable flag of a file descriptor. |
setpgid() [Unix] | Set the process group id. |
setpgrp() [Unix] | Make the current process a session leader. |
setpriority() [Unix] | Set process scheduling priority. |
setregid() [Unix] | Set the real and effective group ids. |
setreuid() [Unix] | Set the real and effective user ids. |
setsid() [Unix] | Start a new session. |
setuid() [Unix] | Set the real user id. |
spawnl() | Spawn a process with a path (varargs). |
spawnle() | Spawn a process with a path and environment (varargs). |
spawnlp() | Spawn a process searching PATH (varargs). |
spawnlpe() | Spawn a process searching PATH with environment (varargs). |
spawnv() | Spawn a process with a path (vector args). |
spawnve() | Spawn a process with a path and environment (vector args). |
spawnvp() | Spawn a process searching PATH (vector args). |
spawnvpe() | Spawn a process searching PATH with environment (vector args). |
startfile() [Windows] | Open a file with its associated application. |
stat() | Perform a stat system call on a path. |
statvfs() [Unix] | Return filesystem statistics. |
strerror() | Return the error message corresponding to an errno value. |
supports_bytes_environ | True if environ accepts bytes keys/values. |
supports_dir_fd | True if functions accept a dir_fd parameter. |
supports_effective_ids | True if functions support effective ids. |
supports_fd | True if functions accept a file descriptor. |
supports_follow_symlinks | True if functions support follow_symlinks parameter. |
symlink() | Create a symbolic link. On Windows, requires Developer Mode or administrator privileges. |
sync() [Unix] | Flush file system buffers. |
system() | Execute the command (string) in a subshell. |
times() | Return process times. |
truncate() | Truncate a file to a specified length. |
umask() | Set the process umask and return the previous value. |
uname() [Unix] | Return OS identification. |
unlink() | Remove (delete) a file. |
urandom() | Return random bytes for cryptographic use. |
utime() | Set access and modified times. |
wait() [Unix] | Wait for completion of a child process. |
wait3() [Unix] | Wait for a child process, returning resource usage. |
wait4() [Unix] | Wait for a child process with rusage. |
waitpid() [Unix] | Wait for completion of a specific child process. |
walk() | Generate file names in a directory tree by walking. |
write() | Write to a file descriptor. |
writev() [Unix] | Write to a file descriptor from multiple buffers. |