Sharedfile
Easily let multiple Python processes read from and write to the same file at once.
A simple, cross-platform Python extension that makes it safe and easy for different processes to open and use the same file at the same time—perfect for logging, sharing data, or coordinating between programs.
Features
- Super simple API:
sharedfile.open(path, mode="r", share="rw") - Works on Windows and POSIX (Linux/macOS)
- Lets you control how files are shared (Windows)
- Uses advisory locking for safe sharing on POSIX systems
- Feels just like Python’s built-in
open
Installation
Install directly from PyPI:
pip install sharedfile
Or build and install manually:
python setup.py build
python setup.py install
Usage Example
Let two processes write to and read from the same file:
import multiprocessing
import time
import sharedfile
def writer():
with sharedfile.open("shared_test.txt", mode="w", share="rw") as f:
for i in range(5):
line = f"Writer line {i}\n"
f.write(line)
f.flush()
print(f"[Writer] wrote: {line.strip()}")
time.sleep(1)
def reader():
time.sleep(0.5) # Let writer start first
with sharedfile.open("shared_test.txt", mode="r", share="rw") as f:
for _ in range(5):
f.seek(0)
content = f.read()
print(f"[Reader] read:\n{content.strip()}")
time.sleep(1)
if __name__ == "__main__":
p1 = multiprocessing.Process(target=writer)
p2 = multiprocessing.Process(target=reader)
p1.start()
p2.start()
p1.join()
p2.join()
API
sharedfile.open(path, mode="r", share="rw")
path: File path.mode: File mode ("r","w","a","r+", etc.).share: (Windows only) Control who else can access the file:"r": Let others read"w": Let others write"rw": Let others read and write- (Ignored on POSIX; uses advisory locking)
Returns: A Python file-like object.
Platform Details
- Windows: Uses native Win32 APIs for explicit read/write sharing.
- POSIX: Uses advisory
fcntllocking for cooperative sharing.
License
Licensed under the Apache License, Version 2.0. See LICENSE for details.
Author
Release files for sharedfile 0.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| sharedfile-0.8-cp314-cp314t-win_amd64.whl | CPython 3.14 | CPython 3.14 free-threading | Windows x86-64 | Details |
| sharedfile-0.8-cp314-cp314t-win32.whl | CPython 3.14 | CPython 3.14 free-threading | Windows x86-32 | Details |
| sharedfile-0.8-cp314-cp314-win_amd64.whl | CPython 3.14 | CPython 3.14 | Windows x86-64 | Details |
| sharedfile-0.8-cp314-cp314-win32.whl | CPython 3.14 | CPython 3.14 | Windows x86-32 | Details |
| sharedfile-0.8-cp313-cp313-win_amd64.whl | CPython 3.13 | CPython 3.13 | Windows x86-64 | Details |
| sharedfile-0.8-cp313-cp313-win32.whl | CPython 3.13 | CPython 3.13 | Windows x86-32 | Details |
| sharedfile-0.8-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| sharedfile-0.8-cp312-cp312-win32.whl | CPython 3.12 | CPython 3.12 | Windows x86-32 | Details |
| sharedfile-0.8-cp311-cp311-win_amd64.whl | CPython 3.11 | CPython 3.11 | Windows x86-64 | Details |
| sharedfile-0.8-cp311-cp311-win32.whl | CPython 3.11 | CPython 3.11 | Windows x86-32 | Details |
| sharedfile-0.8-cp310-cp310-win_amd64.whl | CPython 3.10 | CPython 3.10 | Windows x86-64 | Details |
| sharedfile-0.8-cp310-cp310-win32.whl | CPython 3.10 | CPython 3.10 | Windows x86-32 | Details |
| sharedfile-0.8-cp39-cp39-win_amd64.whl | CPython 3.9 | CPython 3.9 | Windows x86-64 | Details |
| sharedfile-0.8-cp39-cp39-win32.whl | CPython 3.9 | CPython 3.9 | Windows x86-32 | Details |
| sharedfile-0.8-cp38-cp38-win_amd64.whl | CPython 3.8 | CPython 3.8 | Windows x86-64 | Details |
| sharedfile-0.8-cp38-cp38-win32.whl | CPython 3.8 | CPython 3.8 | Windows x86-32 | Details |
Total release size: 191.3 kB