hoops_ai.storage.convert_storage
- hoops_ai.storage.convert_storage(source_handler, dest_handler, verbose=False)
Generic converter that works with ANY DataStorage implementation.
This universal converter supports all storage types including: - OptStorage / ZarrStorage - Compressed binary format - JsonStorageHandler - Human-readable JSON format - MemoryStorage - In-memory storage (no files) - Custom implementations - Any class inheriting from DataStorage
The converter uses only the base DataStorage interface methods: - get_keys() or load_metadata() to discover data keys - load_data() to read data arrays - save_data() to write data arrays - save_metadata() to copy metadata
This makes it completely storage-agnostic and extensible.
Common Use Cases: - OptStorage → JSON: Decompress for inspection/debugging - JSON → OptStorage: Compress for performance/storage - MemoryStorage → OptStorage: Persist in-memory data to disk - OptStorage → MemoryStorage: Load encoded data for ML training
- Parameters:
source_handler (DataStorage) – Source storage to read from (any type).
dest_handler (DataStorage) – Destination storage to write to (any type).
verbose (bool) – Print progress messages. Default False.
- Returns:
None
- Raises:
RuntimeError – If no data keys found or conversion fails.
- Return type:
None
Examples
>>> # OptStorage → JSON (decompression) >>> opt = OptStorage("flows/data_mining/abc123") >>> json_storage = JsonStorageHandler("flows/json/abc123") >>> convert_storage(opt, json_storage)
>>> # MemoryStorage → OptStorage (persist to disk) >>> mem = MemoryStorage() >>> mem.save_data("faces/positions", np.array([[0,0,0], [1,1,1]])) >>> opt = OptStorage("output/saved_data") >>> convert_storage(mem, opt)
>>> # JSON → MemoryStorage (load for processing) >>> json_storage = JsonStorageHandler("data/abc123") >>> mem = MemoryStorage() >>> convert_storage(json_storage, mem)