Readers#
PyVista provides class based readers to have more control over reading
data files. These classes allows for more fine-grained control over
reading datasets from files. See pyvista.get_reader() for a
list of file types supported.
Also, see Load data using a Reader for a full example using reader classes.
|
Get a reader for fine-grained control of reading data files. |
Reader Classes#
|
AVSucdReader for .inp files. |
|
BMP Reader for .bmp files. |
|
BYU Reader for .g files. |
|
BinaryMarchingCubes Reader for .tri files. |
|
CGNS Reader for .cgns files. |
|
DEM Reader for .dem files. |
|
DICOM Reader for reading |
|
EnSight Reader for .case files. |
|
Class for enabling and disabling blocks, sets, and block/set arrays in Exodus II files. |
|
ExodusIIReader for .e and .exo files. |
|
Facet Reader for .facet files. |
|
FLUENTCFFReader for .h5 files. |
|
FluentReader for .cas files. |
|
Reader for CalculiX FRD ASCII result files ( |
|
GambitReader for .neu files. |
|
GaussianCubeReader for .cube files. |
|
GESignaReader for .MR files. |
|
GIFReader for .gif files. |
|
GLTFeader for .gltf and .glb files. |
|
HDFReader for .hdf files. |
|
HDRReader for .hdr files. |
|
JPEG Reader for .jpeg and .jpg files. |
|
MFIXReader for .res files. |
|
Meta Image Reader for .mha and .mhd files. |
|
MINCImageReader for .mnc files. |
|
MultiBlock Plot3D Reader. |
|
Class for reading .nek5000 files produced by Nek5000 and NekRS. |
|
NIFTI Reader for .nii and .nii.gz files. |
|
NRRDReader for .nrrd and .nhdr files. |
|
OBJ Reader for reading .obj files. |
|
OpenFOAM Reader for .foam files. |
|
ParticleReader for .raw files. |
|
PDBReader for .pdb files. |
|
PLY Reader for reading .ply files. |
|
PNGReader for .png files. |
|
PNMReader for .pnm files. |
|
Parallel OpenFOAM Reader for .foam files. |
|
PTSReader for .pts files. |
|
PVD Reader for .pvd files. |
|
Plot3DMeta Reader for .p3d files. |
|
ProStarReader for .vrt files. |
|
SLCReader for .slc files. |
|
STL Reader for .stl files. |
|
SegYReader for .sgy and .segy files. |
|
Class for reading .series file supported by Paraview. |
|
TIFFReader for .tif and .tiff files. |
|
Tecplot Reader for ascii .dat files. |
|
VTK Data Set Reader for .vtk files. |
|
Parallel VTK Data Set Reader for .pvtk files. |
|
XML Image Data Reader for .vti files. |
|
XML MultiBlock Data Reader for .vtm or .vtmb files. |
|
Parallel XML Image Data Reader for .pvti files. |
|
Parallel XML RectilinearGrid Reader for .pvtr files. |
|
Parallel XML UnstructuredGrid Reader for .pvtu files. |
|
XML PartitionedDataSet Reader for reading .vtpd files. |
|
XML PolyData Reader for .vtp files. |
|
XML RectilinearGrid Reader for .vtr files. |
|
XML StructuredGrid Reader for .vts files. |
|
XML UnstructuredGrid Reader for .vtu files. |
|
XdmfReader for .xdmf files. |
Custom Readers#
Third-party packages can register custom readers so that
pyvista.read() handles additional file formats automatically.
Registration can be done programmatically or via Python entry points
for zero-config discovery at install time.
- register_reader( ) Callable[[ReaderHandler], ReaderHandler] | None[source]#
Register a custom reader for a file extension.
Can be used as a plain call or as a decorator.
Added in version 0.48.0.
- Parameters:
- key
str A file extension (e.g.
'.myformat').- handler
callable(),optional A callable with signature
handler(path: str, **kwargs)that returns apyvista.DataSet. When omitted the function acts as a decorator and returns the decorated callable unchanged.- overridebool, default:
False If
True, allow overriding a built-in VTK reader for this extension. WhenFalse(the default), registering a handler for an extension that collides with a built-in reader raisesValueError.
- key
- Returns:
callable()orNoneWhen used as a decorator (
handleromitted), returns the decorated function. Otherwise returnsNone.
- Raises:
ValueErrorIf
keycollides with a built-in VTK reader and override isFalse.
See also
pyvista.register_writerSibling API for registering custom writers.
Examples
Register a reader for a custom file extension.
>>> import pyvista as pv >>> def my_reader(path, **kwargs): ... >>> pv.register_reader('.myformat', my_reader)
Use as a decorator.
>>> @pv.register_reader('.myformat') ... def my_reader(path, **kwargs): ...
Entry points
Packages can also register readers in pyproject.toml so they are
discovered automatically when installed:
[project.entry-points."pyvista.readers"]
".myformat" = "my_package:read_my_format"
Remote URI support
When pyvista.read() is given a remote URI (https://,
s3://, etc.) and a custom reader is registered for the file
extension, the URI is passed directly to the reader. If the reader
raises LocalFileRequiredError, PyVista downloads
the file to a temporary local path and retries. For built-in
formats with no custom reader, the download happens automatically.
This uses fsspec when available (install with
pip install pyvista[io]), falling back to pooch for HTTP(S)
URIs.
- class LocalFileRequiredError[source]#
Raise from a registered reader to signal it needs a local file path.
When
pyvista.read()passes a remote URI to a custom reader and the reader raises this exception, PyVista will download the file to a temporary local path and retry the reader automatically.Examples
>>> import pyvista as pv >>> from pyvista.core.utilities.reader_registry import LocalFileRequiredError >>> @pv.register_reader('.myformat') ... def my_reader(path, **kwargs): ... if '://' in path: ... raise LocalFileRequiredError ... ...
Custom Writers#
Third-party packages can register custom writers so that
pyvista.DataObject.save() handles additional file formats
automatically. Registration mirrors pyvista.register_reader()
and supports programmatic calls, decorators, and Python entry points
for zero-config discovery at install time.
- register_writer( ) Callable[[WriterHandler], WriterHandler] | None[source]#
Register a custom writer for a file extension.
Can be used as a plain call or as a decorator.
Added in version 0.48.0.
- Parameters:
- key
str A file extension (e.g.
'.myformat').- handler
callable(),optional A callable with signature
handler(dataset, path, **kwargs)that writes dataset to path. Any extra keyword arguments passed topyvista.DataObject.save()are forwarded to the handler as**kwargs— use them to expose format-specific options such as compression level, thread count, or chunking. Handlers that do not need per-call options can omit**kwargs; a call tosave()that passes extras to such a handler will raiseTypeErrorfrom Python itself. Whenhandleris omitted the function acts as a decorator and returns the decorated callable unchanged.- overridebool, default:
False If
True, allow overriding a built-in PyVista writer for this extension. WhenFalse(the default), registering a handler for an extension that collides with a built-in writer raisesValueError.
- key
- Returns:
callable()orNoneWhen used as a decorator (
handleromitted), returns the decorated function. Otherwise returnsNone.
- Raises:
ValueErrorIf
keycollides with a built-in PyVista writer and override isFalse.
See also
pyvista.register_readerSibling API for registering custom readers.
Notes
When
pyvista.DataObject.save()is called, registered custom writers are dispatched before built-in VTK writers — mirroring the dispatch order ofpyvista.read(). Passingoverride=Trueis therefore the only way to replace a built-in writer at save time.Any keyword arguments passed to
save()beyond its documented parameters are forwarded verbatim to the registered handler. When no custom writer is registered for the target extension, extra keyword arguments raiseTypeErrorfromsave()— PyVista never silently drops writer options.Examples
Register a writer for a custom file extension with a format-specific option.
>>> import pyvista as pv >>> def my_writer(dataset, path, *, level=3): ... >>> pv.register_writer('.myformat', my_writer) >>> pv.Sphere().save('sphere.myformat', level=9)
Use as a decorator.
>>> @pv.register_writer('.myformat') ... def my_writer(dataset, path, **kwargs): ...
Handler signature
A writer handler is a callable handler(dataset, path, **kwargs)
that writes dataset to path. Any extra keyword arguments passed
to pyvista.DataObject.save() beyond its documented parameters
are forwarded verbatim to the handler as **kwargs. Use them to
expose format-specific options such as compression level, thread
count, or chunking. When no custom writer is registered for the
target extension, passing extra keyword arguments to
save() raises TypeError; PyVista
never silently drops writer options.
Entry points
Packages can register writers in pyproject.toml so they are
discovered automatically when installed:
[project.entry-points."pyvista.writers"]
".myformat" = "my_package:write_my_format"
Dispatch order
When save() is called, custom writers
registered via pyvista.register_writer() are dispatched before
built-in VTK writers for the same extension, mirroring the dispatch
order used by pyvista.read(). By default, registering a
handler for an extension that collides with a built-in PyVista writer
raises ValueError; pass override=True to replace the
built-in writer.
The .pv Format: PyVista’s Native Binary Format#
PyVista has a native zstd-compressed binary format with the
.pv extension, implemented by the
pyvista-zstd companion
package. It is a compact, multi-threaded format for fast dataset
I/O and is included in the io extra:
pip install pyvista[io]
Once installed, .pv round-trips “just work” via the
pyvista.readers and pyvista.writers entry-point hooks
without any manual registration:
import pyvista as pv
mesh = pv.Sphere()
mesh.save('sphere.pv')
pv.read('sphere.pv')
Supported dataset types include ImageData,
PolyData, StructuredGrid,
RectilinearGrid, UnstructuredGrid,
MultiBlock, and
ExplicitStructuredGrid. The format uses zstd
compression with multi-threaded encode/decode and is a good choice
over .vtu / .vtp / .vtm when file size or I/O latency
matters.
Inherited Classes#
The pyvista.BaseReader is inherited by all sub-readers. It
has the basic functionality of all readers to set filename and read
the data.
The PointCellDataSelection is inherited by readers that
support inspecting and setting data related to point and cell arrays.
The TimeReader is inherited by readers that support inspecting
and setting time or iterations for reading.
|
The Base Reader class. |
|
Mixin for readers that support data array selections. |
Abstract class for readers supporting time. |
Enumerations#
Enumerations are available to simplify inputs to certain readers.