Skip to main content

pyass

A library to read, manipulate, and write Advanced SubStation Alpha (.ass) files

Installation

pip3 install pyass

Quickstart

import pyass

from datetime import timedelta

# subtitles.ass
'''
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: New subtitles
ScriptType: v4.00+
WrapStyle: 0
PlayResX: 640
PlayResY: 480
ScaledBorderAndShadow: yes

[Aegisub Project Garbage]

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Arial,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,This is an event
'''

# Read an .ass file
# .ass files are typically encoded using "utf_8_sig"
with open("subtitles.ass", encoding="utf_8_sig") as f:
    script = pyass.load(f)

# Read styles
for style in script.styles:
    # Style name: Default, Font name: Arial, Font size: 20, Primary color: &H00FFFFFF
    print(f'Style name: {style.name}, Font name: {style.fontName}, Font size: {style.fontSize}, Primary color: {style.primaryColor}')

# Modify styles
script.styles[0].fontName = "Times New Roman"

# Add styles
script.styles.append(pyass.Style(name="New Style", primaryColor=pyass.Color(r=0xFF)))

for style in script.styles:
    # Style name: Default, Font name: Times New Roman, Font size: 20, Primary color: &H00FFFFFF
    # Style name: New Style, Font name: Arial, Font size: 48, Primary color: &H000000FF
    print(f'Style name: {style.name}, Font name: {style.fontName}, Font size: {style.fontSize}, Primary color: {style.primaryColor}')

# Read events
for event in script.events:
    # Style: Default, Start: 0:00:00.00, End: 0:00:05.00, Text: This is an event
    print(f'Style: {event.style}, Start: {event.start}, End: {event.end}, Text: {event.text}')

# Modify events
script.events[0].text = "Some new text"

# Add events
script.events.append(pyass.Event(format=pyass.EventFormat.COMMENT, start=timedelta(seconds=0), end=timedelta(seconds=10), text="This is a comment"))

for event in script.events:
    # Style: Default, Start: 0:00:00.00, End: 0:00:05.00, Text: Some new text
    # Style: Default, Start: 0:00:00, End: 0:00:10, Text: This is a comment
    print(f'Style: {event.style}, Start: {event.start}, End: {event.end}, Text: {event.text}')

# Write an .ass file
# .ass files are typically encoded using "utf_8_sig"
with open("new_subtitles.ass", "w+", encoding="utf_8_sig") as f:
    pyass.dump(script, f)

# new_subtitles.ass
'''
[Script Info]
; Script generated by Aegisub 3.2.2
; http://www.aegisub.org/
Title: New subtitles
ScriptType: v4.00+
WrapStyle: 0
PlayResX: 640
PlayResY: 480
ScaledBorderAndShadow: yes

[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Times New Roman,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1
Style: New Style,Arial,48,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,2,2,10,10,10,1

[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Dialogue: 0,0:00:00.00,0:00:05.00,Default,,0,0,0,,Some new text
Comment: 0,0:00:00.00,0:00:10.00,Default,,0,0,0,,This is a comment
'''

Metadata

Release files for pyass 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyass 0.1.4
File Size Uploaded
pyass-0.1.4.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyass 0.1.4
File Interpreter ABI Platform
pyass-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 30.3 kB

Release files / pyass-0.1.4.tar.gz

Download URL pyass-0.1.4.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a2be209be92adc504fd052c4d6f80931c2d35f10642a84bbf9f535ef80af315b
BLAKE2b-256 checksum
How to use checksums
7ae3f578390546ec381d129fb78c3519c926b78aacd9c471d5c080f0bde9079f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / pyass-0.1.4-py3-none-any.whl

Download URL pyass-0.1.4-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
25be1c74301fe0ae14a3fcbfb2ea7c70f5842b2eca902da334e355c920acbb86
BLAKE2b-256 checksum
How to use checksums
897bfd66125da6d85b1e780481c9415f518aec41e7cf8c969e3ef70786d42760
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.4 This release

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page