Quickstart

Parse an SRT to Python objects

>>> import srt
>>> subtitle_generator = srt.parse('''\
... 1
... 00:31:37,894 --> 00:31:39,928
... OK, look, I think I have a plan here.
...
... 2
... 00:31:39,931 --> 00:31:41,931
... Using mainly spoons,
...
... 3
... 00:31:41,933 --> 00:31:43,435
... we dig a tunnel under the city and release it into the wild.
...
... ''')
>>> subtitles = list(subtitle_generator)
>>>
>>> subtitles[0].start
datetime.timedelta(0, 1897, 894000)
>>> subtitles[1].content
'Using mainly spoons,'

Compose an SRT from Python objects

>>> print(srt.compose(subtitles))
1
00:31:37,894 --> 00:31:39,928
OK, look, I think I have a plan here.

2
00:31:39,931 --> 00:31:41,931
Using mainly spoons,

3
00:31:41,933 --> 00:31:43,435
we dig a tunnel under the city and release it into the wild.