To open and export .ost files to .pst format, you can use Microsoft Outlook via COM automation with Python and the win32com.client library. This method works only on Windows with Outlook installed.
⚠️ Important Notes:
.ost files are offline Outlook data files tied to an Exchange or IMAP account.
- You cannot directly open an
.ost file in Outlook unless it's associated with a profile.
- To export
.ost to .pst, you must import the .ost into a temporary Outlook profile, then export the mailbox to .pst.
✅ Prerequisites
- Windows OS
- Microsoft Outlook installed
- Python with
pywin32 installed:
pip install pywin32
✅ Python Script: Export OST to PST via Outlook COM
import win32com.client
import os
def export_ost_to_pst(ost_path, pst_output_path):
if not os.path.exists(ost_path):
raise FileNotFoundError(f"OST file not found: {ost_path}")
outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI")
# Create a temporary Outlook profile (manual step required)
# You must manually add the OST file to a profile via Control Panel > Mail > Data Files > Add > OST file
# Access the default store (assumes OST is loaded into the default profile)
store = outlook.DefaultStore
# Create a new PST file
new_pst = outlook.AddStore(pst_output_path)
# Copy all folders and items from the OST store to the PST
root_folder = store.GetRootFolder()
for folder in root_folder.Folders:
folder.CopyTo(new_pst)
# Remove the PST store from Outlook
outlook.RemoveStore(new_pst)
print(f"✅ Export complete: {pst_output_path}")
# Example usage
if __name__ == "__main__":
ost_file = r"C:\Path\To\Your\file.ost"
pst_file = r"C:\Path\To\Output\exported.pst"
export_ost_to_pst(ost_file, pst_file)
⚠️ Manual Step Required
You must manually:
- Open Control Panel > Mail > Show Profiles
- Create a new profile
- Add the
.ost file as a data file (not as an email account)
- Set this profile as default or launch Outlook with it
- Run the script
🛠️ Alternative: Use OST2PST Tools
If you want a fully automated solution without Outlook, use third-party tools like:
- Stellar Converter for OST
- SysTools OST to PST Converter
- Kernel for OST to PST
These tools offer CLI or SDK access, but are paid.
✅ Summary
| Method | Automation | Cost | Notes |
|---|
| Outlook COM + Python | Semi-automated | Free | Requires Outlook & manual profile setup |
| Third-party tools | Fully automated | Paid | No Outlook needed |
Let me know if you want a PowerShell version or a fully automated third-party CLI script.