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