config

janim.utils.config.optional_type_validator(type, typename: str)
class janim.utils.config.Config(*, fps: int = None, preview_fps: int = None, anti_alias_width: float = None, frame_height: float = None, frame_width: float = None, pixel_height: int = None, pixel_width: int = None, background_color: Color = None, font: str | Iterable[str] = None, subtitle_font: str | Iterable[str] = None, subtitle_to_edge_buff: float = None, audio_framerate: int = None, audio_channels: int = None, wnd_pos: str = None, wnd_monitor: int = None, typst_bin: str = None, typst_shared_preamble: str = None, typst_text_preamble: str = None, typst_math_preamble: str = None, ffmpeg_bin: str = None, ffprobe_bin: str = None, output_dir: str = None, temp_dir: str | Path = None, asset_dir: str | Path | list[str | Path] = None, client_search_port: int = None)

Bases: object

Configuration

Most parameters are not explained, but here are some notes on these parameters:

  • fps: Frame rate when outputting video

  • preview_fps: Frame rate in the preview window

  • When setting background_color in code, you cannot use background_color='#RRGGBB', you should use background_color=Color('#RRGGBB')

  • When output_dir starts with :, it represents a path relative to the .py file, for example output_dir=':/videos'

Setting Configuration

Three ways to set configuration:

  1. In Python code, write the configuration in the timeline class

    class YourTimeline(Timeline):
        CONFIG = Config(
            fps=120,
            preview_fps=30
        )
    
        def construct(self) -> None:
            ...
    

See also CONFIG

  1. Modify global configuration using command-line arguments

    janim write your_file.py YourTimeline -c fps 120 -c output_dir custom_dir
    
  2. Modify configuration for local code blocks

    class YourTimeline(Timeline):
        def construct(self):
            txt1 = Text('Using default font')
    
            with Config(font='Noto Serif CJK SC'):
                txt2 = Text('Using "Noto Serif CJK SC" font')
    
            txt3 = Text('Using default font again')
    
            group = Group(txt1, txt2, txt3).show()
            group.points.arrange(DOWN, aligned_edge=LEFT)
    

Getting Configuration

Use Config.get.xxx to get attributes, for example:

class YourTimeline(Timeline):
    def construct(self):
        print(Config.get.fps)

For more information, refer to the Configuration System page in the documentation tutorials

fps: int
preview_fps: int
anti_alias_width: float
frame_height: float
frame_width: float
pixel_height: int
pixel_width: int
background_color: Color
font: str | Iterable[str]
subtitle_font: str | Iterable[str]
subtitle_to_edge_buff: float
audio_framerate: int
audio_channels: int
wnd_pos: str
wnd_monitor: int
typst_bin: str
typst_shared_preamble: str
typst_text_preamble: str
typst_math_preamble: str
ffmpeg_bin: str
ffprobe_bin: str
output_dir: str
temp_dir: str | Path
asset_dir: str | Path | list[str | Path]
client_search_port: int
janim.utils.config.is_power_plugged() bool
janim.utils.config.default_config = Config(fps=60, preview_fps=60, anti_alias_width=0.015, frame_height=8.0, frame_width=14.222222222222221, pixel_height=1080, pixel_width=1920, background_color=<Color black>, font='Consolas', subtitle_font='', subtitle_to_edge_buff=0.5, audio_framerate=44100, audio_channels=2, wnd_pos='OR', wnd_monitor=0, typst_bin='typst', typst_shared_preamble='', typst_text_preamble='', typst_math_preamble='', ffmpeg_bin='ffmpeg', ffprobe_bin='ffprobe', output_dir='videos', temp_dir='/tmp/janim', asset_dir='', client_search_port=40565)

Default configuration

Where:

  • preview_fps is 60 when power is plugged and 30 when not plugged.

  • temp_dir is determined by the operating system.

janim.utils.config.cli_config = Config(fps=None, preview_fps=None, anti_alias_width=None, frame_height=None, frame_width=None, pixel_height=None, pixel_width=None, background_color=None, font=None, subtitle_font=None, subtitle_to_edge_buff=None, audio_framerate=None, audio_channels=None, wnd_pos=None, wnd_monitor=None, typst_bin=None, typst_shared_preamble=None, typst_text_preamble=None, typst_math_preamble=None, ffmpeg_bin=None, ffprobe_bin=None, output_dir=None, temp_dir=None, asset_dir=None, client_search_port=None)

Command-line configuration

Will be automatically modified by the command-line --config parameter

class janim.utils.config.ConfigGetter(config_ctx: list[Config] | None = None)

Bases: object

The retrieval of data associated with configuration settings.

Please continue to use Config.get.xxx to retrieve the content defined in this class.

walk() Generator[Config, None, None]
property aspect_ratio: float
property frame_x_radius: float
property frame_y_radius: float
property pixel_to_frame_ratio: float
property default_pixel_to_frame_ratio: float
property left_side: Vect
property right_side: Vect
property bottom: Vect
property top: Vect
formated_output_dir(relative_path: str) str

To convert :/path/to/file to a path relative to relative_path.

scaled_pixel_size(scale: float) dict[str, int]

Calculate scaled pixel size based on the scaling factor

Usage example:

Config(
    **Config.get.scaled_pixel_size(0.5)
)
scaled_frame_size(scale: float) dict[str, float]

Calculate scaled frame size based on the scaling factor

Usage example:

Config(
    **Config.get.scaled_frame_size(0.5)
)
scaled_width(scale: float) dict[str, float]

Calculate scaled pixel width and frame width based on the scaling factor

Usage example:

Config(
    **Config.get.scaled_width(0.5)
)
scaled_height(scale: float) dict[str, float]

Calculate scaled pixe height and frame height based on the scaling factor

Usage example:

Config(
    **Config.get.scaled_height(0.5)
)
scaled_size(scale: float) dict[str, float]

Calculate scaled pixel size and frame size based on the scaling factor

Usage example:

Config(
    **Config.get.scaled_size(0.5)
)
swapped_size() dict[str, int]

Gets the pixel size and frame size with width and height swapped

Usage example (converting landscape configuration to portrait):

Config(
    **Config.get.swapped_size()
)