blob: 6763c06fd0c91964d9e50c55ef0de96bb17a1a79 [file] [log] [blame] [view]
Wenzel Jakob937d6462016-03-01 15:41:02 +01001![pybind11 logo](https://github.com/pybind/pybind11/raw/master/docs/pybind11-logo.png)
Wenzel Jakob10d992e2015-08-04 13:59:51 +02002
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 Jakob937d6462016-03-01 15:41:02 +01006[![Build Status](https://travis-ci.org/pybind/pybind11.svg?branch=master)](https://travis-ci.org/pybind/pybind11)
7[![Build status](https://ci.appveyor.com/api/projects/status/riaj54pn4h08xy40?svg=true)](https://ci.appveyor.com/project/pybind/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 Jakob678d7872016-01-17 22:36:41 +010025everything stripped away that isn't relevant for binding generation. Without
26comments, the core header files only require ~2.5K lines of code and depend on
27Python (2.7 or 3.x) and the C++ standard library. This compact implementation
28was possible thanks to some of the new C++11 language features (specifically:
29tuples, lambda functions and variadic templates). Since its creation, this
30library has grown beyond Boost.Python in many ways, leading to dramatically
31simpler binding code in 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
Wenzel Jakob6eb11da2016-01-17 22:36:36 +010077- When supported by the compiler, two new C++14 features (relaxed constexpr and
Wenzel Jakob240e4042016-02-20 21:00:45 +010078 return value deduction) are used to precompute function signatures at compile
Wenzel Jakob66c9a402016-01-17 22:36:36 +010079 time, leading to smaller binaries.
80
Wenzel Jakob240e4042016-02-20 21:00:45 +010081## Supported compilers
82
831. Clang/LLVM (any non-ancient version with C++11 support)
842. GCC (any non-ancient version with C++11 support)
853. Microsoft Visual Studio 2015 or newer
864. Intel C++ compiler v15 or newer
87
Wenzel Jakob74982c32016-03-01 12:45:08 +010088## About
89
90This project was created by [Wenzel Jakob](https://www.mitsuba-renderer.org/~wenzel/).
91Significant features and/or improvements to the code were contributed by
92Jonas Adler,
93Sylvain Corlay,
94Axel Huebl,
95Johan Mabille, and
96Tomasz Miąsko.
97
Wenzel Jakob24fe0902015-12-05 14:41:25 +010098### License
99
100pybind11 is provided under a BSD-style license that can be found in the
Wenzel Jakob1ae77fe2016-01-17 22:36:43 +0100101``LICENSE`` file. By using, distributing, or contributing to this project,
Wenzel Jakob24fe0902015-12-05 14:41:25 +0100102you agree to the terms and conditions of this license.