plyfile

1.1.3 · active · verified Sun Apr 12

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.

Warnings

Install

Imports

Quickstart

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.

import numpy as np
from plyfile import PlyData, PlyElement
import os

# 1. Prepare data for a PLY file
vertices = np.array([
    (0.0, 0.0, 0.0, 255, 0, 0),
    (1.0, 0.0, 0.0, 0, 255, 0),
    (0.0, 1.0, 0.0, 0, 0, 255),
    (1.0, 1.0, 0.0, 255, 255, 0)
], dtype=[('x', 'f4'), ('y', 'f4'), ('z', 'f4'), ('red', 'u1'), ('green', 'u1'), ('blue', 'u1')])

faces = np.array([
    ([0, 1, 2],),
    ([1, 3, 2],)
], dtype=[('vertex_indices', 'i4', (3,))])

# 2. Create PlyElement instances
vertex_element = PlyElement.describe(vertices, 'vertex')
face_element = PlyElement.describe(faces, 'face')

# 3. Create a PlyData instance
plydata_to_write = PlyData([vertex_element, face_element], text=True, comments=['Created by plyfile quickstart'])

output_filename = 'quickstart_output.ply'

# 4. Write the PLY data to a file
with open(output_filename, 'wb') as f:
    plydata_to_write.write(f)

print(f"Successfully wrote PLY file: {output_filename}")

# 5. Read the PLY data from the file
with open(output_filename, 'rb') as f:
    plydata_read = PlyData.read(f)

print("\nSuccessfully read PLY file:")
print(plydata_read)
print("Vertices:\n", plydata_read['vertex'].data)
print("Faces:\n", plydata_read['face'].data)

# Clean up the created file
os.remove(output_filename)
print(f"Cleaned up {output_filename}")

view raw JSON →