Read in STL files
Project description
stl-reader is a Python library for raipidly reading binary STL files. It wraps a Cython interface to the fast STL library provided by libstl. Thanks @aki5!
The main advantage of stl-reader over other STL reading libraries is its performance. It is particularly well-suited for large files, mainly due to its efficient use of hashing when merging points. This results in a 5-35x speedup over VTK for files containing between 4,000 and 9,000,000 points.
See the benchmarks below for more details.
Installation
The recommended way to install stl-reader is via PyPI:
pip install stl-reader
You can also clone the repository and install it from source:
git clone https://github.com/pyvista/stl-reader.git
cd stl-reader
pip install .
Usage
Load in the vertices and indices of a STL file directly as a NumPy array:
>>> import stl_reader
>>> vertices, indices = stl_reader.read("example.stl")
>>> vertices
array([[-0.01671113, 0.5450843 , -0.8382146 ],
[ 0.01671113, 0.5450843 , -0.8382146 ],
[ 0. , 0.52573115, -0.8506509 ],
...,
[ 0.5952229 , -0.57455426, 0.56178033],
[ 0.56178033, -0.5952229 , 0.57455426],
[ 0.57455426, -0.56178033, 0.5952229 ]], dtype=float32)
>>> indices
array([[ 0, 1, 2],
[ 1, 3, 4],
[ 4, 5, 2],
...,
[9005998, 9005988, 9005999],
[9005999, 9005996, 9005995],
[9005998, 9005999, 9005995]], dtype=uint32)
In this example, vertices is a 2D NumPy array where each row represents a vertex and the three columns represent the X, Y, and Z coordinates, respectively. indices is a 1D NumPy array representing the triangles from the STL file.
Alternatively, you can load in the STL file as a PyVista PolyData:
>>> import stl_reader
>>> mesh = stl_reader.read_as_mesh('example.stl')
>>> mesh
PolyData (0x7f43063ec700)
N Cells: 1280000
N Points: 641601
N Strips: 0
X Bounds: -5.000e-01, 5.000e-01
Y Bounds: -5.000e-01, 5.000e-01
Z Bounds: -5.551e-17, 5.551e-17
N Arrays: 0
Benchmark
The main reason behind writing yet another STL file reader for Python is to leverage the performant libstl library.
Here are some timings from reading in a 1,000,000 point binary STL file:
Library |
Time (seconds) |
---|---|
stl-reader |
0.174 |
numpy-stl |
0.201 (see note) |
PyVista (VTK) |
1.663 |
meshio |
4.451 |
Note numpy-stl does not merge duplicate vertices.
Comparison with VTK
Here’s an additional benchmark comparing VTK with stl-reader:
import numpy as np
import time
import pyvista as pv
import matplotlib.pyplot as plt
import stl_reader
times = []
filename = 'tmp.stl'
for res in range(50, 800, 50):
mesh = pv.Plane(i_resolution=res, j_resolution=res).triangulate().subdivide(2)
mesh.save(filename)
tstart = time.time()
out_pv = pv.read(filename)
vtk_time = time.time() - tstart
tstart = time.time()
out_stl = stl_reader.read(filename)
stl_reader_time = time.time() - tstart
times.append([mesh.n_points, vtk_time, stl_reader_time])
print(times[-1])
times = np.array(times)
plt.figure(1)
plt.title('STL load time')
plt.plot(times[:, 0], times[:, 1], label='VTK')
plt.plot(times[:, 0], times[:, 2], label='stl_reader')
plt.xlabel('Number of Points')
plt.ylabel('Time to Load (seconds)')
plt.legend()
plt.figure(2)
plt.title('STL load time (Log-Log)')
plt.loglog(times[:, 0], times[:, 1], label='VTK')
plt.loglog(times[:, 0], times[:, 2], label='stl_reader')
plt.xlabel('Number of Points')
plt.ylabel('Time to Load (seconds)')
plt.legend()
plt.show()
License and Acknowledgments
This project relies on libstl for reading in and merging the vertices of a STL file. Wherever code is reused, the original MIT License is mentioned.
The work in this repository is also licensed under the MIT License.
Support
If you are having issues, please feel free to raise an Issue.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file stl-reader-0.2.1.tar.gz
.
File metadata
- Download URL: stl-reader-0.2.1.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e08b868a82cae4cddfa2688a936d6bddd225813c7d69fe1efdab99175a30cbc |
|
MD5 | 0dc827c672cba519f5318b4cd90e8374 |
|
BLAKE2b-256 | 4246efaeeb55859511d17ed1982dd5cf1cd895fa3e9860ee19962952acf7bc17 |
File details
Details for the file stl_reader-0.2.1-cp312-cp312-win_amd64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 46.2 kB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 56c715bfe29d0bd92ce76c428e70784d1b61327ee2077cc6778716b7259cd9b7 |
|
MD5 | ebaa00c6187b3d8808fab6f9f3db68cb |
|
BLAKE2b-256 | 36561018e937ed4f69005ff19913ee24402553ee4fcec315a32b4de8235f76c9 |
File details
Details for the file stl_reader-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 62.6 kB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4e5e0f27586bace015119deff0c40f44d70456dc931b9b8a13106cb450923a2 |
|
MD5 | 3b12d360c6508744667bd2328dceeaf4 |
|
BLAKE2b-256 | 8377cb95fbcb0e54c0e047dd04764bff0c53077ac226235f128fef080de6966b |
File details
Details for the file stl_reader-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 37.9 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d5f424ed53ef3b1a2de091e7ddc0a606c72b3689a58c824091276bc289ce72d |
|
MD5 | 46f3b6be4fbbfeef420758ac8182ad75 |
|
BLAKE2b-256 | 472e51c22467b51fa96b74856a99c214b88e830b5b4dbecba5bc50092fbf7386 |
File details
Details for the file stl_reader-0.2.1-cp312-cp312-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp312-cp312-macosx_10_14_x86_64.whl
- Upload date:
- Size: 40.6 kB
- Tags: CPython 3.12, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c6bb593c99fded2eae7796a67b3442d4a5ec083f5490fdb2591f42afc6828b7d |
|
MD5 | 19063eeadc953a831fb625268238d9d4 |
|
BLAKE2b-256 | 02d2af94109c77cb4431c2a3b63cb0c1867ca13b4dd2287cbf5e1eee26d96623 |
File details
Details for the file stl_reader-0.2.1-cp311-cp311-win_amd64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 48.1 kB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fdec6aed73c93a0adc88feddf61cf0ab0a6c5e3c49a7222614091e7804a391c9 |
|
MD5 | 2864d6498434a6776377597941681bde |
|
BLAKE2b-256 | 42d8bf737ff1aa75700e101301e0ff63f37a501c06672b6a7694eed9c9abeb7e |
File details
Details for the file stl_reader-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 65.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f613c85d4da23c87c9596542d7a8173060af61ce701964046352ab050f6a4b24 |
|
MD5 | 5ebc397d0f07fec7adec188ce2a5f06f |
|
BLAKE2b-256 | 61ab2f76ec4f6ac16f7e104f83747513c60cc56f56e024b3bfa00b333f2c3ed5 |
File details
Details for the file stl_reader-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 39.9 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba5fff907b16bdd0b83b3cf5aa28e04ca2afadc140a1aad19beb475fb879046b |
|
MD5 | 5f1d1ebe0628b4ebf27ba4b7685f5867 |
|
BLAKE2b-256 | c599c1767fea1f3809df38e5bb2a33494a166aacae7715029f6644cd11fb8036 |
File details
Details for the file stl_reader-0.2.1-cp311-cp311-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp311-cp311-macosx_10_14_x86_64.whl
- Upload date:
- Size: 42.8 kB
- Tags: CPython 3.11, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5ea98040c80be5cf0148125821289f58bfa9bce25c2ab4a6358570dcec3c69 |
|
MD5 | c0fe10a1fc1dcabdc433d3367c65f9e2 |
|
BLAKE2b-256 | 42bf539c358a83d7f76f289c3161ea0f2c427f121bc90ff19601f4c8be8c23ed |
File details
Details for the file stl_reader-0.2.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 48.2 kB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f958cdb502f6f1c80f30854dd911883b495ba5ffc1cab8c38e02e46ab0ea1c9c |
|
MD5 | 267859afea4f929fd66050b03f3b6cfa |
|
BLAKE2b-256 | 7e6944fdd95f5890cc9ac95c69a1ac1bf5b9f9f80b07d0d276ba723bee8ea127 |
File details
Details for the file stl_reader-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 65.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e6f607810e241d2fc43e3eea48019b4715800d49374589f572db326095cf252 |
|
MD5 | 41aa3ec1451e786a5fcd4dc1f4a4220c |
|
BLAKE2b-256 | 0c20c321942965a07b0636f15a2154a6533c082126052100b5cd99a8b3e710db |
File details
Details for the file stl_reader-0.2.1-cp310-cp310-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp310-cp310-macosx_11_0_arm64.whl
- Upload date:
- Size: 40.0 kB
- Tags: CPython 3.10, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0aeb77d73108af1f7bab46aaaf85e82165f84a0c10bd38a9f59b5a84121d8042 |
|
MD5 | 28b2b2a41ea7596613e85c0f36a2a74f |
|
BLAKE2b-256 | 153dfbc902c29ab2c7851de2fd995ce2e0dead284a1ad283c63ae615c585193f |
File details
Details for the file stl_reader-0.2.1-cp310-cp310-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp310-cp310-macosx_10_14_x86_64.whl
- Upload date:
- Size: 43.0 kB
- Tags: CPython 3.10, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04e860f72b427b829388625f124b0eac2293d6a641ed83389305b887ef3bdcdf |
|
MD5 | f3bf68b2802dfe4d38e73cba16fcc8b6 |
|
BLAKE2b-256 | c6c9e6778c578a6ac2b8ad9fdb01c0f61570de7a5fc285d6ecfb09d7dafc8dec |
File details
Details for the file stl_reader-0.2.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 48.6 kB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2558cd827ca69874c8e879b8da688cf05505510b118289eed0a853d9fa880a5 |
|
MD5 | 65d4944d70fca838526ee12deadd1d9b |
|
BLAKE2b-256 | a5aa48f5edf1bcd86c79c2c2b929e4d6b05e498920eca4888447ee57971dce9e |
File details
Details for the file stl_reader-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 65.4 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7102a474108985d43b9f4185b300faaf5a705e02eddc99eca23a32f67849ff93 |
|
MD5 | a92efbf58a093113bb5f5c4936699405 |
|
BLAKE2b-256 | d5a0234459d546743b3f155adfc7f468da6e98f27bd8d828e4fdc9b9e23294bd |
File details
Details for the file stl_reader-0.2.1-cp39-cp39-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp39-cp39-macosx_11_0_arm64.whl
- Upload date:
- Size: 40.1 kB
- Tags: CPython 3.9, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 561f46e88a7236ab8463bcdc60b8c5a310d4c03e7f35d20ff46ea26250ee1ffb |
|
MD5 | bcea23d7f41b16194b8291f079c4be12 |
|
BLAKE2b-256 | 5ffbd85eefcd9578e4ba2e447503e94ac31ffad607ec55f7a7522221cdd58c1a |
File details
Details for the file stl_reader-0.2.1-cp39-cp39-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp39-cp39-macosx_10_14_x86_64.whl
- Upload date:
- Size: 43.0 kB
- Tags: CPython 3.9, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e02fe8d107eae5d57c2a7dcd0683583fc71547f173e9622b08057f38246816a |
|
MD5 | 0cfe7a8de7cd7645bf8e16cb4644af4c |
|
BLAKE2b-256 | d348cccab4304c723ee6c501677c5791d6288527deb1f4705be776dfdf091290 |
File details
Details for the file stl_reader-0.2.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 48.5 kB
- Tags: CPython 3.8, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1053e93c01a780e41035073444a5ecfc43e348e64b44afbf8e3f9175a5252d40 |
|
MD5 | 84598b1363c9771ccbc6c4c7bb7bf902 |
|
BLAKE2b-256 | ef964b05321d20f35b7e8e7ede900280f7406ec55262b80771e54a90f81c4ab6 |
File details
Details for the file stl_reader-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 65.3 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08833bfce0910b46db37d5926f868ca2c2f9d4e88372548cf3586bcd3ee8bf76 |
|
MD5 | 0d793bca2e1eca106e80677dedd77405 |
|
BLAKE2b-256 | 9dfc88c5527dcc168378f1439cd6b890fa33385ad7792b3106ac415abda97a35 |
File details
Details for the file stl_reader-0.2.1-cp38-cp38-macosx_11_0_arm64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp38-cp38-macosx_11_0_arm64.whl
- Upload date:
- Size: 40.1 kB
- Tags: CPython 3.8, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73b2949246179de60ddd3aeba5772edcb0107af754ce3048553d314f16ba75ff |
|
MD5 | ed65434639e6c15fa25caf4103c90bc1 |
|
BLAKE2b-256 | ec4eaa072c2b8818d3a8a8ab4503ccf1d20ab5f0c55b5fcc446d332cbf9dc3d7 |
File details
Details for the file stl_reader-0.2.1-cp38-cp38-macosx_10_14_x86_64.whl
.
File metadata
- Download URL: stl_reader-0.2.1-cp38-cp38-macosx_10_14_x86_64.whl
- Upload date:
- Size: 43.0 kB
- Tags: CPython 3.8, macOS 10.14+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d4f85c3b707bc8b32be90d6243b209a4bebb8d3db751dd18e9cd48308eaf261 |
|
MD5 | 268ec60ad0eb1f489d22b9d49ba3248b |
|
BLAKE2b-256 | c5a6e46b67a0b87d7dd20cd1782e552790ab4c6213ca53db933a5e3073e7672d |