VLArray¶
Overview¶
VLArray is a variable-length array container backed by a single Blosc2 SChunk.
Each entry is stored as one compressed chunk:
entries can be any serializable Python object
items are serialized with msgpack before compression
Blosc2 containers (
NDArray,SChunk,VLArray,BatchArray,EmbedStore) are serialized transparently viato_cframe()/blosc2.from_cframe()structured Blosc2 reference objects (
C2Array,LazyExpr, andLazyUDFbacked byblosc2.dsl_kernel()) are also supported
VLArray is a good fit when you need:
a persistent, compressed list of arbitrary Python objects
per-item random access and mutation
compact summary information via
.info
Quick example¶
import blosc2
vl = blosc2.VLArray(urlpath="example.b2z", mode="w", contiguous=True)
vl.append({"x": 1, "y": 2})
vl.append([3, 4, 5])
vl.append("hello")
print(vl[0]) # {'x': 1, 'y': 2}
print(vl[1]) # [3, 4, 5]
print(len(vl)) # 3
reopened = blosc2.open("example.b2z", mode="r")
print(type(reopened).__name__)
print(reopened.info)
- class blosc2.VLArray(chunksize: int | None = None, _from_schunk: SChunk | None = None, **kwargs: Any)[source]¶
A variable-length array backed by an
blosc2.SChunk.Entries are serialized with msgpack before compression. Standard Python objects are supported, and Blosc2 containers such as
blosc2.NDArray,blosc2.SChunk,blosc2.VLArray,blosc2.BatchArray, andblosc2.EmbedStoreare serialized transparently viato_cframe()/blosc2.from_cframe().Msgpack also supports structured Blosc2 reference objects. Currently this includes
blosc2.C2Array,blosc2.LazyExpr, andblosc2.LazyUDFbacked byblosc2.dsl_kernel(). Lazy expressions and supported lazy UDFs are serialized as recipes plus durable operand references, so only persistent local operands,blosc2.C2Arrayoperands, andblosc2.DictStoremembers are supported. Purely in-memory operands are intentionally rejected. Plain Pythonblosc2.LazyUDFcallables are not serialized by msgpack.- Attributes:
- cbytes
- chunksize
- contiguous
- cparams
- cratio
- dparams
infoPrint information about this VLArray.
info_itemsA list of tuples with summary information about this VLArray.
- meta
- nbytes
- typesize
- urlpath
- vlmeta
Methods
append(value)Append one value and return the new number of entries.
clear()Remove all entries from the container.
copy(**kwargs)Create a copy of the container with optional constructor overrides.
delete(index)Delete the value at
indexand return the new number of entries.extend(values)Append all values from an iterable.
insert(index, value)Insert one value at
indexand return the new number of entries.pop([index])Remove and return the value at
index.to_cframe
Constructors¶
Item Interface¶
Mutation¶
Context Manager¶
Public Members¶