nanocct
Open Cascade bindings created with nanobind for the stable ABI of Python 3
Open Cascade (OCCT) is a commonly used 3D CAD kernel for open source projects. It already has established Python bindings in OCP and pythonocc, and a whole ecosystem builds on them. nanocct takes a different route, started fresh with OCCT 8 and nanobind and makes OCCT 8 available to Python, class for class and method for method, so that code reads like the OCCT reference manual.
Design principles
nanocct follows 3 design principles:
-
One wheel per platform for the stable ABI of Python 3: The bindings are built with nanobind against the Python 3 stable ABI, so a single
cp312-abi3wheel runs on 3.12, 3.13, 3.14 and later without a rebuild. (Design 5.1) -
Coverage of Open Cascade: Support of the OCCT modules FoundationClasses, ModelingData, ModelingAlgorithms, Visualization (without VTK, which would break principle 1), ApplicationFramework, and DataExchange, and keep the syntax as near to the Open Cascade C++ API as possible (Design 2)
-
Make the bindings Python'ish: Provide addon features that make nanocct fit well into the Python ecosystem, within the constraints of principle 2 (e.g. names stay OCCT's CamelCase). (Design 2, Python additions)
Key features
From principle 2:
- The OCCT reference manual is the documentation. Names follow the OCCT headers, without renaming for Python taste, so the Open Cascade reference manual applies as it is. (Design 3.1)
From principle 3 (see Pythonic-OCCT.md):
- The OCCT 8 collection classes are Python generics.
NCollection_IndexedDataMap[TCollection_AsciiString, TCollection_AsciiString]()creates that instantiation, andisinstance(x, NCollection_Array1)holds for every array, whatever its element type. Design 3.1, 7a - Zero-copy access to OCCT's arrays. Triangulation nodes, triangles, UVs and normals, the
NCollectionarrays andImage_PixMapare numpy views of OCCT's own memory throughnp.asarray(obj), not copies. (Design 2, Python additions) - Iterators.
for e in TopExp_Explorer(shape, TopAbs_EDGE)andfor x in array: every OCCT iterator withMore()/Next()/Value()and everyNCollectioncontainer is a Python iterable. (Design 2, Python additions) - Out-parameters come back as results. A C++ reference parameter that OCCT writes into is part of the Python return value:
curve, first, last = BRep_Tool.Curve_s(edge). (Design 3.2) - Data exchange in memory. An output stream is a returned
str(bytesfor binary formats), an input stream any file-like object:BRepTools.Write_s(shape)returns the BREP text, STEP and the OCAF documents work the same way. (Design 3.2) - Type stubs in the package, checked with mypy and ty as part of the test suite. (Design 7b)
nanocct ships a few selected AddOns (Design 7, R-ADDON):
- C++ helpers where a Python loop over OCCT calls would dominate (
nanocct.AddOns.Tessellator) - Workarounds (not patches and very rarely) for OCCT bugs that hit often and are not fixed upstream — each with a test that fails once OCCT fixes the bug, so it can be removed again (
nanocct.AddOns.ShapeClean.ShapeClean)
Validation
nanocct comes with its own test suite of about 1 260 tests, run against the repaired wheel in a fresh environment by every build (make test), on all five platforms in CI. One test file per toolkit checks that the bindings behave as OCCT does; the generator itself is tested on synthetic headers that exercise its binding rules. Lifetime tests drop the owner or the result of every ownership rule in a fresh interpreter with the allocator's scribbling switched on, leak tests check that repeating each life cycle keeps memory flat, and the type stubs are checked with mypy and ty.
nanocct is also validated against real code. The full test suites of nanocct-enabled versions of build123d (2 780 tests), ocpsvg, ocp_gordon and ocp_tessellate run on nanocct with the same outcome, test by test, as with the OCP bindings they were written for.
A first look
import numpy as np
from nanocct.BRep import BRep_Tool
from nanocct.BRepMesh import BRepMesh_IncrementalMesh
from nanocct.BRepPrimAPI import BRepPrimAPI_MakeCylinder
from nanocct.BRepTools import BRepTools
from nanocct.TopAbs import TopAbs_ShapeEnum
from nanocct.TopExp import TopExp_Explorer
from nanocct.TopLoc import TopLoc_Location
import nanocct.TopoDS as TopoDS
shape = BRepPrimAPI_MakeCylinder(5.0, 10.0).Shape()
BRepMesh_IncrementalMesh(shape, 0.1)
for face in TopExp_Explorer(shape, TopAbs_ShapeEnum.TopAbs_FACE):
mesh = BRep_Tool.Triangulation_s(TopoDS.Face(face), TopLoc_Location())
nodes = np.asarray(mesh.InternalNodes()) # (N, 3) numpy view of OCCT's memory, no copy
edge = TopoDS.Edge(next(iter(TopExp_Explorer(shape, TopAbs_ShapeEnum.TopAbs_EDGE))))
curve, first, last = BRep_Tool.Curve_s(edge) # out-parameters come back in the result
brep = BRepTools.Write_s(shape) # a BREP in memory, as str
Status
- OCCT 8.0.1, 45 toolkits: FoundationClasses, ModelingData, ModelingAlgorithms, Visualization (without VTK), ApplicationFramework and DataExchange. Design 2
- Built and tested on five platforms: macOS arm64 and x86_64, Linux x86_64 and aarch64 (
manylinux_2_28) and Windows x64. The wheels bundle OCCT, FreeType and FreeImage; the only Python dependency is numpy. - Install it from PyPI with
pip install nanocct, download the wheels from the release page, or build them from source with theMakefile. Design 8 - Porting from OCP: Design 10
How to start with build123d on nanocct
nanocct-tests sets up a Python environment with nanocct, build123d and the packages build123d and its viewer build on, ported to nanocct, and runs their test suites:
git clone https://github.com/bernhard-42/nanocct-tests
cd nanocct-tests
make env
source .venv/bin/activate
It installs the nanocct wheel of the latest release, or the one you copy into its wheels/ folder (a wheel built here lands in dist/).
How to build nanocct
Prerequisites: git, curl, uv, CMake and Ninja; on macOS the Xcode command line tools, on Linux Docker (the build runs in a manylinux_2_28 container), on Windows Git Bash and the Visual Studio Build Tools (MSVC). Design 4, Design 8
-
Clone the repo
git clone https://github.com/bernhard-42/nanocct cd nanocct
-
Create the Python environment the build uses (
.venv)make env -
Build the dependencies OCCT 8.0.1, FreeType, FreeImage and RapidJSON
make deps -
Build the bindings: generate, compile, stubs, pack and repair the wheel, test the repaired wheel in a fresh environment -- the wheel lands in
dist/make wheels
License
nanocct's own code is Apache-2.0 (LICENSE). The wheels bundle OCCT (LGPL-2.1 with the OCCT exception), FreeType and FreeImage; licenses/ and NOTICE say which terms apply and why.
Metadata
Release files for nanocct 8.0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| nanocct-8.0.1.3-cp312-abi3-win_amd64.whl | CPython 3.12 | abi3 | Windows x86-64 | Details for nanocct-8.0.1.3-cp312-abi3-win_amd64.whl |
| nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_x86_64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ x86-64 | Details for nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_x86_64.whl |
| nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_aarch64.whl | CPython 3.12 | abi3 | Linux glibc 2.28+ ARM64 | Details for nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_aarch64.whl |
| nanocct-8.0.1.3-cp312-abi3-macosx_11_0_x86_64.whl | CPython 3.12 | abi3 | macOS 11.0+ x86-64 | Details for nanocct-8.0.1.3-cp312-abi3-macosx_11_0_x86_64.whl |
| nanocct-8.0.1.3-cp312-abi3-macosx_11_0_arm64.whl | CPython 3.12 | abi3 | macOS 11.0+ ARM64 | Details for nanocct-8.0.1.3-cp312-abi3-macosx_11_0_arm64.whl |
Total release size: 260.5 MB
Release files / nanocct-8.0.1.3-cp312-abi3-win_amd64.whl
| Download URL | nanocct-8.0.1.3-cp312-abi3-win_amd64.whl |
|---|---|
| Size | 53.4 MB |
| Tags | CPython 3.12 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0750ddca37497e7a2df88d690892c624924ea6e3287403c0597bef62d684da3e
|
|
BLAKE2b-256 checksum How to use checksums |
cff0019766d18b65c23bd9abdc6fe74a2ab7baa0ac750c1a359d4cc5b7b5c6bb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_x86_64.whl
| Download URL | nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 54.7 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0b3f07f793ed3b99d47ad453867f13721443e7a541dae3b0ca72420e135937ee
|
|
BLAKE2b-256 checksum How to use checksums |
5f0f6ce2db5e80603ad146e600e15fd6a553b4b256ed501c9b5a1ced1106101a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_aarch64.whl
| Download URL | nanocct-8.0.1.3-cp312-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 49.6 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
1ced20a43e70d701c740fec68c05d8c0843bb9ae1b1ccab91c54fa22df7e9d8b
|
|
BLAKE2b-256 checksum How to use checksums |
1914616b77507c78e217d83ef8688be076ab94a7e9a8763dc748a3d1982f391e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nanocct-8.0.1.3-cp312-abi3-macosx_11_0_x86_64.whl
| Download URL | nanocct-8.0.1.3-cp312-abi3-macosx_11_0_x86_64.whl |
|---|---|
| Size | 53.7 MB |
| Tags | CPython 3.12 abi3 macOS 11.0+ x86-64 |
|
SHA-256 checksum How to use checksums |
57c0e4d215311f3df639a8bcb5c53c77f2aba61239ee8243488fd971274345d5
|
|
BLAKE2b-256 checksum How to use checksums |
ba049523e5d81386e79b9b672e79ba9d18945d3ab87108e6675705e74be0a4ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / nanocct-8.0.1.3-cp312-abi3-macosx_11_0_arm64.whl
| Download URL | nanocct-8.0.1.3-cp312-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 49.1 MB |
| Tags | CPython 3.12 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
2417822a9e937b470a7aee0eb0418fb34806bb84df929226094bcb244605abdc
|
|
BLAKE2b-256 checksum How to use checksums |
c74511361e9780b85cf63b7bb50e7e1ffe52a4f94712c07fcb137ca64740753c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for nanocct 8.0.1.3
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.