ParallelStorage

モジュール概要

Parallel storage and multipart upload.

チュートリアル

最初に以下の最小例でモジュール利用方法を確認し、その後 API リファレンスを参照してください。

from nexom.app.parallel_storage import ParallelStorage

ps = ParallelStorage(
    db_file='data/db/storage.db',
    contents_dir='data/contents',
    working_dir='data/work',
)
meta = ps.getMeta(public_id='PUBLIC_ID')

運用チェックリスト

  • 本番では例外処理を必ず実装し、戻り値の型を固定してください。
  • 引数のデフォルト値と必須/任意を仕様書としてチーム内で固定してください。
  • ログと監視を追加し、エラー時の復旧手順を運用Runbookに記載してください。

API リファレンス(全関数・全メソッド)

モジュール関数

_FileStatusTypesCheck

分類: internal function

シグネチャ

_FileStatusTypesCheck(status: FileStatus) -> None

使い方と仕様

実装コード由来のAPIです。

引数

  • status / kind=positional-or-keyword / type=FileStatus / 必須 / default=なし

戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例

from nexom.app.parallel_storage import _FileStatusTypesCheck

result = _FileStatusTypesCheck(status=...)
print(result)

_rand

分類: internal function

シグネチャ

_rand(nbytes: int = 24) -> str

使い方と仕様

実装コード由来のAPIです。

引数

  • nbytes / kind=positional-or-keyword / type=int / 任意 / default=24

戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例

from nexom.app.parallel_storage import _rand

result = _rand(nbytes=24)
print(result)

_sha256_hex_file

分類: internal function

シグネチャ

_sha256_hex_file(path: Path) -> str

使い方と仕様

実装コード由来のAPIです。

引数

  • path / kind=positional-or-keyword / type=Path / 必須 / default=なし

戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例

from nexom.app.parallel_storage import _sha256_hex_file

result = _sha256_hex_file(path="/path/to/value")
print(result)

_detect_file_type

分類: internal function

シグネチャ

_detect_file_type(path: Path, filename: str) -> FileTypes

使い方と仕様

Detect a FileTypes value from content and filename. Priority: - image content -> Images - media mime (audio/video) -> Media - document mime (text/application) -> Documents - dangerous extensions -> Dangerous - fallback -> Binary

引数

  • path / kind=positional-or-keyword / type=Path / 必須 / default=なし
  • filename / kind=positional-or-keyword / type=str / 必須 / default=なし

戻り値

FileTypes

例外・注意点

実装コード内の例外仕様を確認してください。

利用例

from nexom.app.parallel_storage import _detect_file_type

result = _detect_file_type(path="/path/to/value", filename="sample")
print(result)

format_psc_filename

分類: public function

シグネチャ

format_psc_filename(contents_id: str, suffix: str, **kwargs) -> str

使い方と仕様

Build a PSC filename for X-Accel-Redirect. Format: <contents_id>__PSC_arg1-000_arg2-111<suffix> kwargs are sorted alphabetically by key.

引数

  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • suffix / kind=positional-or-keyword / type=str / 必須 / default=なし
  • kwargs / kind=variadic-keyword(**kwargs) / type=型指定なし / 必須 / default=なし

戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例

from nexom.app.parallel_storage import format_psc_filename

result = format_psc_filename(contents_id="sample", suffix="sample")
print(result)

クラス

FileMeta

分類: public class

Immutable metadata for a stored file.

FileMeta の全メソッド

isTypes

分類: public method

シグネチャ
isTypes(self, types: FileTypes) -> bool
使い方と仕様

Return True if the stored type matches the given FileTypes value.

引数
  • types / kind=positional-or-keyword / type=FileTypes / 必須 / default=なし
戻り値

bool

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import FileMeta

obj = FileMeta(...)
result = obj.isTypes(types=...)
print(result)

ParallelStorage

分類: public class

