@cadbuildr/cad-pyodide-runtime
v0.1.0
Published
Pyodide runtime for running foundation CAD code in browser apps
Maintainers
Readme
cad-pyodide-runtime
Standalone browser runtime for Pyodide with a CAD foundation package preinstalled.
Summary
This package provides an ergonomic way to run CAD foundation Python code in the browser:
- Load Pyodide.
- Install
micropip,numpy, and a configurable foundation package. - Run Python code and optionally extract a DAG via
show(...).
Install
npm install @cadbuildr/cad-pyodide-runtime pyodideQuick start
import { initializeCadPyodideRuntime, runCadPythonCode } from "@cadbuildr/cad-pyodide-runtime";
const pyodide = await initializeCadPyodideRuntime({
packages: {
foundation: "^0.2.0",
foundationPackageName: "foundation-core",
},
foundationImportPath: "foundation_core",
foundationDagUtilsPath: "foundation_core.dag_utils",
});
const result = await runCadPythonCode(
pyodide,
`
from foundation_core import show
from foundation_core.models import Part
part = Part()
show(part)
`
);
console.log(result.dag);API
initializeCadPyodideRuntime(options)-> initializes Pyodide + foundation package.runCadPythonCode(pyodide, pythonCode, options?)-> runs code and returns{ dag }.buildFoundationRequirement(version, packageName?)-> converts versions/caret constraints to micropip requirements.
Development
npm install
npm test
npm run type-checkPublishing
Ensure you are logged into npm with access to the @cadbuildr scope, then:
npm publish --access publicPairing with cad-kernel-r3f
After runCadPythonCode returns a DAG, pass it to @cadbuildr/cad-kernel-r3f (for example KernelStlMesh and createKernelApiClient pointed at your kernel-api base URL). The Pyodide and kernel layers are separate concerns; compose them in your app.
