You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.7 KiB

  1. .. image:: pybind11-logo.png
  2. About this project
  3. ==================
  4. **pybind11** is a lightweight header-only library that exposes C++ types in Python
  5. and vice versa, mainly to create Python bindings of existing C++ code. Its
  6. goals and syntax are similar to the excellent `Boost.Python`_ library by David
  7. Abrahams: to minimize boilerplate code in traditional extension modules by
  8. inferring type information using compile-time introspection.
  9. .. _Boost.Python: http://www.boost.org/doc/libs/release/libs/python/doc/index.html
  10. The main issue with Boost.Python—and the reason for creating such a similar
  11. project—is Boost. Boost is an enormously large and complex suite of utility
  12. libraries that works with almost every C++ compiler in existence. This
  13. compatibility has its cost: arcane template tricks and workarounds are
  14. necessary to support the oldest and buggiest of compiler specimens. Now that
  15. C++11-compatible compilers are widely available, this heavy machinery has
  16. become an excessively large and unnecessary dependency.
  17. Think of this library as a tiny self-contained version of Boost.Python with
  18. everything stripped away that isn't relevant for binding generation. Without
  19. comments, the core header files only require ~2.5K lines of code and depend on
  20. Python (2.7 or 3.x) and the C++ standard library. This compact implementation
  21. was possible thanks to some of the new C++11 language features (specifically:
  22. tuples, lambda functions and variadic templates). Since its creation, this
  23. library has grown beyond Boost.Python in many ways, leading to dramatically
  24. simpler binding code in many common situations.
  25. Core features
  26. *************
  27. The following core C++ features can be mapped to Python
  28. - Functions accepting and returning custom data structures per value, reference, or pointer
  29. - Instance methods and static methods
  30. - Overloaded functions
  31. - Instance attributes and static attributes
  32. - Exceptions
  33. - Enumerations
  34. - Iterators and ranges
  35. - Callbacks
  36. - Custom operators
  37. - STL data structures
  38. - Smart pointers with reference counting like ``std::shared_ptr``
  39. - Internal references with correct reference counting
  40. - C++ classes with virtual (and pure virtual) methods can be extended in Python
  41. Goodies
  42. *******
  43. In addition to the core functionality, pybind11 provides some extra goodies:
  44. - It is possible to bind C++11 lambda functions with captured variables. The
  45. lambda capture data is stored inside the resulting Python function object.
  46. - pybind11 uses C++11 move constructors and move assignment operators whenever
  47. possible to efficiently transfer custom data types.
  48. - It's easy to expose the internal storage of custom data types through
  49. Pythons' buffer protocols. This is handy e.g. for fast conversion between
  50. C++ matrix classes like Eigen and NumPy without expensive copy operations.
  51. - pybind11 can automatically vectorize functions so that they are transparently
  52. applied to all entries of one or more NumPy array arguments.
  53. - Python's slice-based access and assignment operations can be supported with
  54. just a few lines of code.
  55. - Everything is contained in just a few header files; there is no need to link
  56. against any additional libraries.
  57. - Binaries are generally smaller by a factor of 2 or more compared to
  58. equivalent bindings generated by Boost.Python.
  59. - When supported by the compiler, two new C++14 features (relaxed constexpr and
  60. return value deduction) are used to precompute function signatures at compile
  61. time, leading to smaller binaries.
  62. - With little extra effort, C++ types can be pickled and unpickled similar to
  63. regular Python objects.
  64. Supported compilers
  65. *******************
  66. 1. Clang/LLVM (any non-ancient version with C++11 support)
  67. 2. GCC (any non-ancient version with C++11 support)
  68. 3. Microsoft Visual Studio 2015 or newer
  69. 4. Intel C++ compiler v15 or newer