pysrt is a Python library for parsing, modifying, and composing SubRip (.srt) subtitle files. It allows developers to read SRT files, manipulate subtitle text and timing, and save changes. The current version is 1.1.2. The library appears to have a slow release cadence, with the last release being seven years ago and minimal recent development activity on its GitHub repository.
pip install pysrtVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to open an SRT file, access and modify individual subtitle items, shift the timings of all subtitles, and save the changes to a new file. It includes a basic example of creating a dummy SRT file and then cleaning it up.
Specify the `encoding` parameter in `pysrt.open()` to match the SRT file's encoding.
For new projects or if encountering unaddressed issues, consider evaluating alternative, more actively maintained subtitle parsing libraries like the `srt` library (pypi-slug: `srt`), which is reported to be faster and more robust.
Review GitHub issues for potential workarounds or be cautious when performing complex time shifts. Thoroughly test any operations involving `shift` and `to_time()`.
pip install pysrt
subs = pysrt.open('filename.srt', encoding='latin-1') # Or 'cp1252', 'windows-1250', etc., depending on the file's actual encodingsubs.save('output.srt', encoding='utf-8')import pysrt
subs = pysrt.open('input.srt')
subs.shift(hours=1, minutes=5, seconds=0)No dependency data recorded yet.