ply_parser
Read PLY (Polygon File Format) files in Python, with zero dependencies.
ply_parser reads ASCII and binary PLY meshes into plain Python lists: vertices, faces, colors and normals. It follows the header, so unusual vertex layouts and extra elements are handled, and malformed files fail with a readable ValueError instead of silent garbage.
pip install ply_parser
Requires Python 3.8+.
Quick start
from ply_parser import parse_ply_file
obj = parse_ply_file("cube.ply")
print(obj) # PLYObject(name='cube.ply', vertices=8, faces=12, colors=0, normals=0)
print(obj.vertices[0]) # [-1.0, -1.0, 1.0]
print(obj.faces[0]) # [0, 1, 2]
What you get
parse_ply_file() takes a path (str or pathlib.Path) and returns a PLYObject with:
| Attribute | Contents |
|---|---|
name |
The path you passed, or the name you gave parse_ply() |
vertices |
[x, y, z] floats for every vertex |
faces |
Vertex indices for each face (any number of vertices per face) |
colors |
[r, g, b] per vertex, as stored in the file. Empty if none |
normals |
[nx, ny, nz] per vertex. Empty if none |
Colors keep their file values: a uchar channel is 0-255.
Features
- ASCII, binary little-endian and big-endian formats
- Any header layout: properties in any order, extra properties and extra elements are skipped
- Polygons, not just triangles: faces keep every vertex index
- Colors and normals picked up from
red/green/blue,r/g/b,diffuse_*,nx/ny/nzornormal_*properties - Strict by default: header and body must agree, indices must be in range, coordinates must be finite
- Parse from memory as well as from disk
Parsing data you already have
from ply_parser import parse_ply
with open("scan.ply", "rb") as f:
obj = parse_ply(f.read(), name="scan")
parse_ply() takes str for ASCII data or bytes for any format.
For line-based input, parse_ply_file_data() returns the older [vertices, faces, colors] list:
from ply_parser import parse_ply_file_data
vertices, faces, colors = parse_ply_file_data(lines)
Handling bad files
from ply_parser import parse_ply_file
try:
obj = parse_ply_file("broken.ply")
except ValueError as err:
print(err) # e.g. "PLY: vertex index 9 out of range (only 8 vertices) in face 0"
Development
git clone https://github.com/HimalayanSeer/ply_parser
cd ply_parser
pip install .
python -m unittest tests/test_ply_parser.py -v
Contributing
Issues and pull requests are welcome, especially sample PLY files that the parser gets wrong. Please include a small file that reproduces the problem.
License
MIT. See LICENSE.
Metadata
Release files for ply-parser 3.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ply_parser-3.0.1.tar.gz | 12.5 kB | Without provenance | Details for ply_parser-3.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ply_parser-3.0.1-py3-none-any.whl | Python 3 | none | any | Details for ply_parser-3.0.1-py3-none-any.whl |
Total release size: 20.3 kB
Release files / ply_parser-3.0.1.tar.gz
| Download URL | ply_parser-3.0.1.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8aa5b187d49f8ef4d7e1b7170ca3a03fe38cc3b4794ef40ae8e87c6563c274cd
|
|
BLAKE2b-256 checksum How to use checksums |
6ef84ae9ffba6a837ed69df1d04126af9b95660792d66c94ac8721f4be56886c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.9
|
Release files / ply_parser-3.0.1-py3-none-any.whl
| Download URL | ply_parser-3.0.1-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6dd42c1be02f64567d27dd26a8eb2a4138c0f645970ab8be98641e8dc8dd47af
|
|
BLAKE2b-256 checksum How to use checksums |
de6c630a00295ff05d5deb88584eac74cbb9f828f70571f8134f1c3d41b744aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.9
|
Security for ply-parser 3.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.