os — 0.1.0

org.pycforge.os · Author: PyCForge

License: GPL-3.0-only · Created: 2026-11-20

Runtime conversion · Direct declared calls

Using this import · Functions · Conversion contract · Worked examples

Function index

path.abspath · path.basename · path.dirname · path.exists · getcwd · getenv · path.getmtime · path.getsize · path.isabs · path.isdir · path.isfile · path.join · listdir · makedirs · path.normpath · replace · path.splitext

Overview

Inspect and update files through a bounded native OS interface.

Using this import

Use *import os as fs. Path functions live under fs.path. Other functions live directly under fs.

Author's limitations

Unicode str paths and a native Windows or POSIX target. Filesystem calls use the running program's working directory and environment. Returned names must be representable as Unicode scalars in the Runtime's UTF-8 strings. Windows uses the wide-character API. Path joins accept 1 to 64 positional components. Expanded arguments, file descriptors, bytes paths, PathLike objects, dir_fd and Typed conversion are outside this profile. File and allocation budgets apply. Directory entries follow native enumeration order. Parent directories created before a failure remain on disk. Place a replacement source beside its destination for same-filesystem replacement.

Release notes

Native filesystem and environment operations.

Conversion contract

Declare *import os as fs. Use fs.path.join for paths and fs.listdir for directory contents. Paths and environment variables use the operating system running the generated program.

Unicode str paths and a native Windows or POSIX target. Filesystem calls use the running program's working directory and environment. Returned names must be representable as Unicode scalars in the Runtime's UTF-8 strings. Windows uses the wide-character API. Path joins accept 1 to 64 positional components. Expanded arguments, file descriptors, bytes paths, PathLike objects, dir_fd and Typed conversion are outside this profile. File and allocation budgets apply. Directory entries follow native enumeration order. Parent directories created before a failure remain on disk. Place a replacement source beside its destination for same-filesystem replacement.

os.path.abspath(path, /) -> os-text

Return an absolute normalized path using the current working directory.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Return an absolute normalized path using the current working directory.

View example: portable-path

os.path.basename(path, /) -> os-text

Return the final pathname component.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Return the final pathname component.

View example: portable-path

os.path.dirname(path, /) -> os-text

Return the directory portion of a pathname.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Return the directory portion of a pathname.

View example: portable-path

os.path.exists(path, /) -> bool

Test whether the target of the pathname exists.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Test whether the target of the pathname exists.

View example: completed-file

os.getcwd() -> os-text

Return the working directory of the running program.

Normalized semantic slots: . These slots are supplied by the engine; the signature above defines source arguments and defaults.

Returns: Return the working directory of the running program.

View example: portable-path

os.getenv(key, default=None) -> os-lookup-result

Return the environment value or the supplied default if the variable is absent.

Normalized semantic slots: key, default. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: Name of the environment variable.

Argument 2: Value returned unchanged if the variable is absent.

Returns: Return the environment value or the supplied default if the variable is absent.

View example: completed-file

os.path.getmtime(path, /) -> float64

Read the last modification time in seconds since the Unix epoch.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Read the last modification time in seconds since the Unix epoch.

View example: completed-file

os.path.getsize(path, /) -> int64

Read the size in bytes from the filesystem.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Read the size in bytes from the filesystem.

View example: completed-file

os.path.isabs(path, /) -> bool

Test whether a path is absolute under Python 3.12 target rules.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Test whether a path is absolute under Python 3.12 target rules.

View example: portable-path

os.path.isdir(path, /) -> bool

Test whether the pathname refers to a directory.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Test whether the pathname refers to a directory.

View example: completed-file

os.path.isfile(path, /) -> bool

Test whether the pathname refers to a regular file.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Test whether the pathname refers to a regular file.

View example: completed-file

os.path.join(path, /, *paths) -> os-text

Join one or more path components using target operating-system rules.

Normalized semantic slots: path, paths. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Argument 2: Additional positional Unicode components.

Returns: Join one or more path components using target operating-system rules.

View example: portable-path

os.listdir(path='.') -> os-entry-list

List directory entry names, excluding the dot entries. An omitted path or None selects the working directory.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: List directory entry names, excluding the dot entries. An omitted path or None selects the working directory.

View example: completed-file

os.makedirs(name, mode=0o777, exist_ok=False) -> none

Create missing directories. The supplied mode applies to the leaf directory.

Normalized semantic slots: name, mode, exist_ok. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: The directory path to create.

Argument 2: Permission bits for the leaf directory on POSIX.

Argument 3: Whether an existing directory is acceptable.

Returns: Create missing directories. The supplied mode applies to the leaf directory.

View example: completed-file

os.path.normpath(path, /) -> os-text

Normalize separators, dot components and parent references.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Normalize separators, dot components and parent references.

View example: portable-path

os.replace(src, dst) -> none

Rename a file or directory, replacing an eligible destination.

Normalized semantic slots: src, dst. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: Existing source path.

Argument 2: Destination path.

Returns: Rename a file or directory, replacing an eligible destination.

View example: completed-file

os.path.splitext(path, /) -> os-extension-pair

Split the last filename extension from the root.

Normalized semantic slots: path. These slots are supplied by the engine; the signature above defines source arguments and defaults.

Argument 1: A Unicode pathname.

Returns: Split the last filename extension from the root.

View example: portable-path

Worked examples

Compare your run with the expected output below. The SDK checks conversion when authoring a package. Opening Help and registering a package do not execute the examples.

Example: completed-file

*import os as fs

def main():
    fs.makedirs("reports", exist_ok=True)
    with open("reports/draft", "w", encoding="utf-8") as stream:
        stream.write("finished")
    fs.replace("reports/draft", "reports/final.txt")
    final = "reports/final.txt"
    print(fs.path.isfile(final), fs.path.getsize(final))
    print(fs.path.isdir("reports"), fs.path.exists(final), "final.txt" in fs.listdir("reports"))
    print(fs.path.getmtime(final) == fs.path.getmtime(final), fs.getenv("", "default"))
    return 0

Expected standard output:

True 8
True True True
True default

Expected exit code: 0

Example: portable-path

*import os as fs

def main():
    path = fs.path.join("reports", "sales.csv")
    filename = fs.path.basename(path)
    print(filename, fs.path.splitext(filename))
    print(fs.path.dirname(path), fs.path.normpath(fs.path.join("x", "..", "reports")))
    print(fs.path.isabs(fs.path.abspath(path)), fs.path.abspath(".") == fs.getcwd())
    return 0

Expected standard output:

sales.csv ('sales', '.csv')
reports reports
True True

Expected exit code: 0