Ref¶
Overview¶
Ref is a small durable reference object for locating reopenable Blosc2
objects without embedding their full value.
Currently supported reference kinds are:
"urlpath"for persistent local objects"dictstore_key"for members inside.b2d/.b2zDictStorecontainers"c2array"for remoteC2Arrayobjects
Use Ref.open() to resolve a reference back into a live object.
Example¶
import tempfile
from pathlib import Path
import blosc2
with tempfile.TemporaryDirectory() as tmpdir:
array_path = Path(tmpdir) / "array.b2nd"
catalog_path = Path(tmpdir) / "catalog.b2nd"
# References are durable only for persistent objects.
arr = blosc2.arange(5, urlpath=array_path, mode="w")
ref = blosc2.Ref.from_object(arr)
# A Ref can itself be persisted, for example as variable-length metadata
# in another persistent Blosc2 object.
catalog = blosc2.zeros(1, urlpath=catalog_path, mode="w")
catalog.schunk.vlmeta["array_ref"] = ref
# Reopen the metadata holder and resolve the persisted reference.
catalog = blosc2.open(catalog_path, mode="r")
restored_ref = catalog.schunk.vlmeta["array_ref"]
reopened = restored_ref.open()
print(reopened[:]) # [0 1 2 3 4]
- class blosc2.Ref(kind: str, urlpath: str | None = None, key: str | None = None, path: str | None = None, urlbase: str | None = None)[source]¶
A durable reference to a Blosc2 object.
Refcan describe:a persistent local Blosc2 object reopenable from
urlpatha member inside a
blosc2.DictStorea remote
blosc2.C2Array
Instances can be created directly, from dictionaries via
from_dict(), or from supported objects viafrom_object(). Useopen()to resolve the reference back into a live Blosc2 object.- Attributes:
- key
- kind
- path
- urlbase
- urlpath
Methods
c2array_ref
dictstore_key
from_dict
from_object
open
to_dict
urlpath_ref