Example package for the nanobind-uv-template GitHub template
Project description
nanobind-uv-template
Batteries-included GitHub template for a Python package whose core is C++: nanobind, CMake, and uv — separate core/ and bindings/; the sample project is nbuv.
The Python build backend isscikit-build-core; uv drives it transparently during uv sync / uv build.
Template repository: https://github.com/touken928/nanobind-uv-template
nanobind-uv-templateis only the GitHub template's name. Everything inside the repo — the Python distribution, the import name, the C++ namespace, the library target, the CMake project — is callednbuv. Renamenbuvto whatever you want after cloning.
Use this template
-
Click "Use this template" → "Create a new repository" on GitHub, or
git clone https://github.com/touken928/nanobind-uv-template my-pkg. -
Rename the example project
nbuvto your own name.nbuvonly appears in these places:# rename on disk git mv src/nbuv src/<your_pkg> # list every file that still references `nbuv` rg -l '\bnbuv\b' # pyproject.toml, CMakeLists.txt, core/**, bindings/**, # src/<your_pkg>/__init__.py, tests/*, README*
-
Update
pyproject.toml:[project].name(currentlynbuv),authors,urls,version, etc. -
Run
uv syncand you're off.
Layout
nanobind-uv-template/
├── CMakeLists.txt # top-level, wires core/ + bindings/
├── pyproject.toml # scikit-build-core backend + project metadata
│
├── core/ # (1) standalone C++ library — nbuv::core
│ ├── CMakeLists.txt # pure C++, no Python / nanobind dependency
│ ├── include/nbuv/
│ │ ├── math.hpp
│ │ └── greeter.hpp
│ └── src/
│ ├── math.cpp
│ └── greeter.cpp
│
├── bindings/ # (2) nanobind glue — nbuv._core
│ ├── CMakeLists.txt # nanobind_add_module + link nbuv::core
│ └── _core.cpp # argument / return-value conversion only
│
├── src/nbuv/ # (3) Python package facade
│ ├── __init__.py # `from ._core import *` — add Python code here
│ └── py.typed
│
└── tests/
└── test_basic.py
Dependencies flow one way: core ← bindings ← src/nbuv.
core/holds all business logic in plain C++17. It has no knowledge of Python and can be reused by any other CMake project viaadd_subdirectory.bindings/is intentionally thin. It only#includes thenbuv/*.hppheaders and callsm.def(...)/nb::class_<...>(...)— no logic.src/nbuv/__init__.pyre-exports the compiled_coresubmodule as the package's public API. This is also where you drop any pure-Python helpers.
Requirements
- C++17 compiler (Clang 8+ / GCC 8+ / MSVC 2019+)
- CMake 3.15+ (fetched automatically by
scikit-build-coreif missing) - uv
Quick start
# 1. Create the venv, compile the extension, install in editable mode.
uv sync
# 2. Try it out.
uv run python -c "import nbuv; print(nbuv.add(2, 3), nbuv.Greeter('uv').greet())"
# 3. Run the test suite.
uv run --group dev pytest
# 4. Build distributable artifacts (wheel + sdist) into dist/.
uv build
Thanks to [tool.uv] cache-keys in pyproject.toml, changes under
core/** / bindings/** / CMakeLists.txt automatically trigger a rebuild
on the next uv sync / uv run.
The wheel is tagged cp312-abi3 (Python stable ABI), so a single artifact
works across Python 3.12 and every later 3.x release.
Releasing
Pushing a v* tag runs two workflows in parallel:
| Workflow | What it does |
|---|---|
.github/workflows/release.yml |
Builds wheels + sdist and attaches them to a GitHub Release. |
.github/workflows/pypi.yml |
Builds wheels + sdist and uploads them to PyPI (pip install nbuv). |
Configure PyPI Trusted Publishing once (GitHub workflow pypi.yml, environment pypi). On tag push, the PyPI job is skipped if the tag name contains - (treated as a pre-release). Use a repository secret PYPI_API_TOKEN instead if you do not use Trusted Publishing—see the comments in pypi.yml.
uv version X.Y.Z # bump version in pyproject.toml
git commit -am "Release vX.Y.Z"
git tag vX.Y.Z
git push && git push --tags
From PyPI (after a successful upload):
pip install nbuv
From GitHub Releases — use a direct asset URL (copy the exact .whl name from the release; it embeds the version and platform tags):
pip install https://github.com/touken928/nanobind-uv-template/releases/latest/download/<wheel-file>
After each release, wheel filenames change with the version; check Releases if you install by URL.
Using core/ as a plain C++ library
core/ is self-contained and has no dependency on Python or nanobind.
# Build it standalone (e.g. for C++ unit tests or CI without Python).
cmake -S core -B build-core && cmake --build build-core -j
# Or pull it into any other CMake project.
add_subdirectory(path/to/nanobind-uv-template/core)
target_link_libraries(my_app PRIVATE nbuv::core)
Extending the template
- Add C++ functionality: put headers in
core/include/nbuv/and sources incore/src/, then append them toadd_library(nbuv_core ...)incore/CMakeLists.txt. - Expose it to Python: add
m.def(...)/nb::class_<...>(...)calls inbindings/_core.cpp. Thefrom ._core import *in__init__.pypicks them up automatically. - Add pure-Python helpers: drop them in
src/nbuv/__init__.pyor new submodules beside it. - Add a C++ dependency:
find_package/FetchContentincore/CMakeLists.txt, thentarget_link_libraries(nbuv_core PRIVATE ...). The binding layer inherits it transitively. - Add a Python dependency:
uv add <pkg>; dev-only withuv add --group dev <pkg>.
References
License
Licensed under the Apache License, Version 2.0. See that file for the full text.
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 nbuv-0.1.1.tar.gz.
File metadata
- Download URL: nbuv-0.1.1.tar.gz
- Upload date:
- Size: 25.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
530ada301cc4ab9fc533589b3a79c2bd7e450c141106d26aad163a9cf2d8d742
|
|
| MD5 |
cdd87aa8500cd868a10d54dd4b316482
|
|
| BLAKE2b-256 |
58ba485dc58eb332ad3d4337c62f5a88046671f2b067490fe575d158a67f6e87
|
Provenance
The following attestation bundles were made for nbuv-0.1.1.tar.gz:
Publisher:
pypi.yml on touken928/nanobind-uv-template
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbuv-0.1.1.tar.gz -
Subject digest:
530ada301cc4ab9fc533589b3a79c2bd7e450c141106d26aad163a9cf2d8d742 - Sigstore transparency entry: 1326285765
- Sigstore integration time:
-
Permalink:
touken928/nanobind-uv-template@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/touken928
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nbuv-0.1.1-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: nbuv-0.1.1-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 58.5 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c9d9155cc3f975f7b37580bcc54f94477cd40d72af18511d3de6bd530caf9a1
|
|
| MD5 |
1165d64cef45464b4ae7bc06545d6b64
|
|
| BLAKE2b-256 |
62d0c95156b4ad45d44c5524d3fc026e1aa2e1635fc76038894497d7b43103bb
|
Provenance
The following attestation bundles were made for nbuv-0.1.1-cp312-abi3-win_amd64.whl:
Publisher:
pypi.yml on touken928/nanobind-uv-template
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbuv-0.1.1-cp312-abi3-win_amd64.whl -
Subject digest:
7c9d9155cc3f975f7b37580bcc54f94477cd40d72af18511d3de6bd530caf9a1 - Sigstore transparency entry: 1326286040
- Sigstore integration time:
-
Permalink:
touken928/nanobind-uv-template@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/touken928
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nbuv-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: nbuv-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 60.8 kB
- Tags: CPython 3.12+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
878a7e1604325d44bd4f38d5f6d80b12a31ec85058cf4552cfbe52c6bfafb8d6
|
|
| MD5 |
05adc91f24a64fe9305da40293781881
|
|
| BLAKE2b-256 |
6387ef21300cda0a7fe616f3ad6cba80048d35adf13778b0fdbd5f47ab6fd9c2
|
Provenance
The following attestation bundles were made for nbuv-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl:
Publisher:
pypi.yml on touken928/nanobind-uv-template
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbuv-0.1.1-cp312-abi3-manylinux_2_34_x86_64.whl -
Subject digest:
878a7e1604325d44bd4f38d5f6d80b12a31ec85058cf4552cfbe52c6bfafb8d6 - Sigstore transparency entry: 1326285851
- Sigstore integration time:
-
Permalink:
touken928/nanobind-uv-template@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/touken928
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nbuv-0.1.1-cp312-abi3-macosx_15_0_arm64.whl.
File metadata
- Download URL: nbuv-0.1.1-cp312-abi3-macosx_15_0_arm64.whl
- Upload date:
- Size: 50.9 kB
- Tags: CPython 3.12+, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43d8363268721323e102b8511c6b1303c5b089f016667e71f734060a7890a53d
|
|
| MD5 |
3c293daf7e6098392807998d1882a7a0
|
|
| BLAKE2b-256 |
a65c9b4040deda371723636d41a3080672ad4bdf7def649413e5bf3138fad77a
|
Provenance
The following attestation bundles were made for nbuv-0.1.1-cp312-abi3-macosx_15_0_arm64.whl:
Publisher:
pypi.yml on touken928/nanobind-uv-template
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nbuv-0.1.1-cp312-abi3-macosx_15_0_arm64.whl -
Subject digest:
43d8363268721323e102b8511c6b1303c5b089f016667e71f734060a7890a53d - Sigstore transparency entry: 1326285930
- Sigstore integration time:
-
Permalink:
touken928/nanobind-uv-template@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/touken928
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@bbb7daef9a36400e9f46967c4b5729756c5501d6 -
Trigger Event:
push
-
Statement type: