oschmod: Cross-platform file permissions

0.3.12 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
from oschmod import oschmod

# Create a dummy file for demonstration
file_path = 'my_test_file.txt'
with open(file_path, 'w') as f:
    f.write('Hello, oschmod!')

print(f"Initial permissions for {file_path}: {oct(os.stat(file_path).st_mode & 0o777)}")

# Set permissions to rwxr-xr-x (0o755)
oschmod(file_path, 0o755)

print(f"New permissions for {file_path}: {oct(os.stat(file_path).st_mode & 0o777)}")

# Clean up the dummy file
os.remove(file_path)

view raw JSON →