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.4

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.4
File Actions
nanocct-8.0.1.4-cp312-abi3-win_amd64.whl CPython 3.12 abi3 Windows x86-64 Details for nanocct-8.0.1.4-cp312-abi3-win_amd64.whl
nanocct-8.0.1.4-cp312-abi3-manylinux_2_28_x86_64.whl CPython 3.12 abi3 Linux glibc 2.28+ x86-64 Details for nanocct-8.0.1.4-cp312-abi3-manylinux_2_28_x86_64.whl
nanocct-8.0.1.4-cp312-abi3-manylinux_2_28_aarch64.whl CPython 3.12 abi3 Linux glibc 2.28+ ARM64 Details for nanocct-8.0.1.4-cp312-abi3-manylinux_2_28_aarch64.whl
nanocct-8.0.1.4-cp312-abi3-macosx_11_0_x86_64.whl CPython 3.12 abi3 macOS 11.0+ x86-64 Details for nanocct-8.0.1.4-cp312-abi3-macosx_11_0_x86_64.whl
nanocct-8.0.1.4-cp312-abi3-macosx_11_0_arm64.whl CPython 3.12 abi3 macOS 11.0+ ARM64 Details for nanocct-8.0.1.4-cp312-abi3-macosx_11_0_arm64.whl

Total release size: 260.6 MB

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

Download URL nanocct-8.0.1.4-cp312-abi3-win_amd64.whl
Size 53.4 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
17e6b1d0b0185ffc9fa20042926c9cec42fa22cff0e4021cef7166f874216d0d
BLAKE2b-256 checksum
How to use checksums
2108a4119d97d539dec5042a52ecf022cb9df42990568c05a2ab6f186dad2737
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.4-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL nanocct-8.0.1.4-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
6684b23f58fd69a4c162f2f3ba4532bf63dfa662c4c21e0c56e6e9003cffb948
BLAKE2b-256 checksum
How to use checksums
d13bceb0030a0b1c88cb51835aa865ede759c2f75b214b53c91e01d0e19b562e
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.4-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL nanocct-8.0.1.4-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
b05ab9c901448a4d70d96a4644c5822867eb53a93a5c6f1fe1b269e43e5c2a31
BLAKE2b-256 checksum
How to use checksums
24a912208dbdc22fb8015860f083ae9b9a905a3fbceede47abb856e8d17f4590
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.4-cp312-abi3-macosx_11_0_x86_64.whl

Download URL nanocct-8.0.1.4-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
34e8fe10f54781a05082ff3599cf9106a8050ca3fae25d54899b02ce2cd61e22
BLAKE2b-256 checksum
How to use checksums
1407e5c4431d6d95a0791643e390096c4a8d05d53993b9f3f368840688368e7d
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.4-cp312-abi3-macosx_11_0_arm64.whl

Download URL nanocct-8.0.1.4-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
d37628cd4be8d3f79d6d6289b418cf8b9e255aa6f4da2ac94818ecd27ed7cc70
BLAKE2b-256 checksum
How to use checksums
5539a98563a2040ad69ab583f21728f4b1a81e802c6a6ab94c3dacb62154daaa
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.4

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