{"library":"pybindgen","title":"PyBindGen","description":"PyBindGen is a code generator that produces C++ source files to create Python bindings for C/C++ libraries. It helps expose C/C++ functions and classes to Python without writing manual wrapper code. As of version 0.22.1, it's an active project with a slow but steady release cadence, often tied to changes in `ns-3` (its primary consumer).","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pybindgen"],"cli":{"name":"pybindgen","version":"sh: 1: pybindgen: not found"}},"imports":["from pybindgen import Module","from pybindgen import Parameter","from pybindgen import ReturnValue"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from pybindgen import Module, Function, Parameter, ReturnValue\n\ndef generate_bindings(filename):\n    module = Module('my_bindings_module', cpp_namespace='MyCppNamespace')\n\n    # Example: Bind a simple C++ function 'int add(int a, int b);'\n    module.add_function(\n        'add',\n        retval=ReturnValue.copy(Parameter.new('int', 'a')),\n        params=[Parameter.new('int', 'a'), Parameter.new('int', 'b')]\n    )\n\n    # Generate the C++ binding code\n    module.generate(filename)\n    print(f\"Generated binding code to {filename}\")\n\n# To run this, you would typically integrate it into a setup.py or build script\n# For a standalone example:\n# generate_bindings('my_bindings_module.cc')","lang":"python","description":"This quickstart demonstrates how to define a simple Python module that wraps a C++ function `add(int, int)`. The `generate_bindings` function creates a `Module` instance, adds a function definition with its parameters and return value, and then generates the C++ source file `my_bindings_module.cc`. This generated file then needs to be compiled into a Python extension module using a C++ compiler and a build system like `setuptools` or `waf`.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}