pycdlib
PyCdlib is a pure Python library designed to parse, create, and manipulate ISO9660 files, suitable for writing to a CD or USB. It supports various extensions including El Torito, Joliet, Rock Ridge, and UDF. The current stable version available on PyPI is 1.14.0, and it maintains a relatively active development and release cadence.
Warnings
- breaking Python 2.7 compatibility has been removed. PyCdlib versions 1.14.0 and later are strictly Python 3 compatible.
- gotcha PyCdlib employs a 'lazy' approach to updating ISO metadata for performance. This means that direct inspection of the `PyCdlib` object's internal metadata state might not always reflect the absolute latest changes until `force_consistency()` is explicitly called.
- gotcha The library may throw `PyCdlibInvalidISO` or `PyCdlibInternalError` exceptions when encountering ISO files that do not strictly adhere to relevant standards.
- gotcha Version 1.15.0 has been released on GitHub but is not yet available on PyPI (as of current date). Users wishing to access the absolute latest features or fixes must install directly from the GitHub repository rather than via `pip install pycdlib`.
Install
-
pip install pycdlib
Imports
- PyCdlib
from pycdlib import PyCdlib
Quickstart
from pycdlib import PyCdlib
from io import BytesIO
import os
# Create a new, empty ISO
iso = PyCdlib()
iso.new(interchange_level=3, joliet=True, rock_ridge='1.09')
# Add a directory
iso.add_directory('/TESTDIR;1')
# Add a file from a BytesIO object
file_content = b"Hello, pycdlib!\n"
iso.add_fp(BytesIO(file_content), len(file_content), '/TESTFILE.TXT;1',
joliet_path='/testfile.txt', rock_ridge_path='testfile.txt')
# Define output path (using a temporary file for quickstart example)
output_path = 'my_new_iso.iso'
# Write the ISO to a file
try:
iso.write(output_path)
print(f"Successfully created ISO image: {output_path}")
except Exception as e:
print(f"Error creating ISO: {e}")
finally:
iso.close()
# Clean up the created file for the quickstart example
if os.path.exists(output_path):
# os.remove(output_path) # Uncomment to clean up automatically
pass