Skip to main content

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:

  1. 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-abi3 wheel runs on 3.12, 3.13, 3.14 and later without a rebuild. (Design 5.1)

  2. 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)

  3. 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:

From principle 3 (see Pythonic-OCCT.md):

  • The OCCT 8 collection classes are Python generics. NCollection_IndexedDataMap[TCollection_AsciiString, TCollection_AsciiString]() creates that instantiation, and isinstance(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 NCollection arrays and Image_PixMap are numpy views of OCCT's own memory through np.asarray(obj), not copies. (Design 2, Python additions)
  • Iterators. for e in TopExp_Explorer(shape, TopAbs_EDGE) and for x in array: every OCCT iterator with More()/Next()/Value() and every NCollection container 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 (bytes for 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 the Makefile. 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.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for nanocct 8.0.1.5
File Actions
nanocct-8.0.1.5-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for nanocct-8.0.1.5-cp312-abi3-win_amd64.whl
nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_x86_64.whl
nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_aarch64.whl
nanocct-8.0.1.5-cp312-abi3-macosx_11_0_x86_64.whl CPython 3.12 abi3 macOS 11.0+ x86-64 Details for nanocct-8.0.1.5-cp312-abi3-macosx_11_0_x86_64.whl
nanocct-8.0.1.5-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for nanocct-8.0.1.5-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 260.6 MB

Release files / nanocct-8.0.1.5-cp312-abi3-win_amd64.whl

Download URL nanocct-8.0.1.5-cp312-abi3-win_amd64.whl
Size 53.4 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a5e54c73e6c4e26eda26cff68d520c3fb1a327b8e9568b6140e53dab0239d7e2
BLAKE2b-256 checksum
How to use checksums
cba4c0771092082127036f99874b7d97838f36a31fc766e9e169f9b569391a2e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL nanocct-8.0.1.5-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
9ce2755c65ae424cad71deb7b6738416fb1d57e10f054dcdc4bab066ec47c5e3
BLAKE2b-256 checksum
How to use checksums
f4159dabc8e1619d4eff9ab87b4066d770518011cda547b6c414679bfb91be08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / nanocct-8.0.1.5-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL nanocct-8.0.1.5-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
f0e71e8a95ab2f27354951387d91db5f5526c84479df4294b88409e84e6e539d
BLAKE2b-256 checksum
How to use checksums
a9b2a5494cd8748ebd2f22996ad8ec14fdab417313303053439fadfe470da36a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / nanocct-8.0.1.5-cp312-abi3-macosx_11_0_x86_64.whl

Download URL nanocct-8.0.1.5-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
8ed381d129e825e75abe50470dae2f9c24f16f6e32efb0961a911e97c52ed4d9
BLAKE2b-256 checksum
How to use checksums
2788b8420ba9535205448f2f4af3339233c100664d399e6356f42aa9ac892251
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Release files / nanocct-8.0.1.5-cp312-abi3-macosx_11_0_arm64.whl

Download URL nanocct-8.0.1.5-cp312-abi3-macosx_11_0_arm64.whl
Size 49.2 MB
Tags CPython 3.12 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cc0b9443c2d4f89cac005692eb1e412e2781e574bbf0092ca6d65e76b1d4d127
BLAKE2b-256 checksum
How to use checksums
e3129ca845bc2322346777dd23d3edb7cf02d6679b62a47e7311c08fbe42d856
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.9

Security for nanocct 8.0.1.5

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page