webvtt-py is a Python library (current version 0.5.1) for reading, writing, converting, and segmenting WebVTT caption files. It is actively maintained with regular releases, often several times a year, addressing new features, bug fixes, and Python compatibility.
pip install webvtt-pyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to read an existing WebVTT file, iterate over its captions, and then create a new WebVTT object programmatically, add captions to it, and save it to a new file. It also includes creating a dummy file for immediate execution.
Upgrade your Python environment to 3.7 or higher.
Use `webvtt.from_buffer()` instead for reading from file-like objects or in-memory buffers.
If you need the raw, uncleaned text, access `caption.raw_text`. Otherwise, `caption.text` provides a clean payload.
Be aware that malformed WebVTT files might be parsed differently (more leniently) than in older versions. If strict validation is required, consider pre-validating files or implementing custom checks.
Upgrade to version 0.5.1 or newer to ensure SRT output is clean of WebVTT-specific cue tags.
Ensure the package is installed with `pip install webvtt-py` and then import it using `import webvtt` or `from webvtt import WebVTT`.
Validate and correct the WebVTT file to ensure it strictly adheres to the WebVTT specification, particularly the `WEBVTT` header on the first line, correct timestamp formats (`HH:MM:SS.mmm --> HH:MM:SS.mmm`), and blank lines between cues.
Call `read()` as `webvtt.WebVTT.read('path/to/file.vtt')` or use the top-level convenience function `webvtt.read('path/to/file.vtt')`.Specify the correct encoding when reading the file, for example, `webvtt.read('file.vtt', encoding='latin-1')` or `webvtt.read('file.vtt', encoding='cp1252')`, replacing with the actual encoding of your file.No dependency data recorded yet.