blob: 96560e46e45de803b22691d9049a57ac0a25626f [file] [log] [blame] [view]
Wenzel Jakob10d992e2015-08-04 13:59:51 +02001![pybind11 logo](https://github.com/wjakob/pybind11/raw/master/logo.png)
2
3# pybind11 — Seamless operability between C++11 and Python
Wenzel Jakob38bd7112015-07-05 20:05:44 +02004
Wenzel Jakob28f98aa2015-10-13 02:57:16 +02005[![Documentation Status](https://readthedocs.org/projects/pybind11/badge/?version=latest)](http://pybind11.readthedocs.org/en/latest/?badge=latest)
Wenzel Jakobfab881c2015-10-18 17:04:24 +02006[![Build Status](https://travis-ci.org/wjakob/pybind11.svg?branch=master)](https://travis-ci.org/wjakob/pybind11)
7[![Build status](https://ci.appveyor.com/api/projects/status/rfbxqkgxkcrxdu0f?svg=true)](https://ci.appveyor.com/project/wjakob/pybind11)
Wenzel Jakob3b806d42015-10-11 16:29:35 +02008
Wenzel Jakob7641c1d2015-10-18 14:48:24 +02009**pybind11** is a lightweight header-only library that exposes C++ types in Python
Wenzel Jakob38bd7112015-07-05 20:05:44 +020010and vice versa, mainly to create Python bindings of existing C++ code. Its
11goals and syntax are similar to the excellent
12[Boost.Python](http://www.boost.org/doc/libs/1_58_0/libs/python/doc/) library
13by David Abrahams: to minimize boilerplate code in traditional extension
14modules by inferring type information using compile-time introspection.
15
16The main issue with Boost.Pythonand the reason for creating such a similar
17projectis Boost. Boost is an enormously large and complex suite of utility
18libraries that works with almost every C++ compiler in existence. This
19compatibility has its cost: arcane template tricks and workarounds are
20necessary to support the oldest and buggiest of compiler specimens. Now that
21C++11-compatible compilers are widely available, this heavy machinery has
22become an excessively large and unnecessary dependency.
23
24Think of this library as a tiny self-contained version of Boost.Python with
Wenzel Jakob7641c1d2015-10-18 14:48:24 +020025everything stripped away that isn't relevant for binding generation. The core
Wenzel Jakob66c9a402016-01-17 22:36:36 +010026header files only require ~3K lines of code and depend on Python (2.7 or 3.x)
Wenzel Jakob7641c1d2015-10-18 14:48:24 +020027and the C++ standard library. This compact implementation was possible thanks
Wenzel Jakob66c9a402016-01-17 22:36:36 +010028to some of the new C++11 language features (specifically: tuples, lambda
29functions and variadic templates). Since its creation, this library has grown
30beyond Boost.Python in many ways, leading to dramatically simpler binding code
31in many common situations.
Wenzel Jakob28f98aa2015-10-13 02:57:16 +020032
33Tutorial and reference documentation is provided at
34[http://pybind11.readthedocs.org/en/latest](http://pybind11.readthedocs.org/en/latest).
Wenzel Jakob38bd7112015-07-05 20:05:44 +020035
36## Core features
Wenzel Jakob28f98aa2015-10-13 02:57:16 +020037pybind11 can map the following core C++ features to Python
Wenzel Jakob38bd7112015-07-05 20:05:44 +020038
39- Functions accepting and returning custom data structures per value, reference, or pointer
40- Instance methods and static methods
41- Overloaded functions
42- Instance attributes and static attributes
43- Exceptions
44- Enumerations
45- Callbacks
46- Custom operators
47- STL data structures
48- Smart pointers with reference counting like `std::shared_ptr`
49- Internal references with correct reference counting
Wenzel Jakoba2f6fde2015-10-01 16:46:03 +020050- C++ classes with virtual (and pure virtual) methods can be extended in Python
Wenzel Jakob38bd7112015-07-05 20:05:44 +020051
52## Goodies
53In addition to the core functionality, pybind11 provides some extra goodies:
54
Wenzel Jakob28f98aa2015-10-13 02:57:16 +020055- pybind11 uses C++11 move constructors and move assignment operators whenever
56 possible to efficiently transfer custom data types.
57
58- It is possible to bind C++11 lambda functions with captured variables. The
59 lambda capture data is stored inside the resulting Python function object.
60
Wenzel Jakob38bd7112015-07-05 20:05:44 +020061- It's easy to expose the internal storage of custom data types through
62 Pythons' buffer protocols. This is handy e.g. for fast conversion between
63 C++ matrix classes like Eigen and NumPy without expensive copy operations.
64
Wenzel Jakobd4258ba2015-07-26 16:33:49 +020065- pybind11 can automatically vectorize functions so that they are transparently
66 applied to all entries of one or more NumPy array arguments.
67
Wenzel Jakob38bd7112015-07-05 20:05:44 +020068- Python's slice-based access and assignment operations can be supported with
69 just a few lines of code.
70
John Kirkham648e1962015-12-04 17:51:42 -050071- Everything is contained in just a few header files; there is no need to link
Wenzel Jakob7641c1d2015-10-18 14:48:24 +020072 against any additional libraries.
Wenzel Jakob24fe0902015-12-05 14:41:25 +010073
Wenzel Jakob66c9a402016-01-17 22:36:36 +010074- Binaries are generally smaller by a factor of 2 or more compared to
75 equivalent bindings generated by Boost.Python.
76
77- When supported by the compiler, two new C++14 features (relaxed constexpr,
78 return value deduction) such as are used to do additional work at compile
79 time, leading to smaller binaries.
80
Wenzel Jakob24fe0902015-12-05 14:41:25 +010081### License
82
83pybind11 is provided under a BSD-style license that can be found in the
84``LICENSE.txt`` file. By using, distributing, or contributing to this project,
85you agree to the terms and conditions of this license.