Skip to main content

otsutil

よく使う関数やクラスを纏めたライブラリです。

このライブラリは以下の環境で作成・最適化されています。 Windows10/11, Python 3.12.0+

インストール

インストール pip install otsutil

アップデート pip install -U otsutil

アンインストール pip uninstall otsutil

モジュール

以下のモジュールが存在します。

モジュール名 概要
cfg 定数
classes スレッドセーフなコンテナやタイマーなどのクラス定義
exceptions 例外
funcs ファイル操作や型判定などの便利な関数定義
types パッケージ全体で共通利用する型ヒント・ジェネリクス共通定義

cfgモジュール

cfgモジュールでは以下の定数が定義されています。

定数名 概要
JST 日本のタイムゾーン。

classesモジュール

classesモジュールでは以下のクラスが定義されています。

クラス名 概要
LockableDict 要素の操作時に threading.RLock を使用するスレッドセーフな dict クラス。
with obj: 構文によるコンテキストマネージャに対応し、複数の操作をアトミックに実行可能です。
LockableList 要素の操作時に threading.RLock を使用するスレッドセーフな list クラス。
with obj: 構文によるコンテキストマネージャに対応し、複数の操作をアトミックに実行可能です。
ObjectStore オブジェクトを pickle + base64 でシリアライズし、ファイルに永続化・管理するクラス。
カスタムクラスを保存する場合、そのクラスに __reduce__ を実装することでリスト内の要素なども含め高度な変換・復元が可能です。
OtsuNone None を返す可能性のある辞書の get デフォルト値などに使用するセンチネルオブジェクト。
bool() 判定では False を返します。
Timer 指定時間の経過判定および待機を行うタイマー。
同期的なブロック待機 (join) に加え、asyncio による非同期待機 (ajoin) をサポート。
for / async for 文で残り時間を yield しながら処理を行うイテレータ機能を持ちます。

exceptionsモジュール

exceptionsモジュールでは以下の定数が定義されています。

| 例外名 | 概要 | | PathError | パスに関連するエラー | | PathTypeError | パスの形式に関連するエラー |


funcsモジュール

funcsモジュールでは以下の関数が定義されています。

関数名 概要
deduplicate シーケンスから重複を取り除き、順序を保持したまま元の型(list/tuple)で返す。
get_sub_paths ディレクトリ内を探索し、ワイルドカードや拡張子による高度なフィルタリングを適用して子パスを一覧取得する。
is_all_type 反復可能オブジェクトの全ての要素が、指定した型であるか判定する。
is_dict_key_type dict[K, Any]か検証する。
is_dict_type dict[K, V]か検証する。
is_dict_value_type dict[K, V]か検証する。
is_type オブジェクトが指定した型であるか判定する(None 許容判定などを含む)。
iter_sub_paths get_sub_pathsのイテレータ版。
load_json JSON ファイルを読み込む。親ディレクトリがない場合は作成し、ファイルがない場合はデフォルト値を返します。
read_lines ファイルを1行ずつ読み出すジェネレータ。改行コードの自動除去やエンコーディング指定が可能です。
same_path 2つのパスが(相対/絶対に関わらず)物理的に同じ場所を指しているか判定する。
save_json オブジェクトを JSON 形式で保存する。
setup_path パスを Path オブジェクトとして整備し、必要に応じて親ディレクトリを生成して利用可能な状態にする。
str_to_path 文字列を pathlib.Path に変換する。
write_lines 反復可能な文字列データを1行ずつファイルに書き出す。

typesモジュール

typesモジュールでは、Python 3.12 のジェネリクス構文に対応した以下の型定義がされています。

名称 概要
ExpectType[T] isinstance(obj, ExpectType)で使用できる型。
FloatInt float または int に限定した数値型。
HMSTuple (時, 分, 秒) のタプル。型は (int, int, float)
OptPath pathlib.Path またはNone
OptStrPath pathlib.PathまたはstrまたはNone
StrPath pathlib.Path または str

Download files

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

Source Distribution

otsutil-1.3.2.312.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

otsutil-1.3.2.312-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file otsutil-1.3.2.312.tar.gz.

File metadata

  • Download URL: otsutil-1.3.2.312.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for otsutil-1.3.2.312.tar.gz
Algorithm Hash digest
SHA256 af15e0d14c88200affe06ba6b281a9470fa3e60c59db848978f8b87e472508b1
MD5 16970ee2eb52987690d405489cf94cce
BLAKE2b-256 d0bd79732b5e13bbdaed3a3217d6e3193d79edd34f14752e0b76ba3b185bc04a

See more details on using hashes here.

File details

Details for the file otsutil-1.3.2.312-py3-none-any.whl.

File metadata

  • Download URL: otsutil-1.3.2.312-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.10

File hashes

Hashes for otsutil-1.3.2.312-py3-none-any.whl
Algorithm Hash digest
SHA256 47ef4079eb511f6c8e851dbb2de5e16413494dffdf35d24e62a08806ea2d95b2
MD5 7689964c64c3c814337eb07fd8f09fde
BLAKE2b-256 327e188e303d13a163416beae55d2856138bfdf280ec48546f9b8e2b24ba21ab

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.3.2.312 This release

2 files

1.3.1.312

2 files

1.3.0.312

2 files

1.2.3.312

2 files

1.2.2.310

1 file

1.2.1.310

1 file

1.2.0.310

1 file

1.1.2.310

1 file

1.1.1.310

1 file

1.1.0.310

1 file

1.0.4.310

2 files

1.0.4.37

2 files

1.0.3.310

2 files

1.0.1.310

2 files

1.0.1.37

2 files

1.0.1

2 files

1.0.0

2 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