rich.progress¶
- class rich.progress.BarColumn(bar_width=40, style='bar.back', complete_style='bar.complete', finished_style='bar.finished', pulse_style='bar.pulse', table_column=None)[ソース]¶
視覚的なプログレスバーをレンダリングします。
- パラメータ
bar_width (Optional[int], オプション) – バーの幅、または全幅にする場合はNone。デフォルトは40。
style (StyleType, オプション) – バーの背景のスタイル。デフォルトは "bar.back"。
complete_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.complete"。
finished_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.finished"。
pulse_style (StyleType, オプション) – パルスバーのスタイル。デフォルトは "bar.pulse"。
- class rich.progress.DownloadColumn(binary_units=False, table_column=None)[ソース]¶
ダウンロード済みのファイルサイズと合計サイズをレンダリングします(例: '0.5/2.3 GB')。
- パラメータ
- class rich.progress.MofNCompleteColumn(separator='/', table_column=None)[ソース]¶
完了数/合計数をレンダリングします(例: '10/1000')。
整数量の境界のあるタスクに最適です。
スペースは完了数を埋め、タスクが10の累乗を超えて進行しても進捗の長さが変わらないようにします。
- class rich.progress.Progress(*columns, console=None, auto_refresh=True, refresh_per_second=10, speed_estimate_period=30.0, transient=False, redirect_stdout=True, redirect_stderr=True, get_time=None, disable=False, expand=False)[ソース]¶
自動更新するプログレスバーをレンダリングします。
- パラメータ
console (Console, オプション) – オプションのConsoleインスタンス。デフォルトではstdoutに出力する内部Consoleインスタンスを使用します。
auto_refresh (bool, オプション) – 自動更新を有効にするかどうか。無効にした場合、`refresh()`を呼び出す必要があります。
refresh_per_second (Optional[float], オプション) – 進捗情報を更新する1秒あたりの回数、またはデフォルトを使用する場合はNone (10)。デフォルトはNone。
speed_estimate_period (float) – (float, オプション): 速度推定の計算に使用される期間(秒単位)。デフォルトは30。
transient (bool) – (bool, オプション): 終了時に進捗をクリアするかどうか。デフォルトはFalse。
redirect_stdout (bool) – (bool, オプション): stdoutのリダイレクトを有効にするかどうか。`print`を使用できるようにします。デフォルトはTrue。
redirect_stderr (bool) – (bool, オプション): stderrのリダイレクトを有効にするかどうか。デフォルトはTrue。
get_time (Optional[Callable[[], float]]) – (Callable, オプション): 現在の時刻を取得する呼び出し可能オブジェクト、またはConsole.get_timeを使用する場合はNone。デフォルトはNone。
disable (bool, オプション) – 進捗表示を無効にするかどうか。デフォルトはFalse。
expand (bool, オプション) – タスクテーブルを幅に合わせて展開するかどうか。デフォルトはFalse。
columns (Union[str, ProgressColumn]) –
- add_task(description, start=True, total=100.0, completed=0, visible=True, **fields)[source]¶
プログレス表示に新しい「タスク」を追加します。
- パラメータ
description (str) – タスクの説明。
start (bool, optional) – タスクをすぐに開始します(経過時間を計算するため)。Falseに設定すると、`start` を手動で呼び出す必要があります。デフォルトはTrueです。
total (float, optional) – 知られている場合、プログレスの総ステップ数。パルスアニメーションを表示するにはNoneに設定します。デフォルトは100です。
completed (int, optional) – これまでに完了したステップ数。デフォルトは0です。
visible (bool, optional) – タスクの表示を有効にします。デフォルトはTrueです。
**fields (str) – レンダリングに必要な追加のデータフィールド。
- 戻り値
`update` を呼び出す際に使用できるID。
- 戻り値の型
TaskID
- advance(task_id, advance=1)[source]¶
タスクを一定のステップ数だけ進めます。
- パラメータ
task_id (TaskID) – タスクのID。
advance (float) – 進めるステップ数。デフォルトは1です。
- 戻り値の型
None
- property finished: bool¶
すべてのタスクが完了したかどうかを確認します。
- classmethod get_default_columns()[source]¶
- 新しいProgressインスタンスで使用されるデフォルトのカラムを取得します。
説明のためのテキストカラム (TextColumn)
バー自体 (BarColumn)
完了率を表示するテキストカラム (TextColumn)
残りの推定時間カラム (TimeRemainingColumn)
columns引数を渡さずにProgressインスタンスを作成した場合、ここで定義されているデフォルトのカラムが使用されます。
この例のように、デフォルトの前後にカスタムカラムを使用してProgressインスタンスを作成することもできます。
- progress = Progress(
SpinnerColumn(), Progress.default_columns(), “経過時間:”, TimeElapsedColumn(),
)
このコードは、左側にスピナー、デフォルトのカラム、ラベル付きの経過時間カラムを含むProgress表示の作成を示しています。
- 戻り値の型
Tuple[ProgressColumn, …]
- get_renderable()[source]¶
プログレス表示のレンダリング可能なオブジェクトを取得します。
- 戻り値の型
Union[ConsoleRenderable, RichCast, str]
- get_renderables()[source]¶
プログレス表示の複数のレンダリング可能なオブジェクトを取得します。
- 戻り値の型
Iterable[Union[ConsoleRenderable, RichCast, str]]
- make_tasks_table(tasks)[source]¶
Progress表示をレンダリングするためのテーブルを取得します。
- パラメータ
tasks (Iterable[Task]) – テーブルの各行に対応するTaskインスタンスのイテラブル。
- 戻り値
テーブルインスタンス。
- 戻り値の型
- open(file: Union[str, PathLike[str], bytes], mode: typing_extensions.Literal['rb'], buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, *, total: Optional[int] = None, task_id: Optional[TaskID] = None, description: str = 'Reading...') BinaryIO [source]¶
- open(file: Union[str, PathLike[str], bytes], mode: Union[typing_extensions.Literal[r], typing_extensions.Literal[rt]], buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, *, total: Optional[int] = None, task_id: Optional[TaskID] = None, description: str = 'Reading...') TextIO
バイナリファイルからの読み込み中に進捗状況を追跡します。
- パラメータ
- 戻り値
バイナリモードで読み取り可能なファイルのようなオブジェクト。
- 戻り値の型
BinaryIO
- 例外
ValueError – 無効なモードが指定された場合。
- reset(task_id, *, start=True, total=None, completed=0, visible=None, description=None, **fields)[source]¶
タスクをリセットして、完了数を0にし、クロックをリセットします。
- パラメータ
task_id (TaskID) – タスクのID。
start (bool, optional) – リセット後にタスクを開始します。デフォルトはTrue。
total (float, optional) – タスクの新しい合計ステップ数、または現在の合計を使用する場合はNone。デフォルトはNone。
completed (int, optional) – 完了したステップ数。デフォルトは0。
visible (bool, optional) – タスクの表示を有効にします。デフォルトはTrueです。
description (str, optional) – Noneでない場合、タスクの説明を変更します。デフォルトはNone。
**fields (str) – レンダリングに必要な追加のデータフィールド。
- 戻り値の型
None
- start_task(task_id)[source]¶
タスクを開始します。
経過時間を計算する場合にタスクを開始します ( `start=False` で `add_task` を呼び出した場合は、手動で呼び出す必要がある場合があります)。
- パラメータ
task_id (TaskID) – タスクのID。
- 戻り値の型
None
- stop_task(task_id)[source]¶
タスクを停止します。
これにより、タスクの経過時間が固定されます。
- パラメータ
task_id (TaskID) – タスクのID。
- 戻り値の型
None
- track(sequence, total=None, task_id=None, description='Working...', update_period=0.1)[source]¶
シーケンスを反復処理することで進捗状況を追跡します。
- パラメータ
sequence (Sequence[ProgressType]) – 進捗状況を追跡する反復処理対象の値のシーケンス。
total (Optional[float]) – (float, オプション): ステップの総数。デフォルトはlen(sequence)。
task_id (Optional[TaskID]) – (TaskID): 追跡するタスク。デフォルトは新規タスク。
description (str) – (str, オプション): 新規タスクが作成された場合のタスクの説明。
update_period (float, オプション) – update() への呼び出し間の最小時間(秒単位)。デフォルトは 0.1。
- 戻り値
指定されたシーケンスから取得された値のイテラブル。
- 戻り値の型
Iterable[ProgressType]
- update(task_id, *, total=None, completed=None, advance=None, description=None, visible=None, refresh=False, **fields)[source]¶
タスクに関連付けられた情報を更新します。
- パラメータ
task_id (TaskID) – タスクID(add_taskによって返される)。
total (float, オプション) – Noneでない場合、task.totalを更新します。
completed (float, オプション) – Noneでない場合、task.completedを更新します。
advance (float, オプション) – Noneでない場合、task.completedに値を追加します。
description (str, オプション) – Noneでない場合、タスクの説明を変更します。
visible (bool, オプション) – Noneでない場合、visibleフラグを設定します。
refresh (bool) – 進捗情報の更新を強制します。デフォルトはFalse。
**fields (Any) – レンダリングに必要な追加データフィールド。
- 戻り値の型
None
- wrap_file(file, total=None, *, task_id=None, description='Reading...')[source]¶
バイナリファイルからのファイル読み取りの進捗状況を追跡します。
- パラメータ
- 戻り値
バイナリモードで読み取り可能なファイルのようなオブジェクト。
- 戻り値の型
BinaryIO
- 例外
ValueError – 引数またはタスクからtotal値を取得できない場合。
- class rich.progress.ProgressSample(timestamp, completed)[source]¶
特定の時間の進捗状況のサンプル。
- property completed¶
完了したステップ数。
- property timestamp¶
サンプルのタイムスタンプ。
- class rich.progress.RenderableColumn(renderable='', *, table_column=None)[source]¶
任意の列を挿入するための列。
- パラメータ
- class rich.progress.SpinnerColumn(spinner_name='dots', style='progress.spinner', speed=1.0, finished_text=' ', table_column=None)[source]¶
「スピナー」アニメーション付きの列。
- パラメータ
- render(task)[source]¶
レンダリング可能なオブジェクトを返す必要があります。
- パラメータ
task (Task) –
- 戻り値の型
Union[ConsoleRenderable, RichCast, str]
- class rich.progress.Task(id, description, total, completed, _get_time, finished_time=None, visible=True, fields=<factory>, finished_speed=None, _lock=<factory>)[source]¶
進捗タスクに関する情報。
Progress
クラス以外では、このオブジェクトは読み取り専用とみなしてください。- パラメータ
- id: TaskID¶
このタスクに関連付けられたタスクID(Progressメソッドで使用)。
- class rich.progress.TaskProgressColumn(text_format='[progress.percentage]{task.percentage:>3.0f}%', text_format_no_percentage='', style='none', justify='left', markup=True, highlighter=None, table_column=None, show_speed=False)[source]¶
タスクの進捗状況をパーセンテージで表示します。
- パラメータ
text_format (str, optional) – パーセンテージ表示のフォーマット。デフォルトは“[progress.percentage]{task.percentage:>3.0f}%”。
text_format_no_percentage (str, optional) – パーセンテージが不明な場合のフォーマット。デフォルトは""。
style (StyleType, optional) – 出力のスタイル。デフォルトは"none"。
justify (JustifyMethod, optional) – テキストの揃え方。デフォルトは"left"。
markup (bool, optional) – マークアップを有効にするかどうか。デフォルトはTrue。
highlighter (Optional[Highlighter], optional) – 出力に適用するハイライター。デフォルトはNone。
table_column (Optional[Column], optional) – 使用するテーブル列。デフォルトはNone。
show_speed (bool, optional) – 合計値が不明な場合に速度を表示するかどうか。デフォルトはFalse。
- class rich.progress.TextColumn(text_format, style='none', justify='left', markup=True, highlighter=None, table_column=None)[source]¶
テキストを含む列。
- パラメータ
- class rich.progress.TimeRemainingColumn(compact=False, elapsed_when_finished=False, table_column=None)[source]¶
残り時間の推定値を表示します。
- パラメータ
- rich.progress.open(file: Union[str, PathLike[str], bytes], mode: Union[typing_extensions.Literal[rt], typing_extensions.Literal[r]], buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, *, total: Optional[int] = None, description: str = 'Reading...', auto_refresh: bool = True, console: Optional[Console] = None, transient: bool = False, get_time: Optional[Callable[[], float]] = None, refresh_per_second: float = 10, style: Union[str, Style] = 'bar.back', complete_style: Union[str, Style] = 'bar.complete', finished_style: Union[str, Style] = 'bar.finished', pulse_style: Union[str, Style] = 'bar.pulse', disable: bool = False) AbstractContextManager[TextIO] [source]¶
- rich.progress.open(file: Union[str, PathLike[str], bytes], mode: typing_extensions.Literal[rb], buffering: int = -1, encoding: Optional[str] = None, errors: Optional[str] = None, newline: Optional[str] = None, *, total: Optional[int] = None, description: str = 'Reading...', auto_refresh: bool = True, console: Optional[Console] = None, transient: bool = False, get_time: Optional[Callable[[], float]] = None, refresh_per_second: float = 10, style: Union[str, Style] = 'bar.back', complete_style: Union[str, Style] = 'bar.complete', finished_style: Union[str, Style] = 'bar.finished', pulse_style: Union[str, Style] = 'bar.pulse', disable: bool = False) AbstractContextManager[BinaryIO]
ファイルからバイトを読み込みながら進捗状況を追跡します。
- パラメータ
path (Union[str, PathLike[str], BinaryIO]) – 読み込むファイルへのパス、またはバイナリモードのファイルのようなオブジェクト。
mode (str) – ファイルを開く際に使用するモード。「r」、「rb」、または「rt」のみサポート。
encoding (str, optional) – テキストモードで読み込む際に使用するエンコーディング。
io.open()
を参照。newline (str, optional) – テキストモードでの改行の処理方法。
io.open()
を参照してください。total – (int, optional): 読み込むバイトの総数。ファイルハンドルから読み込む場合は指定する必要があります。パスのデフォルト値はos.stat(file).st_sizeです。
description (str, optional) – プログレスバーの横に表示されるタスクの説明。デフォルトは「Reading」です。
auto_refresh (bool, optional) – 自動更新。各反復後に更新を強制する場合は無効にします。デフォルトはTrueです。
transient – (bool, optional): 終了時に進捗状況をクリアします。デフォルトはFalseです。
console (Console, optional) – 書き込むコンソール。デフォルトでは内部コンソールインスタンスを作成します。
refresh_per_second (float) – 進捗情報を更新する秒数あたりの回数。デフォルトは10です。
style (StyleType, オプション) – バーの背景のスタイル。デフォルトは "bar.back"。
complete_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.complete"。
finished_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.finished"。
pulse_style (StyleType, オプション) – パルスバーのスタイル。デフォルトは "bar.pulse"。
disable (bool, optional) – 進捗表示を無効にします。
encoding – テキストモードで読み込む際に使用するエンコーディング。
- 戻り値
進捗状況リーダーを返すコンテキストマネージャーです。
- 戻り値の型
ContextManager[BinaryIO]
- rich.progress.track(sequence, description='Working...', total=None, auto_refresh=True, console=None, transient=False, get_time=None, refresh_per_second=10, style='bar.back', complete_style='bar.complete', finished_style='bar.finished', pulse_style='bar.pulse', update_period=0.1, disable=False, show_speed=True)[source]¶
シーケンスを反復処理することで進捗状況を追跡します。
- パラメータ
sequence (Iterable[ProgressType]) – 反復処理するシーケンス(長さをサポートする必要があります)。
description (str, optional) – プログレスバーの横に表示するタスクの説明。デフォルトは「Working」。
total (Optional[float]) – (float, オプション): ステップの総数。デフォルトはlen(sequence)。
auto_refresh (bool, optional) – 自動更新。各反復後に更新を強制する場合は無効にします。デフォルトはTrueです。
transient (bool) – (bool, オプション): 終了時に進捗をクリアするかどうか。デフォルトはFalse。
console (Console, optional) – 書き込むコンソール。デフォルトでは内部コンソールインスタンスを作成します。
refresh_per_second (float) – 進捗情報を更新する秒数あたりの回数。デフォルトは10です。
style (StyleType, オプション) – バーの背景のスタイル。デフォルトは "bar.back"。
complete_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.complete"。
finished_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.finished"。
pulse_style (StyleType, オプション) – パルスバーのスタイル。デフォルトは "bar.pulse"。
update_period (float, オプション) – update() への呼び出し間の最小時間(秒単位)。デフォルトは 0.1。
disable (bool, optional) – 進捗表示を無効にします。
show_speed (bool, optional) – 合計数が不明な場合に速度を表示するかどうか。デフォルトはTrue。
- 戻り値
シーケンス内の値のイテラブル。
- 戻り値の型
Iterable[ProgressType]
- rich.progress.wrap_file(file, total, *, description='Reading...', auto_refresh=True, console=None, transient=False, get_time=None, refresh_per_second=10, style='bar.back', complete_style='bar.complete', finished_style='bar.finished', pulse_style='bar.pulse', disable=False)[source]¶
ファイルからバイトを読み込みながら進捗状況を追跡します。
- パラメータ
file (Union[str, PathLike[str], BinaryIO]) – 読み取るファイルへのパス、またはバイナリモードのファイルのようなオブジェクト。
total (int) – 読み取るバイト数の合計。
description (str, optional) – プログレスバーの横に表示されるタスクの説明。デフォルトは「Reading」です。
auto_refresh (bool, optional) – 自動更新。各反復後に更新を強制する場合は無効にします。デフォルトはTrueです。
transient (bool) – (bool, オプション): 終了時に進捗をクリアするかどうか。デフォルトはFalse。
console (Console, optional) – 書き込むコンソール。デフォルトでは内部コンソールインスタンスを作成します。
refresh_per_second (float) – 進捗情報を更新する秒数あたりの回数。デフォルトは10です。
style (StyleType, オプション) – バーの背景のスタイル。デフォルトは "bar.back"。
complete_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.complete"。
finished_style (StyleType, オプション) – 完了したバーのスタイル。デフォルトは "bar.finished"。
pulse_style (StyleType, オプション) – パルスバーのスタイル。デフォルトは "bar.pulse"。
disable (bool, optional) – 進捗表示を無効にします。
- 戻り値
進捗状況リーダーを返すコンテキストマネージャーです。
- 戻り値の型
ContextManager[BinaryIO]