Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

SubRip (.srt) subtitle parser and writer

Project description


pysrt is a Python library used to edit or create SubRip files.


pysrt is mainly designed as a library, but if you are experiencing troubles with bad subtitles you can first try to use ruby-osdb which will try to find the best subtitle for your movie. If you are still unlucky pysrt also provide an srt command useful for either shift, split, or rescale a .srt file.

Command Usage


$ srt -i shift 2s500ms


$ srt split 58m26s


$ srt -i rate 23.9 25


pysrt is available on pypi. To intall it you can use either


$ sudo pip install pysrt

or distutils:

$ sudo easy_install pysrt

It is compatible with python >= 2.6 and 3.

Library Usage


>>> import pysrt


>>> subs ='some/')
# If you get a UnicodeDecodeError try to specify the encoding
>>> subs ='some/', encoding='iso-8859-1')

SubRipFile are list-like objects of SubRipItem instances:

>>> len(subs)
>>> first_sub = subs[0]

SubRipItem instances are editable just like pure Python objects:

>>> first_sub.text = "Hello World !"
>>> first_sub.start.seconds = 20
>>> first_sub.end.minutes = 5


>>> subs.shift(seconds=-2) # Move all subs 2 seconds earlier
>>> subs.shift(minutes=1)  # Move all subs 1 minutes later
>>> subs.shift(ratio=25/23.9) # convert a 23.9 fps subtitle in 25 fps
>>> first_sub.shift(seconds=1) # Move the first sub 1 second later
>>> first_sub.start += {'seconds': -1} # Make the first sub start 1 second earlier


>>> del subs[12]


>>> part = subs.slice(starts_after={'minutes': 2, 'seconds': 30}, ends_before={'minutes': 3, 'seconds': 40})
>>> part.shift(seconds=-2)

Saving changes:

>>>'other/', encoding='utf-8')

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for pysrt, version 1.1.2
Filename, size File type Python version Upload date Hashes
Filename, size pysrt-1.1.2.tar.gz (104.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page