pycdlib

1.14.0 · active · verified Thu Apr 09

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

Install

Imports

Quickstart

This quickstart demonstrates how to create a new ISO image, add a directory and a file to it, and then write the ISO to a local file. It includes support for Joliet and Rock Ridge extensions during creation and file addition.

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

view raw JSON →