Convenience wrapper around ParallelStorageDBM for public APIs. Provides PSC path formatting, status updates, and image compression helpers.

ParallelStorage の全メソッド

__init__

分類: special method

シグネチャ
__init__(self, db_file: str, contents_dir: str, working_dir: str | None = None) -> None
使い方と仕様

メソッドドキュメントは未定義です。

引数
  • db_file / kind=positional-or-keyword / type=str / 必須 / default=なし
  • contents_dir / kind=positional-or-keyword / type=str / 必須 / default=なし
  • working_dir / kind=positional-or-keyword / type=str | None / 任意 / default=None
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(db_file="sample", contents_dir="sample", working_dir=None)
format_psc_public_id

分類: public method

シグネチャ
format_psc_public_id(self, public_id: str, **kwargs) -> Path
使い方と仕様

Return the resolved PSC file path for a public_id. kwargs are embedded in the PSC filename format.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • kwargs / kind=variadic-keyword(**kwargs) / type=型指定なし / 必須 / default=なし
戻り値

Path

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.format_psc_public_id(public_id="sample")
print(result)
comp_img

分類: public method

シグネチャ
comp_img(self, public_id: str, width: int | None, height: int | None, quality: int | None) -> Path
使い方と仕様

Generate a WebP image variant and return its path. The source must be an image, and output is saved under contents_dir.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • width / kind=positional-or-keyword / type=int | None / 必須 / default=なし
  • height / kind=positional-or-keyword / type=int | None / 必須 / default=なし
  • quality / kind=positional-or-keyword / type=int | None / 必須 / default=なし
戻り値

Path

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.comp_img(public_id="sample", width=1, height=1, quality=1)
print(result)
update_suffix

分類: public method

シグネチャ
update_suffix(self, public_id: str, suffix: str) -> None
使い方と仕様

Update stored file suffix for a public_id.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • suffix / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.update_suffix(public_id="sample", suffix="sample")
print(result)
update_status

分類: public method

シグネチャ
update_status(self, public_id: str, status: FileStatus) -> None
使い方と仕様

Update stored status for a public_id.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • status / kind=positional-or-keyword / type=FileStatus / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.update_status(public_id="sample", status=...)
print(result)
getMeta

分類: public method

シグネチャ
getMeta(self, public_id: str) -> FileMeta
使い方と仕様

Get FileMeta

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

FileMeta

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.getMeta(public_id="sample")
print(result)
delete

分類: public method

シグネチャ
delete(self, pid: str, public_id: str, *, force: bool = False) -> None
使い方と仕様

Delete a content record and related files. Targets: - DB record in parallel_storage - content files in contents_dir matching "<contents_id>__PSC_*" - worker directory "<working_dir>/<public_id>" when working_dir is configured

引数
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • force / kind=keyword-only / type=bool / 任意 / default=False
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorage

obj = ParallelStorage(...)
result = obj.delete(pid="sample", public_id="sample", force=False)
print(result)

ParallelStorageDBM

分類: public class

Database manager for the parallel_storage table.

ParallelStorageDBM の全メソッド

__init__

分類: special method

シグネチャ
__init__(self, db_file: str)
使い方と仕様

メソッドドキュメントは未定義です。

引数
  • db_file / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

型指定なし

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(db_file="sample")
_init

分類: internal method

シグネチャ
_init(self)
使い方と仕様

Create storage table if it does not exist.

引数
  • 引数なし
戻り値

型指定なし

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj._init()
print(result)
_insert

分類: internal method

シグネチャ
_insert(self, *, contents_id: str, public_id: str, size: int, pid: str, filename: str, suffix: str, permission_id: str | None)
使い方と仕様

Insert a new storage record.

引数
  • contents_id / kind=keyword-only / type=str / 必須 / default=なし
  • public_id / kind=keyword-only / type=str / 必須 / default=なし
  • size / kind=keyword-only / type=int / 必須 / default=なし
  • pid / kind=keyword-only / type=str / 必須 / default=なし
  • filename / kind=keyword-only / type=str / 必須 / default=なし
  • suffix / kind=keyword-only / type=str / 必須 / default=なし
  • permission_id / kind=keyword-only / type=str | None / 必須 / default=なし
