This is the API for all file-like objects in the Python standard library (as of 3.10.5).
# All file-like objects inherit the IOBase interface:
# Documented at https://docs.python.org/3/library/io.html#io.IOBase .
close() -> None
closed() -> bool # Implemented as @property `closed`
fileno() -> int
flush() -> None
isatty() -> bool
readable() -> bool
readline(size: int = -1) -> Union[str, bytes]
readlines(hint: Union[int, None] = None) -> list
seek(pos: int, whence: int = io.SEEK_SET) -> int # SEEK_SET is 0
seekable() -> bool
tell() -> int
truncate(pos: int = None) -> int # The parameter is named "size" in class FileIO
writable() -> bool
writelines(lines: list) -> None
__del__() -> None
# Documented at https://docs.python.org/3/library/io.html#class-hierarchy .
__enter__()
__exit__(*args) -> None:
__iter__()
__next__() -> Union[str, bytes]
# Documented in paragraph at https://docs.python.org/3/library/io.html#io.IOBase .
# Note that while the documentation claims that the method signatures
# of `read` and `write` vary, all file-like objects included in the Python
# Standard Library have the following exact method signatures for `read` and `write`:
read(size: int = -1) -> Union[str, bytes]
write(b: Union[str, bytes]) -> int # The parameter is named "s" in TextIOBase
Specific file-like objects may implement more than this, but this is the subset of methods that are common to ALL file-like objects.