Skip to main content

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) -> bytes
@overload
fsencode(filename: bytes) -> bytes
function fsdecode
fsdecode(filename: bytes) -> str
@overload
fsdecode(filename: str) -> str
function system
system(cmd: str) -> int
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: Self, /, fields: List[int])
__init__
__init__(self: Self, /, fields: Ptr[int])
Special methods 4
__len__
__len__(self: Self, /) -> int
__getitem__
__getitem__(self: Self, index: int, /) -> int
__iter__
__iter__(self: Self, /)
__repr__
__repr__(self: Self, /) -> str
function stat
stat(path: str, *, follow_symlinks: bool = True) -> stat_result
@overload
stat(fd: int) -> stat_result
function fstat
fstat(fd: int) -> stat_result
function lstat
lstat(path: str) -> stat_result
function open
open(path: str, flags: int, mode: int = 0o777) -> int
function listdir
listdir(path: str = ".") -> List[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() -> bytes
function getcwd
getcwd() -> str
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) -> bool
function chmod
chmod(path: str, mode: int, *, follow_symlinks: bool = True)
function getpid
getpid() -> int
function getppid
getppid() -> int
function close
close(fd: int)
function read
read(fd: int, n: int, /) -> bytes
function write
write(fd: int, data: bytes, /) -> int
function lseek
lseek(fd: int, pos: int, how: int, /) -> int
function fsync
fsync(fd: int)
function ftruncate
ftruncate(fd: int, length: int, /)
function truncate
truncate(path: str, length: int)
Modules 4