戻り値

型指定なし

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj._insert(contents_id="sample", public_id="sample", size=1, pid="sample", filename="sample", suffix="sample", permission_id="sample")
print(result)
_get_by_public_id

分類: internal method

シグネチャ
_get_by_public_id(self, public_id: str) -> tuple
使い方と仕様

Fetch record by public_id or raise.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

tuple

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj._get_by_public_id(public_id="sample")
print(result)
_get_by_contents_id

分類: internal method

シグネチャ
_get_by_contents_id(self, contents_id: str) -> tuple
使い方と仕様

Fetch record by contents_id or raise.

引数
  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

tuple

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj._get_by_contents_id(contents_id="sample")
print(result)
register

分類: public method

シグネチャ
register(self, filename: str, suffix: str, size: int, pid: str, permission_id: str | None = None) -> str
使い方と仕様

Insert a new record and return public_id.

引数
  • filename / kind=positional-or-keyword / type=str / 必須 / default=なし
  • suffix / kind=positional-or-keyword / type=str / 必須 / default=なし
  • size / kind=positional-or-keyword / type=int / 必須 / default=なし
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • permission_id / kind=positional-or-keyword / type=str | None / 任意 / default=None
戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.register(filename="sample", suffix="sample", size=1, pid="sample", permission_id=None)
print(result)
status_change

分類: public method

シグネチャ
status_change(self, contents_id: str, status: FileStatus) -> None
使い方と仕様

Update status for contents_id.

引数
  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • status / kind=positional-or-keyword / type=FileStatus / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.status_change(contents_id="sample", status=...)
print(result)
update_public_id

分類: public method

シグネチャ
update_public_id(self, contents_id: str) -> None
使い方と仕様

Regenerate public_id for contents_id.

引数
  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.update_public_id(contents_id="sample")
print(result)
update_types

分類: public method

シグネチャ
update_types(self, contents_id: str, types: FileTypes) -> None
使い方と仕様

Update file type for contents_id.

引数
  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • types / kind=positional-or-keyword / type=FileTypes / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.update_types(contents_id="sample", types=...)
print(result)
update_suffix

分類: public method

シグネチャ
update_suffix(self, contents_id: str, suffix: str) -> None
使い方と仕様

Update suffix for contents_id.

引数
  • contents_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • suffix / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.update_suffix(contents_id="sample", suffix="sample")
print(result)
remove

分類: public method

シグネチャ
remove(self, pid: str | None, *, contents_id: str | None = None, public_id: str | None = None) -> None
使い方と仕様

Delete a record by contents_id or public_id.

引数
  • pid / kind=positional-or-keyword / type=str | None / 必須 / default=なし
  • contents_id / kind=keyword-only / type=str | None / 任意 / default=None
  • public_id / kind=keyword-only / type=str | None / 任意 / default=None
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.remove(pid="sample", contents_id=None, public_id=None)
print(result)
getMeta

分類: public method

シグネチャ
getMeta(self, *, contents_id: str | None = None, public_id: str | None = None) -> FileMeta
使い方と仕様

Return FileMeta for contents_id or public_id.

引数
  • contents_id / kind=keyword-only / type=str | None / 任意 / default=None
  • public_id / kind=keyword-only / type=str | None / 任意 / default=None
戻り値

FileMeta

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.getMeta(contents_id=None, public_id=None)
print(result)
commit

分類: public method

シグネチャ
commit(self) -> None
使い方と仕様

メソッドドキュメントは未定義です。

引数
  • 引数なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import ParallelStorageDBM

obj = ParallelStorageDBM(...)
result = obj.commit()
print(result)

UploadMeta

分類: public class

