Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.019s · 17.9MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.017s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
extract
✓ from mozfile import extract
move
✓ from mozfile import move
✗ import shutil; shutil.move(...)
mozfile.move provides enhanced robustness, especially on Windows, by retrying operations on common file access errors.
remove
✓ from mozfile import remove
✗ import shutil; shutil.rmtree(...)
mozfile.remove provides enhanced robustness, especially on Windows, by retrying operations and suppressing errors for non-existent paths (unlike shutil.rmtree).
This quickstart demonstrates the core utilities of `mozfile`: `move` and `remove`. These functions offer enhanced reliability over standard `shutil` operations, particularly in test environments and on Windows where file locking can be problematic. The `remove` function notably does not raise an error if the path does not exist.
import os
from mozfile import move, remove
# Create some dummy files/directories for demonstration
if not os.path.exists('test_dir_src'):
os.makedirs('test_dir_src')
with open('test_dir_src/file1.txt', 'w') as f:
f.write('hello world')
# 1. Use mozfile.move to move a file or directory
try:
print(f"Moving 'test_dir_src/file1.txt' to 'file1_moved.txt'...")
move('test_dir_src/file1.txt', 'file1_moved.txt')
print(f"'file1_moved.txt' exists: {os.path.exists('file1_moved.txt')}")
finally:
# Clean up after move
if os.path.exists('file1_moved.txt'):
os.remove('file1_moved.txt')
# 2. Use mozfile.remove to recursively delete a directory
# This version is more resilient to Windows file lock issues
print(f"Removing 'test_dir_src'...")
remove('test_dir_src')
print(f"'test_dir_src' exists: {os.path.exists('test_dir_src')}")
# 3. Demonstrate remove for non-existent path (no error)
print(f"Attempting to remove a non-existent path 'non_existent_dir'...")
remove('non_existent_dir')
print("No error raised, as expected for mozfile.remove on non-existent paths.")
Errors
Common errors & fixes
[WinError 32] The process cannot access the file because it is being used by another process:
Attempting to move or remove files/directories on Windows that are still locked by another process or application (e.g., explorer, antivirus). Standard `shutil` functions often fail in this scenario.
fixUse `mozfile.move()` or `mozfile.remove()` instead of `shutil.move()` or `shutil.rmtree()`. `mozfile` includes retry logic for such errors, significantly improving reliability in these situations.
[Errno 13] Permission denied:
Similar to `WinError 32`, this often occurs when trying to modify or delete files/directories without sufficient permissions or when they are temporarily held by another process. This is common in automated testing environments.
fixSwitch to `mozfile.move()` or `mozfile.remove()`. These functions are designed to mitigate these common permission/access denial issues by retrying the operation with a delay.
Upgrade
Version history
3.0.0latest on PyPI · released Oct 13, 2022
Audit
Dependencies
orjsonoptionalUsed as a compatibility shim for JSON operations if available, falling back to `stdlib json`. It is an optional dependency.