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

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

Total release size: 261.3 MB

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

Download URL nanocct-8.0.1.2-cp312-abi3-win_amd64.whl
Size 53.4 MB
Tags CPython 3.12 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
fdcd698be373bae96b61fe36fc9a3ae03b3591dfb734911a206d33ad7b331db9
BLAKE2b-256 checksum
How to use checksums
6a2cab90ccc965c45ce9c6816dd6d97f347e1aa2e6c49c7766a343a84ddca8f2
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.2-cp312-abi3-manylinux_2_28_x86_64.whl

Download URL nanocct-8.0.1.2-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
e3cf1e163c42ce5a9f07b006cf1b19da46cb357e9199524fa294a5aafe96ddf2
BLAKE2b-256 checksum
How to use checksums
4a46fda8da42f738bc054b1efbbe69de6d628eb2d6b2bdb7703c1feac12392f1
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.2-cp312-abi3-manylinux_2_28_aarch64.whl

Download URL nanocct-8.0.1.2-cp312-abi3-manylinux_2_28_aarch64.whl
Size 49.5 MB
Tags CPython 3.12 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
a92001b634eb3e14c54b30046c65572632c631ba8d4f1ea8ade47e124a458779
BLAKE2b-256 checksum
How to use checksums
af2f9986ca6ffcfd70839f4075563ead7630702642419204b85e759426e9fc3a
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.2-cp312-abi3-macosx_11_0_x86_64.whl

Download URL nanocct-8.0.1.2-cp312-abi3-macosx_11_0_x86_64.whl
Size 54.5 MB
Tags CPython 3.12 abi3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
85dda5d09f99a205407ff6760b92f0152476267ea91b9429063bf0db16abb728
BLAKE2b-256 checksum
How to use checksums
8a78911370ff41acb1ef7588124adabc2812441a41960fa3e9e3f8906df2988d
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.2-cp312-abi3-macosx_11_0_arm64.whl

Download URL nanocct-8.0.1.2-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
a336d59159895b8054cd5a329621b13ebf0572ff210f070b2e6a9eac8fd550eb
BLAKE2b-256 checksum
How to use checksums
1df2f4577471bc27b92a3f02c0e7e42fde88755ac7d0a936c6303c8b78d3f8c5
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.2

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