Registry / serialization / python-oxmsg

python-oxmsg

JSON →
library0.0.2pypypi✓ verified 26d ago

Python-OXMSG is a library designed to parse Outlook MSG (.msg) files to extract email messages and their attachments. Its primary use case focuses on extracting message text and accessing attachments, rather than modifying messages or creating them from scratch. The library also allows access to other message properties like sent-date. The current version is 0.0.2.

pip install python-oxmsg
INSTALL
IMPORT
SIG · PYTHON-OXMSG
P
python-oxmsg
serializationpythonv0.0.2
Install
1.8s avg
Import
125ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.2 · 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.95 runs
installs and imports cleanly · install 0.0s · import 0.128s · 19.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.122s · 20MB
18MB installed
● package 18MB
Code
Verified usage

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

Message
from oxmsg import Message
Main class for loading and parsing .msg files.

Loads a .msg file, accesses its properties like message class and attachment count, and demonstrates how to retrieve attachment details, including their content if available. Note that a real .msg file is required for actual parsing.

import os from oxmsg import Message # Create a dummy .msg file for demonstration purposes # In a real scenario, you would have an actual .msg file dummy_msg_content = b""" This is a placeholder for a .msg file content. In a real application, this would be binary data. """ with open("message.msg", "wb") as f: f.write(dummy_msg_content) try: msg = Message.load("message.msg") print(f"Message Class: {msg.message_class}") print(f"Attachment Count: {msg.attachment_count}") if msg.attachment_count > 0: attachment = msg.attachments[0] print(f" Attachment File Name: {attachment.file_name}") print(f" Attachment MIME Type: {attachment.mime_type}") print(f" Attachment Size: {attachment.size}") if attachment.attached_by_value: print(f" Attachment Bytes (first 20): {attachment.file_bytes[:20]}...") # Example of saving attachment: # with open(attachment.file_name, "wb") as f: # f.write(attachment.file_bytes) else: print(" Attachment bytes not available directly (attached by reference).") else: print("No attachments found.") except Exception as e: print(f"Error processing MSG file: {e}") finally: # Clean up the dummy file if os.path.exists("message.msg"): os.remove("message.msg")
Debug
Known issues
gotchaThe library explicitly states that it does not support modifying or creating Outlook MSG files. Its functionality is limited to parsing and extracting data.
fix
Do not attempt to use `python-oxmsg` for writing or altering .msg files; consider libraries like `msgforge` or `tutao/oxmsg` if creation/modification is needed (though `tutao/oxmsg` is a JavaScript library).
affects: 0.0.1 and later
gotchaWhen accessing attachment content, the `attachment.file_bytes` property is only populated if the attachment's `attached_by_value` property is `True`. If `attached_by_value` is `False`, the bytes are not directly available through this property, indicating it's an attachment by reference (e.g., a linked file).
fix
Always check `attachment.attached_by_value` before attempting to read `attachment.file_bytes` to avoid unexpected empty byte strings or errors.
affects: 0.0.1 and later
breakingPython-OXMSG requires Python 3.9 or higher. Users running older Python versions will encounter installation or runtime errors.
fix
Upgrade your Python environment to version 3.9 or newer. Python 3.9 reached end-of-life, so it is recommended to use actively supported versions like Python 3.10, 3.11, or 3.12.
affects: 0.0.1 and later
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'oxmsg'
The 'python-oxmsg' package is not installed in your current Python environment.
fix
pip install python-oxmsg
AttributeError: module 'oxmsg' has no attribute 'Oxmsg'
You are trying to access the 'Oxmsg' class as an attribute of the 'oxmsg' module after using 'import oxmsg', but the class needs to be imported directly.
fix
from oxmsg import Oxmsg
TypeError: Oxmsg() missing 1 required positional argument: 'filepath'
The 'Oxmsg' class constructor requires the path to the Outlook MSG file as its first argument.
fix
msg = Oxmsg('path/to/your/outlook_email.msg')
FileNotFoundError: [Errno 2] No such file or directory: 'your_file.msg'
The provided file path for the Outlook MSG (.msg) file is incorrect, or the file does not exist at the specified location.
fix
Ensure the file path is correct and the '.msg' file exists in the specified directory or provide an absolute path.
Upgrade
Version history
0.0.2latest on PyPI · released Feb 3, 2025
Audit
Dependencies
clickrequiredUsed for the command-line interface.
olefilerequiredHandles the underlying OLE Structured Storage format of .msg files.
typing_extensionsrequiredProvides backported and experimental type hints.
Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
python-oxmsg — pip install python-oxmsg · libregistry