DataObject.save

DataObject.save#

DataObject.save(
filename: Path | str,
*,
binary: bool = True,
texture: NDArray[np.uint8] | str | None = None,
compression: _CompressionOptions = 'zlib',
**writer_kwargs: Any,
) → None[source]#

Save this vtk object to file.

Note

Reading a file and saving it in another format is also available via command-line interface. See pyvista convert for details.

Tip

A native .pv binary format with zstd compression is available via the pyvista-zstd companion package, included in the io extra (pip install pyvista[io]). It is a compact, multi-threaded alternative to the built-in VTK formats below when file size or I/O latency matters. Third-party packages can register additional custom writers via pyvista.register_writer().

ImageData File Formats

File Format

File Extension(s)

read()

save()

BMP Image

.bmp

DICOM

.dcm, .img

Digital Elevation Model

.dem

Gaussian Cube

.cube

GE Signa MR

.mr

GIF Image

.gif

JPEG Image

.jpeg, .jpg

Legacy VTK

.vtk

Legacy VTK (partitioned)

.pvtk

MetaImage

.mha, .mhd

MINC Image

.mnc

NIfTI

.nii, .nii.gz

NRRD

.nhdr, .nrrd

PNG Image

.png

PNM Image

.pnm

Radiance HDR

.hdr

SEG-Y

.segy, .sgy

SLC Volume

.slc

TIFF Image

.tif, .tiff

VTK File Series

.series

VTK ImageData

.vti

VTK ImageData (partitioned)

.pvti

VTKHDF

.hdf, .vtkhdf

RectilinearGrid File Formats

File Format

File Extension(s)

read()

save()

Legacy VTK

.vtk

Legacy VTK (partitioned)

.pvtk

VTK File Series

.series

VTK RectilinearGrid

.vtr

VTK RectilinearGrid (partitioned)

.pvtr

XDMF

.xdmf

StructuredGrid File Formats

File Format

File Extension(s)

read()

save()

Legacy VTK

.vtk

Legacy VTK (partitioned)

.pvtk

SEG-Y

.segy, .sgy

VTK File Series

.series

VTK StructuredGrid

.vts

XDMF

.xdmf

PolyData File Formats

File Format

File Extension(s)

read()

save()

Binary Marching Cubes

.tri

Facet Polygonal Data

.facet

Gaussian Cube

.cube

Houdini Geometry

.geo

Legacy VTK

.vtk

Legacy VTK (partitioned)

.pvtk

MOVIE.BYU

.g

Open Inventor

.iv

Protein Data Bank

.pdb

PTS Point Cloud

.pts

Stanford PLY

.ply

Stereolithography

.stl

VTK File Series

.series

VTK Particle

.raw

VTK PolyData

.vtp

VTKHDF

.hdf, .vtkhdf

Wavefront OBJ

.obj

UnstructuredGrid File Formats

File Format

File Extension(s)

read()

save()

AVS UCD

.inp

EnSight

.case

Fluent Case

.cas

GAMBIT Neutral

.neu

Legacy VTK

.vtk

Legacy VTK (partitioned)

.pvtk

MFIX

.res

Nek5000

.nek5000

proSTAR

.vrt

VTK File Series

.series

VTK UnstructuredGrid

.vtu

VTK UnstructuredGrid (partitioned)

.pvtu

VTKHDF

.hdf, .vtkhdf

XDMF

.xdmf

ExplicitStructuredGrid File Formats

File Format

File Extension(s)

read()

save()

Eclipse GRDECL

.grdecl

Legacy VTK

.vtk

VTK File Series

.series

VTK UnstructuredGrid

.vtu

MultiBlock File Formats

File Format

File Extension(s)

read()

save()

3D Studio

.3ds

CGNS

.cgns

EnSight

.case

Exodus II

.e, .ex2, .exii, .exo

Exodus II (partitioned)

.e.N.p, .n.N.p

Fluent CFF Case

.h5

glTF 2.0

.glb, .gltf

OpenFOAM

.foam

ParaView Data

.pvd

PLOT3D Meta

.p3d

Tecplot

.dat

VRML 2.0

.vrml, .wrl

VTK File Series

.series

VTK MultiBlock

.vtm, .vtmb

VTKHDF

.hdf, .vtkhdf

XDMF

.xdmf

PartitionedDataSet File Formats

File Format

File Extension(s)

read()

save()

VTK File Series

.series

VTK PartitionedDataSet

.vtpd

VTKHDF

.hdf, .vtkhdf

Warning

.pkl / .pickle extensions are not supported and will be refused. Pickle is a Python serialization protocol, not a mesh file format (CWE-502). Use a real mesh format or install pyvista-zstd for the .pv single-blob format.

Changed in version 0.49.0: Saving to an extension served by a companion package that is not installed raises ImportError rather than ValueError.

Parameters:
filenamestr, pathlib.Path

Filename of output file. Writer type is inferred from the extension of the filename.

binarybool, default: True

If True, write as binary. Otherwise, write as ASCII.

texturestr, np.ndarray, optional

Write a single texture array to file when using a PLY file. Texture array must be a 3 or 4 component array with the datatype np.uint8. Array may be a cell array or a point array, and may also be a string if the array already exists in the PolyData.

If a string is provided, the texture array will be saved to disk as that name. If an array is provided, the texture array will be saved as 'RGBA'

Note

This feature is only available when saving PLY files.

compressionstr or None, default: ‘zlib’

The compression type to use when binary is True and VTK writer is of type vtkXMLWriter. This argument has no effect otherwise. Acceptable values are 'zlib', 'lz4', 'lzma', and None. None indicates no compression.

Added in version 0.47.

**writer_kwargsdict, optional

Additional keyword arguments forwarded verbatim to a custom writer registered via pyvista.register_writer(). Use these to expose format-specific options such as compression level or thread count. When the target extension dispatches to a built-in VTK writer, passing any extra keyword arguments raises TypeError—PyVista never silently drops writer options.

Added in version 0.48.

Raises:
TypeError

If **writer_kwargs are provided but the target extension does not dispatch to a registered custom writer.

ImportError

If file_ext is served by a companion package that PyVista cannot import, such as .pv and pyvista-zstd.

ValueError

If file_ext is not a supported extension.

Notes#

Binary files write much faster than ASCII and have a smaller file size.

See Also#

pyvista.read