Metadata for a multipart upload session.

UploadMeta の全メソッド

toJson

分類: public method

シグネチャ
toJson(self) -> str
使い方と仕様

Serialize to JSON string.

引数
  • 引数なし
戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import UploadMeta

obj = UploadMeta(...)
result = obj.toJson()
print(result)
readJson

分類: public method

シグネチャ
readJson(path: Path) -> 'UploadMeta'
使い方と仕様

Read UploadMeta from a JSON file.

引数
  • path / kind=positional-or-keyword / type=Path / 必須 / default=なし
戻り値

'UploadMeta'

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import UploadMeta

obj = UploadMeta(...)
result = obj.readJson(path="/path/to/value")
print(result)

MultiPartUploader

分類: public class

Multipart upload workflow with chunk verification and commit. Uses ParallelStorageDBM for metadata and stores chunks under working_root.

MultiPartUploader の全メソッド

__init__

分類: special method

シグネチャ
__init__(self, db_file: str, working_dir: str, contents_dir: str)
使い方と仕様

メソッドドキュメントは未定義です。

引数
  • db_file / kind=positional-or-keyword / type=str / 必須 / default=なし
  • working_dir / kind=positional-or-keyword / type=str / 必須 / default=なし
  • contents_dir / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

型指定なし

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(db_file="sample", working_dir="sample", contents_dir="sample")
_getUploadMeta

分類: internal method

シグネチャ
_getUploadMeta(self, public_id: str) -> UploadMeta
使い方と仕様

Load UploadMeta for a public_id.

引数
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

UploadMeta

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(...)
result = obj._getUploadMeta(public_id="sample")
print(result)
_failed

分類: internal method

シグネチャ
_failed(self, pid: str, public_id: str) -> None
使い方と仕様

Cleanup a failed upload.

引数
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(...)
result = obj._failed(pid="sample", public_id="sample")
print(result)
register

分類: public method

シグネチャ
register(self, filename: str, size: int, pid: str, permission_id: str | None, total_chunks: int, sha256: str) -> str
使い方と仕様

Register an upload and return public_id.

引数
  • filename / kind=positional-or-keyword / type=str / 必須 / default=なし
  • size / kind=positional-or-keyword / type=int / 必須 / default=なし
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • permission_id / kind=positional-or-keyword / type=str | None / 必須 / default=なし
  • total_chunks / kind=positional-or-keyword / type=int / 必須 / default=なし
  • sha256 / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

str

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(...)
result = obj.register(filename="sample", size=1, pid="sample", permission_id="sample", total_chunks=1, sha256="sample")
print(result)
parts_upload

分類: public method

シグネチャ
parts_upload(self, pid: str, public_id: str, count: int, blob: bytes, sha256: str) -> None
使い方と仕様

Upload a single chunk and verify its checksum.

引数
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
  • count / kind=positional-or-keyword / type=int / 必須 / default=なし
  • blob / kind=positional-or-keyword / type=bytes / 必須 / default=なし
  • sha256 / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

None

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(...)
result = obj.parts_upload(pid="sample", public_id="sample", count=1, blob=..., sha256="sample")
print(result)
commit

分類: public method

シグネチャ
commit(self, pid: str, public_id: str) -> FileMeta
使い方と仕様

Assemble chunks, validate checksum/size, and move to contents.

引数
  • pid / kind=positional-or-keyword / type=str / 必須 / default=なし
  • public_id / kind=positional-or-keyword / type=str / 必須 / default=なし
戻り値

FileMeta

例外・注意点

実装コード内の例外仕様を確認してください。

利用例
from nexom.app.parallel_storage import MultiPartUploader

obj = MultiPartUploader(...)
result = obj.commit(pid="sample", public_id="sample")
print(result)

ソース情報

  • module: nexom.app.parallel_storage
  • source file: services/venv/lib/python3.10/site-packages/nexom/app/parallel_storage.py
  • generated date: 2026-03-14