The `plyfile` Python module provides a simple, NumPy-based facility for reading and writing ASCII and binary PLY files, a common format for storing 3D surface meshes. It is currently at version 1.1.3 (released October 21, 2025) and maintains an active development status with several releases per year, as evidenced by its changelog and PyPI activity.
pip install plyfileVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create structured NumPy arrays representing vertices and faces, construct `PlyElement` and `PlyData` objects, write them to an ASCII PLY file, and then read the data back. It covers the basic workflow for both serialization and deserialization.
Upgrade your Python environment to 3.9 or newer and NumPy to 1.21 or newer. `pip install --upgrade python numpy` or manage with your preferred environment tool.
For fixed-length list properties, provide `known_list_len={'element_name': {'list_property_name': length}}` to `PlyData.read`. Avoid memory mapping for elements with truly variable-length list properties.Always use binary mode (`'rb'` for reading, `'wb'` for writing) when opening PLY files to ensure compatibility with both ASCII and binary PLY formats, unless you specifically intend to work only with ASCII files via text streams.
Ensure that the NumPy structured array dtypes align with supported PLY data types (e.g., float, uchar, int). Convert unsupported types to compatible ones before creating `PlyElement` instances.
After reading, if a 2D array is needed from a list property, manually concatenate or stack the individual NumPy arrays stored within the `object`-typed field, e.g., `np.vstack(plydata['element_name'].data['list_property'])`.
Install the package using pip or conda, ensuring the correct environment is activated: `pip install plyfile` or `conda install -c conda-forge plyfile`.
Ensure the PLY file is opened in binary read mode ('rb') when passed to `PlyData.read()`: `with open('file.ply', 'rb') as f: plydata = PlyData.read(f)`.Verify the PLY file's header for strict adherence to the PLY format specification, checking for extraneous characters, correct format declaration, and consistent Unix-style ('\n') line endings, especially on the 'ply' and 'end_header' lines.When adding or modifying properties, explicitly create a new structured NumPy array with the desired new fields and copy over the existing data, or use `numpy.lib.recfunctions.merge_arrays` for merging structured arrays.