Registry / data / olefileio-pl

olefileio-pl

JSON →
library0.42.1pypypi✓ verified 82d ago

OleFileIO_PL is a Python package designed to parse, read, and write Microsoft OLE2 files, also known as Structured Storage or Compound Document files (e.g., older Microsoft Office formats like .doc, .xls, .ppt). It is an improved version of the original OleFileIO module from the Python Image Library (PIL). The current version is 0.42.1, and it maintains an active, though not rapid, release cadence.

pip install olefileio-pl
INSTALL
IMPORT
SIG · OLEFILEIO-PL
O
olefileio-pl
datapythonv0.42.1
Install
4.1s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.31 · 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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.1s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OleFileIO
from OleFileIO_PL import OleFileIO
from olefile import OleFileIO

This quickstart demonstrates how to check if a file is an OLE document, open it, list its contents, and extract common metadata. Note that for full functionality, you must replace `actual_ole_file_path` with the path to an existing, valid OLE file.

import olefile import os import tempfile # For demonstration, let's create a dummy (non-OLE) file to show error handling. # In a real scenario, you would point to an actual OLE file # (e.g., an old .doc, .xls, .ppt document). dummy_file_path = os.path.join(tempfile.gettempdir(), "dummy_not_ole.txt") with open(dummy_file_path, "w") as f: f.write("This is not an OLE file.") # <<< IMPORTANT: REPLACE THIS with the actual path to your OLE file >>> actual_ole_file_path = "path/to/your/actual_ole_file.doc" print(f"Checking if '{dummy_file_path}' is an OLE file: {olefile.isOleFile(dummy_file_path)}") print(f"Checking if '{actual_ole_file_path}' is an OLE file: {olefile.isOleFile(actual_ole_file_path)}\n") try: # Attempt to open a placeholder file - this will likely fail unless # you replace 'actual_ole_file_path' with a real OLE file. print(f"Attempting to open '{actual_ole_file_path}'...") with olefile.open(actual_ole_file_path) as ole: print(f"Successfully opened '{actual_ole_file_path}'.") # List all top-level streams and storages print("\nTop-level entries:") for entry in ole.listdir(): print(f" - {entry}") # Example: Access a stream if it exists (e.g., 'WordDocument' for .doc files) if ole.exists('WordDocument'): with ole.openstream('WordDocument') as stream: content = stream.read() print(f"\nFirst 100 bytes of 'WordDocument' stream: {content[:100]}") else: print("\n'WordDocument' stream not found.") # Example: Read standard metadata properties (if available) print("\nMetadata (if present):") if ole.exists('Root Entry'): root_props = ole.getproperties('Root Entry') if root_props: for prop_id, prop_name, prop_type, prop_value in root_props: # Common properties like Author (0x04) or Creation Time (0x01) if prop_id == 0x01: print(f" Creation Time: {prop_value.as_datetime()}") elif prop_id == 0x04: print(f" Author: {prop_value.as_str()}") else: print(f" Property {hex(prop_id)} ({prop_name}): {prop_value}") else: print(" No standard properties found in Root Entry.") else: print(" 'Root Entry' not found.") except olefile.BadOleFile: print(f"\nError: '{actual_ole_file_path}' is not a valid OLE file. Please provide a real OLE file.") except FileNotFoundError: print(f"\nError: '{actual_ole_file_path}' not found. Please provide a valid path to an OLE file.") except Exception as e: print(f"\nAn unexpected error occurred: {e}") finally: os.remove(dummy_file_path) # Clean up dummy file print(f"\nCleaned up dummy file: {dummy_file_path}")
Debug
Known issues
gotchaOleFileIO_PL loads the entire OLE file into memory when opened. This can lead to significant memory consumption and performance issues when processing very large OLE files.
fix
Be mindful of file sizes. For extremely large files, consider processing them on systems with ample memory or exploring alternative libraries if memory usage becomes critical.
affects: All versions
gotchaThe `listdir()` method returns a list of tuples, where each tuple represents the path components of a stream or storage. It does not return joined paths (e.g., `[('WordDocument',)]` instead of `['WordDocument']`).
fix
If you need a joined path for display or specific operations, you must manually join the tuple components, e.g., `'/'.join(entry)`.
affects: All versions
gotchaStream and storage names within OLE files are case-sensitive by default in OleFileIO_PL. Searching for a stream with incorrect casing will result in it not being found.
fix
Always use the exact case of stream and storage names as reported by `ole.listdir()`. You can use `ole.exists(name)` to check for existence, or `ole.openstream(name)` within a `try-except olefile.OleFileIO.StreamNotFound` block.
affects: All versions
gotchaWhen retrieving properties using methods like `getproperties()`, the values are returned as `OleProperty` objects, not raw Python types (strings, integers, datetimes).
fix
You must explicitly convert `OleProperty` objects to their desired Python type using methods such as `.as_str()`, `.as_int()`, `.as_datetime()`, `.as_bool()`, etc.
affects: All versions
Upgrade
Version history
0.42.1latest on PyPI · released Jan 25, 2015
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
4
Amazon
1
Resources
olefileio-pl — pip install olefileio-pl · libregistry