gtsam-nb: nanobind bindings for GTSAM
This repository provides Python bindings for GTSAM using nanobind.
Most of the code, tests, data, etc. are originally from the official GTSAM repository, just slightly modified to work with nanobind and clean up python typing.
Installation
It's all available via pip!
pip install gtsam-nb # if using pip
uv add gtsam-nb # if using uv
Then use as you would the official gtsam Python bindings:
import gtsam
gtsam-nb should be a near drop-in replacement for the official gtsam python package, with the following (mostly minor) exceptions:
- Unlike pybind11, nanobind doesn't accept python lists in place of numpy arrays for function arguments. So wrapping lists in
np.array(...)is necessary. OrderingTypeenum values are now accessed asgtsam.OrderingType.XXXinstead ofgtsam.Ordering.OrderingType.XXX.lambda_is nowlambda_aingtsam.LevenbergMarquardtOptimizerdue to how nanobind handles private methods.- [FEAT]
NonlinearFactorGraphandValuesinterface more like a python list and dict, respectively including constructors and[]usage.
There are likely other tweaks required (please let us know if you find any), but they should all be fairly minor.
Why?
There's a handful of reasons why I decided to make this (most of which should hopefully be resolved when gtsam 4.3 is released):
- As of the writing of this README,
gtsam's most recent python release only supports up to python 3.11. This has restricted the python version for a number of my projects. - In addition, the current stable
gtsamon pypi are incompatible with numpy>=2.0. - The
gtsampython bindings don't include type stubs, making development in an IDE and type checking more difficult. - A switch to nanobind over pybind11 for a number of reasons, including
- nanobind results in faster compilation, smaller binaries, and a smaller overhead. See benchmarks for more details.
- nanobind has built-in stub generation, make setting up type stubs a cakewalk.
- Based on my knowledge, nanobind has a more permissive ABI compatibility story than pybind11, which makes it easier to extend
gtsamwith custom C++ code that will just work together. See here and here. - Since all my projects now use nanobind, if I want to add new C++ factors to GTSAM from python, I need nanobind bindings.
- I often have found the
gtsambindings to be missing a method or two that I need. This then requires me to build the bindings from source. By having my own version, I can easily add in any missing methods I need, and get them merged and released on PyPI quickly. This is more difficult for the officialgtsambindings since they are released alongside GTSAM itself.
Hopefully in the future these issues will be resolved in the official gtsam bindings, and this repository will no longer be necessary. But for now, this is a useful stopgap.
Building
Building is all piped through scikit-build-core (which we use behind uv). The only dependency is GTSAM 4.2, which will be resolved in the following order:
- If
vcpkg.shwas ran to clone vcpkg into the.vcpkgfolder, then GTSAM will be built and installed via vcpkg. - If not, GTSAM is searched for in the system paths.
- If not found, GTSAM will be cloned and built from source in the build process.
To actually perform the building from source, clone the repository and run:
pip install -e . # if using pip
uv sync --verbose # if using uv
This will build the C++ extension and install the package in editable mode in whatever environment you have activated.
Contributing
There is likely a hidden bug or two, and definitely still some missing methods. Please feel free to open issues or PRs! I imagine most PRs will be to add missing methods or classes from GTSAM so they can be merged and released quickly (especially since it's all automated through our CI setup).
Metadata
Release files for gtsam-nb 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| gtsam_nb-0.1.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.14 | CPython 3.14 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| gtsam_nb-0.1.4-cp314-cp314-macosx_11_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 11.0+ ARM64 | Details |
| gtsam_nb-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 | Details |
| gtsam_nb-0.1.4-cp313-cp313-macosx_11_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 11.0+ ARM64 | Details |
| gtsam_nb-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| gtsam_nb-0.1.4-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| gtsam_nb-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details |
| gtsam_nb-0.1.4-cp311-cp311-macosx_11_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 11.0+ ARM64 | Details |
Total release size: 127.2 MB
Release files / gtsam_nb-0.1.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gtsam_nb-0.1.4-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.4 MB |
| Tags | CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
ce13d78a4333520afa3c743c77f0f80f3debe85f75c16ab9400754a53001a3f8
|
|
BLAKE2b-256 checksum How to use checksums |
3627ebf2d655256d0f6453de85aea4ad0003c6a294d68ce181bef3eea42496cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp314-cp314-macosx_11_0_arm64.whl
| Download URL | gtsam_nb-0.1.4-cp314-cp314-macosx_11_0_arm64.whl |
|---|---|
| Size | 15.4 MB |
| Tags | CPython 3.14 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0374051f9d6cc67edd547122429a1c9924775d19e353a77b792e6737478b2658
|
|
BLAKE2b-256 checksum How to use checksums |
44f227862ba0e2e0db18fe6dae03195cd5c69735087900af4f455ee84c999660
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gtsam_nb-0.1.4-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.4 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e39664c6532e5e610f2d246455f0a66cbc445025be5f932b028f63f6cf04f199
|
|
BLAKE2b-256 checksum How to use checksums |
809841460ae7958b44bbb655c1b709d61894ace8aa48b907e4d4213b8fc830a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp313-cp313-macosx_11_0_arm64.whl
| Download URL | gtsam_nb-0.1.4-cp313-cp313-macosx_11_0_arm64.whl |
|---|---|
| Size | 15.4 MB |
| Tags | CPython 3.13 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a9f3e09db8e661b5aeb6871a96c7cf68540b0f9398cd41a26075d9bbf0251beb
|
|
BLAKE2b-256 checksum How to use checksums |
0aa48c0c86674b7e4de26d97511778796e8064d32f7dbc04cb34a77a38117817
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gtsam_nb-0.1.4-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.4 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a8eb8bd095957a2c7a04a5628f3b262de849c4922720fed6fedad433d373ca37
|
|
BLAKE2b-256 checksum How to use checksums |
f291efe5dc7e4502bfbeaaeb677b68f86b6c9abc7a5c191119e88043f9592004
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | gtsam_nb-0.1.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 15.4 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
bedea298637036d65f954a03385e6ff614d5a26db3206a60e52d50af4b11a8d9
|
|
BLAKE2b-256 checksum How to use checksums |
426e3482539b2a5080d21aa7db17f84c2102c4948242f4cd6edf98d358555ed2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | gtsam_nb-0.1.4-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 16.4 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
03287e05b0a1c8638fb55beee6be803aab42bbc23def9fb41c2db574260ed011
|
|
BLAKE2b-256 checksum How to use checksums |
0bc2e3d2c7a3486bbbf4281b63f3399a52384932e9f2d62e321f8402bdd26d88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency logRelease files / gtsam_nb-0.1.4-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | gtsam_nb-0.1.4-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 15.4 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
b69e69c43f2d4585684c715ccf623cef657d7a0871e7124ac0e4b14e64aa3798
|
|
BLAKE2b-256 checksum How to use checksums |
49b42e0ab7d015d468d6080ca158553702da326f1f873e48f934558abff6a7ea
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 7, 2026.
Transparency log