{"id":10015,"library":"oschmod","title":"oschmod: Cross-platform file permissions","description":"oschmod is a Python library that provides a Windows and Linux compatible `chmod` function for managing file permissions. It aims to offer a consistent API for setting POSIX-like permissions across various operating systems, including Windows, which natively uses Access Control Lists (ACLs) rather than POSIX mode bits. The current version is 0.3.12, and it maintains a moderate release cadence primarily for bug fixes and compatibility updates.","status":"active","version":"0.3.12","language":"en","source_language":"en","source_url":"https://github.com/yakdriver/oschmod","tags":["filesystem","permissions","chmod","windows","linux","cross-platform"],"install":[{"cmd":"pip install oschmod","lang":"bash","label":"Install oschmod"}],"dependencies":[],"imports":[{"note":"The main function for changing permissions is also named 'oschmod' within the 'oschmod' module.","wrong":"import oschmod; oschmod.chmod('file', 0o755)","symbol":"oschmod","correct":"from oschmod import oschmod"}],"quickstart":{"code":"import os\nfrom oschmod import oschmod\n\n# Create a dummy file for demonstration\nfile_path = 'my_test_file.txt'\nwith open(file_path, 'w') as f:\n    f.write('Hello, oschmod!')\n\nprint(f\"Initial permissions for {file_path}: {oct(os.stat(file_path).st_mode & 0o777)}\")\n\n# Set permissions to rwxr-xr-x (0o755)\noschmod(file_path, 0o755)\n\nprint(f\"New permissions for {file_path}: {oct(os.stat(file_path).st_mode & 0o777)}\")\n\n# Clean up the dummy file\nos.remove(file_path)\n","lang":"python","description":"This quickstart demonstrates how to use the `oschmod` function to set file permissions. It creates a temporary file, sets its permissions to 0o755 (read, write, execute for owner; read, execute for group and others), and then verifies the change. Remember to use an octal literal (e.g., `0o755`) for the mode."},"warnings":[{"fix":"Be aware of potential differences in permission interpretation on Windows. For fine-grained Windows permissions, consider using a dedicated ACL management library.","message":"On Windows, `oschmod` translates POSIX-like mode bits to Windows Access Control Lists (ACLs). This is an approximation and not all POSIX modes have direct ACL equivalents, which can lead to slightly different effective permissions or limitations compared to a true POSIX system.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Implement directory traversal logic using `os.walk` or similar methods if you need to set permissions recursively for a directory's contents.","message":"The `oschmod` function is not recursive by default. It only modifies the permissions of the specified file or directory itself. To apply permissions to the contents of a directory, you must manually traverse the directory tree (e.g., using `os.walk`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure the script is run with appropriate user privileges (e.g., administrator on Windows, root or sudo on Linux) or verify the current user has ownership/write permissions for the target file/directory.","message":"Attempting to change permissions on files or directories where the current user lacks the necessary administrative or ownership privileges will result in a `PermissionError`. This is especially common on Windows for system files or on Linux for files owned by root.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Verify that the `file_path` argument is correct and that the file or directory exists at that location before calling `oschmod`.","cause":"The path provided to `oschmod` does not point to an existing file or directory.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'non_existent_file.txt'"},{"fix":"Run your Python script with elevated permissions (e.g., as an administrator on Windows, or using `sudo` on Linux/macOS), or ensure the current user has ownership/write permissions to the target path.","cause":"The Python process does not have sufficient privileges to modify the permissions of the specified file or directory.","error":"PermissionError: [Errno 13] Permission denied: 'some_protected_file.txt'"},{"fix":"Call `oschmod.oschmod(path, mode)` instead of `oschmod.chmod(path, mode)`. If you used `import oschmod`, it would be `oschmod.oschmod(...)`.","cause":"You are trying to call `oschmod.chmod()` but the main function within the `oschmod` module for changing permissions is also named `oschmod`.","error":"AttributeError: module 'oschmod' has no attribute 'chmod'"}]}