Skip to main content

Format-agnostic exporters for vcti trees: an Exporter protocol and registry, with per-format writers as plugins.

Project description

Tree Exporter

Format-agnostic exporters for vcti trees: an Exporter protocol and a plugin catalog, with per-format writers as plugins.

vcti-tree-exporter defines what an exporter is and how to catalogue and look one up. It implements no file format itself — concrete writers (HDF5, JSON, CSV, NumPy, …) live in separate plugin packages and are registered by the consumer. The thing being exported is any vcti-tree tree whose node payloads are vcti-datanode DataNodes (data + attributes), so one tree can be written to any registered format without the producer knowing about serialization.

Cataloguing and lookup are built on vcti-plugin-catalog (Descriptor + Registry).

Installation

pip install vcti-tree-exporter

The base package is intentionally small. Install a format plugin for each format you need:

pip install vcti-tree-exporter-hdf5    # single .h5 file
pip install vcti-tree-exporter-json    # single .json document
pip install vcti-tree-exporter-npz     # single .npz archive
pip install vcti-tree-exporter-csv     # directory tree of CSV tables

Core concepts

Piece Role
Exporter Structural protocol — a single export(tree, path, *, overwrite=False) method. Pure behavior; format name and extension are not on the exporter.
ExporterDescriptor A vcti-plugin-catalog Descriptor[Exporter]: the exporter is its instance; format, extension, and any other metadata are filterable attributes.
get_exporter_descriptor() Factory each plugin package provides, returning its ExporterDescriptor.
build_registry(descriptors) Build a plugin-catalog Registry from those descriptors.
get_exporter(registry, id) Resolve an exporter instance by descriptor id.

Quick Start

Register the descriptors your application uses, then resolve one and write a tree:

from pathlib import Path
from vcti.treeexporter import build_registry, get_exporter
from vcti.treeexporter_hdf5 import get_exporter_descriptor as hdf5_descriptor
from vcti.treeexporter_json import get_exporter_descriptor as json_descriptor

registry = build_registry([hdf5_descriptor(), json_descriptor()])
get_exporter(registry, "hdf5").export(tree, Path("model.h5"), overwrite=True)

registry is an ordinary vcti.plugincatalog.Registry, so the general way to select an exporter is to filter by attributes, then use the matching id — the same pattern as the rest of the ecosystem:

from vcti.lookup import Rule
from vcti.treeexporter import EXTENSION_ATTR

(desc,) = registry.lookup.filter([Rule(EXTENSION_ATTR, "==", ".h5")])
desc.exporter.export(tree, Path("model.h5"))

Exporter ids are a small, fixed, well-known set, so using get_exporter(registry, "hdf5") directly is also fine.

Writing a format plugin

A plugin's exporter only has to satisfy the protocol — one export method, no base class — and ship a get_exporter_descriptor() factory carrying its metadata:

from pathlib import Path
from vcti.treeexporter import EXTENSION_ATTR, FORMAT_ATTR, ExporterDescriptor

class JsonExporter:
    def export(self, tree, path: Path, *, overwrite: bool = False) -> None:
        ...   # walk the tree (node.name, node.attributes, node.load()), write JSON

def get_exporter_descriptor() -> ExporterDescriptor:
    return ExporterDescriptor(
        id="json", name="JSON Exporter", exporter=JsonExporter(),
        attributes={FORMAT_ATTR: "json", EXTENSION_ATTR: ".json"},
    )

Ship it in its own package (with its own format dependencies, e.g. h5py for HDF5). The consuming application decides which descriptors to register — there is no implicit global discovery.

Dependencies

(No heavy/runtime format dependencies live here — those belong to the per-format plugin packages.)

Project details


Download files

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

Source Distribution

vcti_tree_exporter-1.0.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

vcti_tree_exporter-1.0.0-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file vcti_tree_exporter-1.0.0.tar.gz.

File metadata

  • Download URL: vcti_tree_exporter-1.0.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for vcti_tree_exporter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8553c72693e16bbc7c23780304b72544232cd4399d5f437d6398c7f3dd3a3d91
MD5 7d846262d29f8bcc8cd24a8873c05cde
BLAKE2b-256 061e47ecfee99c987a8d49d3a8338fc1d34807aa27d3499cc96fc05877857eb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_tree_exporter-1.0.0.tar.gz:

Publisher: release.yml on vcollab/vcti-python-tree-exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vcti_tree_exporter-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for vcti_tree_exporter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2837a9145f05a5e3c0193f67b744e35e64790b7138445ddb5aa059a17f27a21
MD5 38935fed9336e4e1b454db6ebf39c2cd
BLAKE2b-256 949a787db6ac434b1bc1a3eef3fecf08a21264bc8d2d942d7ad57c289e02f231

See more details on using hashes here.

Provenance

The following attestation bundles were made for vcti_tree_exporter-1.0.0-py3-none-any.whl:

Publisher: release.yml on vcollab/vcti-python-tree-exporter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page