Skip to main content

winunlock

winunlock is a Windows Python module that provides functionality for opening certain types of locked files in Windows, especially the ones that are usually inaccessible due to external locks (e.g. an Excel file being locked by OneDrive). The module exposes two utilities:

  • winunlock.open mimics Python's built-in open but is capable of accessing locked files, and
  • winunlock.monkeypatch_open are used to monkey patch Python's built-in open to allow reading locked files.

Installation

pip install winunlock

Usage

Basic open:

import winunlock

# winunlock.open has the same interface as open
with winunlock.open("locked_file_path.txt", "r") as f:
    content = f.read()

Monkey patching:

from winunlock import monkeypatch_open
import pandas as pd

with monkeypatch_open():
    # open has been temporarily patched
    with open("locked_file_path.txt", "r") as f:
        content = f.read()

    # external code can now read locked files by default
    pd.load_csv("locked_file_path.txt")

Testing

The testing framework used is unittest. The tests are currently dependent on a working Excel installation. You can run the tests by executing the provided test script:

python tests.py

In order to test full compatibility with Python's open, more tests are needed.

Limitations

While winunlock is designed to handle locked files gracefully, there are certain intense locks (as demonstrated in one of the tests) that it might still not be able to handle.

Contributing

Contributions to improve winunlock or expand its functionalities are welcome. Please ensure that you include unit tests for any new features or changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.


Documentation

winunlock.open

def open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None):
    pass

This function is a drop-in replacement for Python's built-in open, designed to work with locked files.

Parameters:

  • All parameters are the same as the built-in open.

winunlock.monkeypatch_open

@contextlib.contextmanager
def monkeypatch_open():
    pass

This context manager monkey patch Python's built-in open function in order to try to open a file via winunlock.open after open throws a PermissionError. After using the context manager, the built-in open will return to its normal functionality once out of the context.

Metadata

Release files for winunlock 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for winunlock 0.1.6
File Size Uploaded
winunlock-0.1.6.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for winunlock 0.1.6
File Interpreter ABI Platform
winunlock-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 24.8 kB

Release files / winunlock-0.1.6.tar.gz

Download URL winunlock-0.1.6.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ccb8ea67a9372f5cb9fa8ac6a9921bea4620b1d57fc16efc93bbcccab19e0ebe
BLAKE2b-256 checksum
How to use checksums
b4b73df1a6393a86b06f8660e200ddbefb34e5a67a3ddf4ecf1df2a2247562c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release files / winunlock-0.1.6-py3-none-any.whl

Download URL winunlock-0.1.6-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
45682f8ef4fae6abbde4913cda130a606940aae83931d1997d70da31a2ca618c
BLAKE2b-256 checksum
How to use checksums
8d840032027c459631b7ba617bfe2be497d354aa969d039b99360dd488339138
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.17

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page