Skip to content
nptmpl @ nguyenpanda.com v1.1.0

cpp/python-c-binding

Professional high-performance template for creating Python extension modules using the native Python C API (<Python.h>) with Meson and Ninja. Includes advanced examples of keyword argument handling, sequence processing (std::vector mapping), and dictionary creation. Features automated venv management with 'uv' support.

Downloads today

0

Total downloads

1

Last updated

2026-05-26

v1.0.0 is latest

Versions

1

0 removed

Download v1.0.0

Clone with the CLI

nptmpl clone http://nptmpl.nguyenpanda.com/api/v1/templates/cpp/python-c-binding

No @version resolves to the latest release (v1.0.0).

Maintainer nguyenpanda License MIT

Downloads over time

0 in the selected range

Files 14
README.md

Python C/C++ API Professional Template (Meson Version)

A high-performance, modern template for creating Python extension modules using the native Python C API (<Python.h>) with the Meson build system and Ninja backend.

Features

  • Meson & Ninja: The fastest and most modern build system for C/C++ projects.
  • Modern C++: Pre-configured for C++20.
  • uv Support: High-speed environment management (with fallback to standard Python).
  • Hybrid Parallelism Friendly: Easily extensible to support OpenMP or other libraries via Meson dependencies.
  • Complex Examples Included:
    • Keyword argument handling (PyArg_ParseTupleAndKeywords).
    • Python sequence processing (List to std::vector).
    • Dictionary creation and mapping.
    • Custom Exception handling with proper reference counting.

Directory Structure

  • cppmodule/: The C++ extension source code.
    • src/: Implementation files (.cpp).
    • include/: Header files (.h).
  • lib/: Third-party C/C++ libraries (gitkept).
  • tests/: Python unit tests using pytest.
  • main.py: Entry point for quick demonstration and manual testing.
  • meson.build: The Meson build configuration.
  • Makefile: Convenient wrapper for environment and build management.

Getting Started

1. Initialize Environment

The Makefile automatically detects uv or standard Python to create a virtual environment and install build tools (Meson, Ninja).

make venv

2. Configure & Build

make setup
make build

3. Run Demonstration

make run

4. Run Tests

make tests

Makefile Targets

Target Description
venv Create virtual environment and install all dependencies
setup Initialize the Meson build directory (build_meson/)
build Compile the extension module using Ninja
run Run main.py
tests Run unit tests using pytest
clean Remove build artifacts
reset Deep clean: remove venv and all artifacts

Author

nguyenpanda
Email: [email protected]
Website: https://nguyenpanda.com

License

MIT License

Version history

Every release ever published, newest first.

v1.0.0 latest 1 downloads

Published 2026-05-26 08:52:33 by nguyenpanda

Related templates