epublib.identifier module

class EPUBId

Bases: str

A unique identifier for a resource within an EPUB file. Use this class to reference epub resources throughout the library using it’s manifest id rather than its complete filename.

Typical usage:

>>> EPUBId("chapter1")
'chapter1'
>>> EPUBId("chapter1") == "chapter1"
True
>>> EPUBId("chapter 1").valid
False
>>> EPUBId.to_valid("chapter 1")
'chapter_1'
Parameters:

value – The identifier string.

classmethod is_valid(value: str) bool

Check if the identifier is valid according to the XML specification.

Returns:

True if the identifier is valid, False otherwise.

classmethod to_valid(value: str) Self

Convert a string to a valid EPUBId by replacing invalid characters with underscores.

Parameters:

value (str) – The string to convert.

Returns:

A valid EPUBId instance.

Return type:

EPUBId