os

Standard library package View source

Native operating-system interfaces for POSIX and Windows.

POSIX paths and environment use UTF-8 with surrogateescape to preserve arbitrary bytes; Windows uses wide-character APIs. Filesystem APIs currently accept str paths only; fsencode() and fsdecode() additionally accept bytes and str identity inputs, respectively.

Failures raise OSError with errno, a system diagnostic and applicable filenames (plus winerror for Windows API failures). File-descriptor reads and writes may transfer fewer bytes than requested. Windows permissions and available process APIs differ from POSIX.

variable curdir
curdir: Literal[str] = "."
variable pardir
pardir: Literal[str] = ".."
variable extsep
extsep: Literal[str] = "."
variable SEEK_SET
SEEK_SET: Literal[int] = 0
variable SEEK_CUR
SEEK_CUR: Literal[int] = 1
variable SEEK_END
SEEK_END: Literal[int] = 2
variable F_OK
F_OK: Literal[int] = 0
variable R_OK
R_OK: Literal[int] = 4
variable W_OK
W_OK: Literal[int] = 2
variable X_OK
X_OK: Literal[int] = 1
variable O_RDONLY
O_RDONLY: Literal[int] = 0
variable O_WRONLY
O_WRONLY: Literal[int] = 1
variable O_RDWR
O_RDWR: Literal[int] = 2
function fspath
fspath(path)
function fsencode
fsencode(filename: str)
@overload
fsencode(filename: bytes)
function fsdecode
fsdecode(filename: bytes)
@overload
fsdecode(filename: str)
function system
system(cmd: str)
function putenv
putenv(key: str, value: str)

Set the process environment without updating the environ mapping.

function unsetenv
unsetenv(key: str)

Remove a process variable without updating the environ mapping.

variable environ
environ = _Environ(_make_env_map(), copy=False)
function getenv
getenv(key: str, default = None)
class stat_result
class stat_result
Fields 14
st_mode int
st_ino int
st_dev int
st_nlink int
st_uid int
st_gid int
st_size int
st_atime float
st_mtime float
st_ctime float
st_atime_ns int
st_mtime_ns int
st_ctime_ns int
st_rdev int
Constructors 2
__init__
__init__(self, fields: List[int])
__init__
__init__(self, fields: Ptr[int])
Special methods 4
__len__
__len__(self)
__getitem__
__getitem__(self, index: int)
__iter__
__iter__(self)
__repr__
__repr__(self)
function stat
stat(path: str, follow_symlinks: bool = True)
@overload
stat(fd: int)
function fstat
fstat(fd: int)
function lstat
lstat(path: str)
function open
open(path: str, flags: int, mode: int = 0o777)
function listdir
listdir(path: str = ".")
function makedirs
makedirs(name: str, mode: int = 0o777, exist_ok: bool = False)
function removedirs
removedirs(name: str)
function mkdir
mkdir(path: str, mode: int = 0o777)
function rmdir
rmdir(path: str)
function chdir
chdir(path: str)
function getcwdb
getcwdb()
function getcwd
getcwd()
function remove
remove(path: str)
function rename
rename(src: str, dst: str)
function replace
replace(src: str, dst: str)
function access
access(path: str, mode: int)
function chmod
chmod(path: str, mode: int, follow_symlinks: bool = True)
function getpid
getpid()
function getppid
getppid()
function close
close(fd: int)
function read
read(fd: int, n: int)
function write
write(fd: int, data: bytes)
function lseek
lseek(fd: int, pos: int, how: int)
function fsync
fsync(fd: int)
function ftruncate
ftruncate(fd: int, length: int)
function truncate
truncate(path: str, length: int)
Modules 4