Self-registering nanobind helpers (import as easybind)
Project description
easybind
Simple self-registering helpers for distributed nanobind bindings.
Install
pip install easybind
import easybind
from easybind import sample # optional demo module
PyPI project: easybind (same name as the import).
Version: Set by Git tags at build time (v0.1.0, …) via setuptools-scm; see RELEASING.md. At runtime, easybind._version.__version__ is written when the wheel is built (or use importlib.metadata.version("easybind")).
Local dev / clangd
An editable install configures CMake under ./build/ and generates build/compile_commands.json, which clangd picks up via .clangd — same database as the Python build, no second configure step:
uv pip install -e . # or: pip install -e .
If you need compile_commands.json without pip, run scripts/clangd-update.sh (plain cmake -S . -B build …).
Python layer
The Python package is implemented as native extensions. It exposes:
easybind(core helpers and macros)easybind.module(module tree API)easybind.sample(demo bindings)
Build-time SDK
easybind provides CMake helpers for hybrid extensions:
easybind::build_interface(INTERFACE): baseline C++20 + PIC + shared include pathseasybind_add_extension(target ...): wrapsnanobind_add_module(... NB_SHARED ...)
Example:
find_package(easybind CONFIG REQUIRED)
easybind_add_extension(my_module src_bind/my_pkg/__cpp__/module.cpp)
target_link_libraries(my_module PRIVATE easybind::easybind)
Core idea
- Each namespace/module defines a
ModuleNodeand a bind callback. - The module entry point calls
apply_initto run the callback and recurse. - Submodules are created on demand and registered in
sys.modules. - Shared-object modules are marked so recursion stops at their boundary.
- A minimal sample module lives at
easybind.sample.
Developer note: layout rules
__init__.cppmarks the Python boundary (NB_MODULE) for a package/module.node.cpp/.hppis the pure C++ module-tree core.ns_module.hppdefines theEASYBIND_NS_MODULE*macros.- Directory layout mirrors namespaces and Python modules.
Smallest possible example
1) Define a C++ type (normal code)
#pragma once
#include <string>
struct PeerInfo {
std::string peer_id;
int transport = 0;
};
2) Bind it in a separate file (module node)
#include <easybind/bind.hpp>
struct PeerInfo; // forward declare or include the header
EASYBIND_NS_MODULE(my_pkg, m, false, {
nanobind::class_<PeerInfo>(m, "PeerInfo")
.def(nanobind::init<>())
.def_rw("peer_id", &PeerInfo::peer_id)
.def_rw("transport", &PeerInfo::transport);
});
3) Module entry point (shared-object boundary)
Use this only for the package that has its own .so and NB_MODULE entry point.
Do not pair it with EASYBIND_NS_MODULE for the same my_pkg name.
If you need to add bindings from another file, use EASYBIND_NS_MODULE_EXTEND
to extend the same module node instead.
#include <easybind/bind.hpp>
EASYBIND_NS_MODULE_SHARED_OBJECT(my_pkg, my_pkg, m, true, {
m.doc() = "my_pkg module";
});
4) Extend from another file
#include <easybind/bind.hpp>
EASYBIND_NS_MODULE_EXTEND(my_pkg, m, {
m.def("ping", [] { return "pong"; });
});
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easybind-0.2.0.tar.gz.
File metadata
- Download URL: easybind-0.2.0.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
380ec3baa06511dadd281e7a4dfffe3bf63b542540f3d351137ce22be1e1131e
|
|
| MD5 |
fdbc7f7b4d3632cf6de0050199a43255
|
|
| BLAKE2b-256 |
b246020fdfc0e4de3780d0c1e7e308215d008b49d63fcc31b3726eea6ebb1a35
|
File details
Details for the file easybind-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: easybind-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 289.9 kB
- Tags: CPython 3.14, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc12d2a8fa9dc0f5a68753cc28151ffff9a394bcdb75b68fa68b993580776898
|
|
| MD5 |
92ca9f88cae2c10980370b68b7ff523b
|
|
| BLAKE2b-256 |
3349477cad189e3cf33d6eda39ede1b32e573856607460a8e2f0d795f4145cd9
|
File details
Details for the file easybind-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: easybind-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 289.8 kB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4203900cbe9733548463d2a142d227f1704da0fee92950d6cf5c3bd0a1dfd6b4
|
|
| MD5 |
597809848ff3b8a3a2bdf5fbe863c2bb
|
|
| BLAKE2b-256 |
cecaaf1d41e951c24f8c38fff325ee90548152c337f980e3ab66c002d70917fa
|
File details
Details for the file easybind-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: easybind-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 289.8 kB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b8f90aba945af41630fdd0dc0aa73e63ae24a4fd67d367b815988b0e7509060
|
|
| MD5 |
965d640d6db9af00d9e1d3606bf642c0
|
|
| BLAKE2b-256 |
8bc403bd766a7dd7ba84d224a89bcbdddd6447e4bab629f26a063edec023e398
|
File details
Details for the file easybind-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: easybind-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 290.2 kB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2567474dedfab5f2b4127d03c72b0b81862b2ffba91e39a349114749b7e3f5b4
|
|
| MD5 |
9d580f7cbedcc18aa2868fc2aa1ca44b
|
|
| BLAKE2b-256 |
314b48f0ffe19f416281fa48722e85ae27b03f0578204f1550fb756dba864935
|