BoB robotics
The Brains on Board robotics library
pybind11 Namespace Reference

glibc defines I as a macro which breaks things, e.g., boost template names More...

Classes

struct  arg
 
struct  arg_v
 
class  args
 
struct  arithmetic
 Annotation to mark enums as an arithmetic type. More...
 
class  array
 
class  array_t
 
struct  base
 Annotation indicating that a class derives from another given type. More...
 
class  bool_
 
class  buffer
 
struct  buffer_info
 Information record describing a Python buffer object. More...
 
struct  buffer_protocol
 Annotation which enables the buffer protocol for a type. More...
 
class  bytearray
 
class  bytes
 
struct  call_guard
 
struct  call_guard< T >
 
struct  call_guard< T, Ts... >
 
struct  call_guard<>
 
class  capsule
 
class  class_
 
class  cpp_function
 Wraps an arbitrary C++ function/method/lambda function/.. into a callable Python object. More...
 
struct  custom_type_setup
 
class  dict
 
struct  doc
 Annotation for documentation. More...
 
class  dtype
 
struct  dynamic_attr
 Annotation which enables dynamic attributes, i.e. adds __dict__ to a class. More...
 
class  ellipsis
 
class  enum_
 Binds C++ enumerations and enumeration classes to Python. More...
 
struct  error_scope
 RAII wrapper that temporarily clears any Python error state. More...
 
class  exception
 
class  float_
 
struct  format_descriptor
 
struct  format_descriptor< char[N]>
 
struct  format_descriptor< std::array< char, N > >
 
struct  format_descriptor< std::complex< T >, detail::enable_if_t< std::is_floating_point< T >::value > >
 
struct  format_descriptor< T, detail::enable_if_t< detail::array_info< T >::is_array > >
 
struct  format_descriptor< T, detail::enable_if_t< detail::is_pod_struct< T >::value > >
 
struct  format_descriptor< T, detail::enable_if_t< std::is_arithmetic< T >::value > >
 
struct  format_descriptor< T, detail::enable_if_t< std::is_enum< T >::value > >
 
class  function
 
class  gil_scoped_acquire
 
class  gil_scoped_release
 
class  handle
 
class  int_
 
struct  is_final
 Annotation for classes that cannot be subclassed. More...
 
struct  is_method
 Annotation for methods. More...
 
struct  is_operator
 Annotation for operators. More...
 
class  iterable
 
class  iterator
 
struct  keep_alive
 Keep patient alive while nurse lives. More...
 
struct  kw_only
 
class  kwargs
 
class  list
 
class  memoryview
 
struct  metaclass
 Annotation which requests that a special metaclass is created for a type. More...
 
class  module_
 Wrapper for Python extension modules. More...
 
struct  module_local
 Annotation that marks a class as local to the module: More...
 
struct  multiple_inheritance
 Annotation indicating that a class is involved in a multiple inheritance relationship. More...
 
struct  name
 Annotation for function names. More...
 
struct  nodelete
 Dummy destructor wrapper that can be used to expose classes with a private destructor. More...
 
class  none
 
class  object
 
class  options
 
struct  overload_cast
 
struct  polymorphic_type_hook
 
struct  polymorphic_type_hook< itype, detail::enable_if_t< std::is_base_of< Animal, itype >::value > >
 
struct  polymorphic_type_hook_base
 
struct  polymorphic_type_hook_base< itype, detail::enable_if_t< std::is_polymorphic< itype >::value > >
 
struct  pos_only
 
struct  prepend
 Mark a function for addition at the beginning of the existing overload chain instead of the end. More...
 
struct  scope
 Annotation for parent scope. More...
 
class  scoped_estream_redirect
 
class  scoped_interpreter
 
class  scoped_ostream_redirect
 
class  sequence
 
class  set
 
struct  sibling
 Annotation indicating that a function is an overload associated with a given "sibling". More...
 
class  slice
 
class  staticmethod
 
class  str
 
class  tuple
 
class  type
 
class  weakref
 

Typedefs

template<typename >
using arg_t = arg_v
 Alias for backward compatibility – to be removed in version 2.0.
 
using ssize_t = Py_ssize_t
 
using size_t = std::size_t
 
using ExceptionTranslator = void(*)(std::exception_ptr)
 
using EigenDStride = Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic >
 
template<typename MatrixType >
using EigenDRef = Eigen::Ref< MatrixType, 0, EigenDStride >
 
template<typename MatrixType >
using EigenDMap = Eigen::Map< MatrixType, 0, EigenDStride >
 
using module = module_
 

Enumerations

enum class  return_value_policy : uint8_t {
  automatic = 0 , automatic_reference , take_ownership , copy ,
  move , reference , reference_internal
}
 Approach used to cast a previously unknown C++ instance into a Python object. More...
 
enum  eval_mode { eval_expr , eval_single_statement , eval_statements }
 

Functions

template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
cast (const handle &handle)
 
template<typename T , detail::enable_if_t<!detail::is_pyobject< T >::value, int > = 0>
object cast (T &&value, return_value_policy policy=return_value_policy::automatic_reference, handle parent=handle())
 
template<typename T >
detail::enable_if_t<!detail::move_never< T >::value, T > move (object &&obj)
 
template<typename T >
detail::enable_if_t< detail::move_always< T >::value, T > cast (object &&object)
 
template<typename T >
detail::enable_if_t< detail::move_if_unreferenced< T >::value, T > cast (object &&object)
 
template<typename T >
detail::enable_if_t< detail::move_never< T >::value, T > cast (object &&object)
 
cast_error cast_error_unable_to_convert_call_arg (const std::string &name, const std::string &type)
 
template<return_value_policy policy = return_value_policy::automatic_reference>
tuple make_tuple ()
 
template<return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
tuple make_tuple (Args &&... args_)
 
constexpr arg operator""_a (const char *name, size_t)
 
template<typename IntType >
ssize_t ssize_t_cast (const IntType &val)
 
class __attribute__((visibility("default"))) stop_iteration class __attribute__((visibility("default"))) index_error class __attribute__((visibility("default"))) key_error class __attribute__((visibility("default"))) value_error class __attribute__((visibility("default"))) type_error class __attribute__((visibility("default"))) buffer_error class __attribute__((visibility("default"))) import_error class __attribute__((visibility("default"))) attribute_error class __attribute__((visibility("default"))) cast_error class __attribute__((visibility("default"))) reference_cast_error __attribute__ ((noinline)) inline void pybind11_fail(const char *reason)
 Thrown when pybind11::cast or handle::call fail due to a type casting error. More...
 
template<typename T >
T & get_or_create_shared_data (const std::string &name)
 
void initialize_interpreter (bool init_signal_handlers=true, int argc=0, const char *const *argv=nullptr, bool add_program_dir_to_path=true)
 
void finalize_interpreter ()
 
template<eval_mode mode = eval_expr>
object eval (const str &expr, object global=globals(), object local=object())
 
template<eval_mode mode = eval_expr, size_t N>
object eval (const char(&s)[N], object global=globals(), object local=object())
 
void exec (const str &expr, object global=globals(), object local=object())
 
template<size_t N>
void exec (const char(&s)[N], object global=globals(), object local=object())
 
template<eval_mode mode = eval_statements>
object eval_file (str fname, object global=globals(), object local=object())
 
class_< detail::OstreamRedirectadd_ostream_redirect (module_ m, const std::string &name="ostream_redirect")
 
template<typename Return , typename... Args>
detail::vectorize_helper< Return(*)(Args...), Return, Args... > vectorize (Return(*f)(Args ...))
 
template<typename Func , detail::enable_if_t< detail::is_lambda< Func >::value, int > = 0>
auto vectorize (Func &&f) -> decltype(detail::vectorize_extractor(std::forward< Func >(f),(detail::function_signature_t< Func > *) nullptr))
 
template<typename Return , typename Class , typename... Args, typename Helper = detail::vectorize_helper<decltype(std::mem_fn(std::declval<Return (Class::*)(Args...)>())), Return, Class *, Args...>>
Helper vectorize (Return(Class::*f)(Args...))
 
dict globals ()
 
template<typename , typename F >
auto method_adaptor (F &&f) -> decltype(std::forward< F >(f))
 
template<typename Derived , typename Return , typename Class , typename... Args>
auto method_adaptor (Return(Class::*pmf)(Args...)) -> Return(Derived::*)(Args...)
 
template<typename... Args>
detail::initimpl::constructor< Args... > init ()
 Binds an existing constructor taking arguments Args...
 
template<typename... Args>
detail::initimpl::alias_constructor< Args... > init_alias ()
 
template<typename Func , typename Ret = detail::initimpl::factory<Func>>
Ret init (Func &&f)
 Binds a factory function as a constructor.
 
template<typename CFunc , typename AFunc , typename Ret = detail::initimpl::factory<CFunc, AFunc>>
Ret init (CFunc &&c, AFunc &&a)
 
template<typename GetState , typename SetState >
detail::initimpl::pickle_factory< GetState, SetState > pickle (GetState &&g, SetState &&s)
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename ValueType = typename detail::iterator_access<Iterator>::result_type, typename... Extra>
iterator make_iterator (Iterator first, Sentinel last, Extra &&... extra)
 Makes a python iterator from a first and past-the-end C++ InputIterator.
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename KeyType = typename detail::iterator_key_access<Iterator>::result_type, typename... Extra>
iterator make_key_iterator (Iterator first, Sentinel last, Extra &&...extra)
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename ValueType = typename detail::iterator_value_access<Iterator>::result_type, typename... Extra>
iterator make_value_iterator (Iterator first, Sentinel last, Extra &&...extra)
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator make_iterator (Type &value, Extra &&... extra)
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator make_key_iterator (Type &value, Extra &&... extra)
 
template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator make_value_iterator (Type &value, Extra &&... extra)
 
template<typename InputType , typename OutputType >
void implicitly_convertible ()
 
void register_exception_translator (ExceptionTranslator &&translator)
 
void register_local_exception_translator (ExceptionTranslator &&translator)
 
template<typename CppException >
exception< CppException > & register_exception (handle scope, const char *name, handle base=PyExc_Exception)
 
template<typename CppException >
exception< CppException > & register_local_exception (handle scope, const char *name, handle base=PyExc_Exception)
 
template<return_value_policy policy = return_value_policy::automatic_reference, typename... Args>
void print (Args &&...args)
 
template<class T >
function get_override (const T *this_ptr, const char *name)
 
 __attribute__ ((deprecated("get_type_overload has been deprecated"))) inline function get_type_overload(const void *this_ptr
 
template<class T >
function get_overload (const T *this_ptr, const char *name)
 
template<typename T >
reinterpret_borrow (handle h)
 
template<typename T >
reinterpret_steal (handle h)
 
template<typename T , detail::enable_if_t< std::is_base_of< object, T >::value, int > = 0>
bool isinstance (handle obj)
 
template<>
bool isinstance< handle > (handle)=delete
 
template<>
bool isinstance< object > (handle obj)
 
bool isinstance (handle obj, handle type)
 
bool hasattr (handle obj, handle name)
 
bool hasattr (handle obj, const char *name)
 
void delattr (handle obj, handle name)
 
void delattr (handle obj, const char *name)
 
object getattr (handle obj, handle name)
 
object getattr (handle obj, const char *name)
 
object getattr (handle obj, handle name, handle default_)
 
object getattr (handle obj, const char *name, handle default_)
 
void setattr (handle obj, handle name, handle value)
 
void setattr (handle obj, const char *name, handle value)
 
ssize_t hash (handle obj)
 
str operator""_s (const char *s, size_t size)
 
template<typename... Args>
constexpr bool args_are_all_keyword_or_ds ()
 
size_t len (handle h)
 Get the length of a Python object.
 
size_t len_hint (handle h)
 
str repr (handle h)
 
iterator iter (handle obj)
 
std::ostream & operator<< (std::ostream &os, const handle &obj)
 
template<typename Vector , typename holder_type = std::unique_ptr<Vector>, typename... Args>
class_< Vector, holder_type > bind_vector (handle scope, std::string const &name, Args &&... args)
 
template<typename Map , typename holder_type = std::unique_ptr<Map>, typename... Args>
class_< Map, holder_type > bind_map (handle scope, const std::string &name, Args &&... args)
 

Variables

const detail::type_infothis_type
 
const detail::type_info const char * name
 

Detailed Description

glibc defines I as a macro which breaks things, e.g., boost template names

Enumeration Type Documentation

◆ eval_mode

Enumerator
eval_expr 

Evaluate a string containing an isolated expression.

eval_single_statement 

Evaluate a string containing a single statement. Returns none.

eval_statements 

Evaluate a string containing a sequence of statement. Returns none.

◆ return_value_policy

enum class pybind11::return_value_policy : uint8_t
strong

Approach used to cast a previously unknown C++ instance into a Python object.

Enumerator
automatic 

This is the default return value policy, which falls back to the policy return_value_policy::take_ownership when the return value is a pointer. Otherwise, it uses return_value::move or return_value::copy for rvalue and lvalue references, respectively. See below for a description of what all of these different policies do.

automatic_reference 

As above, but use policy return_value_policy::reference when the return value is a pointer. This is the default conversion policy for function arguments when calling Python functions manually from C++ code (i.e. via handle::operator()). You probably won't need to use this.

take_ownership 

Reference an existing object (i.e. do not create a new copy) and take ownership. Python will call the destructor and delete operator when the object’s reference count reaches zero. Undefined behavior ensues when the C++ side does the same..

copy 

Create a new copy of the returned object, which will be owned by Python. This policy is comparably safe because the lifetimes of the two instances are decoupled.

move 

Use std::move to move the return value contents into a new instance that will be owned by Python. This policy is comparably safe because the lifetimes of the two instances (move source and destination) are decoupled.

reference 

Reference an existing object, but do not take ownership. The C++ side is responsible for managing the object’s lifetime and deallocating it when it is no longer used. Warning: undefined behavior will ensue when the C++ side deletes an object that is still referenced and used by Python.

reference_internal 

This policy only applies to methods and properties. It references the object without taking ownership similar to the above return_value_policy::reference policy. In contrast to that policy, the function or property’s implicit this argument (called the parent) is considered to be the the owner of the return value (the child). pybind11 then couples the lifetime of the parent to the child via a reference relationship that ensures that the parent cannot be garbage collected while Python is still using the child. More advanced variations of this scheme are also possible using combinations of return_value_policy::reference and the keep_alive call policy

Function Documentation

◆ __attribute__()

pybind11::__attribute__ ( (noinline)  ) const

Thrown when pybind11::cast or handle::call fail due to a type casting error.

Set the shared data that can be later recovered by get_shared_data().

Used internally

Returns a named pointer that is shared among all extension modules (using the same pybind11 version) running in the current interpreter. Names starting with underscores are reserved for internal usage. Returns nullptr if no matching entry was found.

◆ add_ostream_redirect()

class_< detail::OstreamRedirect > pybind11::add_ostream_redirect ( module_  m,
const std::string &  name = "ostream_redirect" 
)
inline

\rst This is a helper function to add a C++ redirect context manager to Python instead of using a C++ guard. To use it, add the following to your binding code:

.. code-block:: cpp

#include <pybind11/iostream.h>

...

py::add_ostream_redirect(m, "ostream_redirect");

You now have a Python context manager that redirects your output:

.. code-block:: python

with m.ostream_redirect():
    m.print_to_cout_function()

This manager can optionally be told which streams to operate on:

.. code-block:: python

with m.ostream_redirect(stdout=true, stderr=true):
    m.noisy_function_with_error_printing()

\endrst

◆ finalize_interpreter()

void pybind11::finalize_interpreter ( )
inline

\rst Shut down the Python interpreter. No pybind11 or CPython API functions can be called after this. In addition, pybind11 objects must not outlive the interpreter:

.. code-block:: cpp

{ // BAD
    py::initialize_interpreter();
    auto hello = py::str("Hello, World!");
    py::finalize_interpreter();
} // <-- BOOM, hello's destructor is called after interpreter shutdown

{ // GOOD
    py::initialize_interpreter();
    { // scoped
        auto hello = py::str("Hello, World!");
    } // <-- OK, hello is cleaned up properly
    py::finalize_interpreter();
}

{ // BETTER
    py::scoped_interpreter guard{};
    auto hello = py::str("Hello, World!");
}

.. warning::

The interpreter can be restarted by calling `initialize_interpreter` again.
Modules created using pybind11 can be safely re-initialized. However, Python
itself cannot completely unload binary extension modules and there are several
caveats with regard to interpreter restarting. All the details can be found
in the CPython documentation. In short, not all interpreter memory may be
freed, either due to reference cycles or user-created global data.

\endrst

◆ get_or_create_shared_data()

template<typename T >
T & pybind11::get_or_create_shared_data ( const std::string &  name)

Returns a typed reference to a shared data entry (by using get_shared_data()) if such entry exists. Otherwise, a new object of default-constructible type T is added to the shared data under the given name and a reference to it is returned.

◆ get_override()

template<class T >
function pybind11::get_override ( const T *  this_ptr,
const char *  name 
)

\rst Try to retrieve a python method by the provided name from the instance pointed to by the this_ptr.

:this_ptr: The pointer to the object the overridden method should be retrieved for. This should be the first non-trampoline class encountered in the inheritance chain. :name: The name of the overridden Python method to retrieve. :return: The Python method by this name from the object or an empty function wrapper. \endrst

◆ init()

template<typename CFunc , typename AFunc , typename Ret = detail::initimpl::factory<CFunc, AFunc>>
Ret pybind11::init ( CFunc &&  c,
AFunc &&  a 
)

Dual-argument factory function: the first function is called when no alias is needed, the second when an alias is needed (i.e. due to python-side inheritance). Arguments must be identical.

◆ init_alias()

template<typename... Args>
detail::initimpl::alias_constructor< Args... > pybind11::init_alias ( )

Like init<Args...>(), but the instance is always constructed through the alias class (even when not inheriting on the Python side).

◆ initialize_interpreter()

void pybind11::initialize_interpreter ( bool  init_signal_handlers = true,
int  argc = 0,
const char *const *  argv = nullptr,
bool  add_program_dir_to_path = true 
)
inline

\rst Initialize the Python interpreter. No other pybind11 or CPython API functions can be called before this is done; with the exception of PYBIND11_EMBEDDED_MODULE. The optional init_signal_handlers parameter can be used to skip the registration of signal handlers (see the Python documentation_ for details). Calling this function again after the interpreter has already been initialized is a fatal error.

If initializing the Python interpreter fails, then the program is terminated. (This is controlled by the CPython runtime and is an exception to pybind11's normal behavior of throwing exceptions on errors.)

The remaining optional parameters, argc, argv, and add_program_dir_to_path are used to populate sys.argv and sys.path. See the |PySys_SetArgvEx documentation|_ for details.

.. _Python documentation: https://docs.python.org/3/c-api/init.html#c.Py_InitializeEx .. |PySys_SetArgvEx documentation| replace:: PySys_SetArgvEx documentation .. _PySys_SetArgvEx documentation: https://docs.python.org/3/c-api/init.html#c.PySys_SetArgvEx \endrst

◆ make_iterator()

template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator pybind11::make_iterator ( Type &  value,
Extra &&...  extra 
)

Makes an iterator over values of an stl container or other container supporting std::begin()/std::end()

◆ make_key_iterator() [1/2]

template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename KeyType = typename detail::iterator_key_access<Iterator>::result_type, typename... Extra>
iterator pybind11::make_key_iterator ( Iterator  first,
Sentinel  last,
Extra &&...  extra 
)

Makes a python iterator over the keys (.first) of a iterator over pairs from a first and past-the-end InputIterator.

◆ make_key_iterator() [2/2]

template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator pybind11::make_key_iterator ( Type &  value,
Extra &&...  extra 
)

Makes an iterator over the keys (.first) of a stl map-like container supporting std::begin()/std::end()

◆ make_value_iterator() [1/2]

template<return_value_policy Policy = return_value_policy::reference_internal, typename Iterator , typename Sentinel , typename ValueType = typename detail::iterator_value_access<Iterator>::result_type, typename... Extra>
iterator pybind11::make_value_iterator ( Iterator  first,
Sentinel  last,
Extra &&...  extra 
)

Makes a python iterator over the values (.second) of a iterator over pairs from a first and past-the-end InputIterator.

◆ make_value_iterator() [2/2]

template<return_value_policy Policy = return_value_policy::reference_internal, typename Type , typename... Extra>
iterator pybind11::make_value_iterator ( Type &  value,
Extra &&...  extra 
)

Makes an iterator over the values (.second) of a stl map-like container supporting std::begin()/std::end()

◆ method_adaptor()

template<typename , typename F >
auto pybind11::method_adaptor ( F &&  f) -> decltype(std::forward<F>(f))

Given a pointer to a member function, cast it to its Derived version. Forward everything else unchanged.

◆ operator""_a()

constexpr arg pybind11::literals::operator""_a ( const char *  name,
size_t   
)
constexpr

\rst String literal version of arg \endrst

◆ operator""_s()

str pybind11::literals::operator""_s ( const char *  s,
size_t  size 
)
inline

\rst String literal version of str \endrst

◆ pickle()

template<typename GetState , typename SetState >
detail::initimpl::pickle_factory< GetState, SetState > pybind11::pickle ( GetState &&  g,
SetState &&  s 
)

Binds pickling functions __getstate__ and __setstate__ and ensures that the type returned by __getstate__ is the same as the argument accepted by __setstate__.

◆ register_exception()

template<typename CppException >
exception< CppException > & pybind11::register_exception ( handle  scope,
const char *  name,
handle  base = PyExc_Exception 
)

Registers a Python exception in m of the given name and installs a translator to translate the C++ exception to the created Python exception using the what() method. This is intended for simple exception translations; for more complex translation, register the exception object and translator directly.

◆ register_local_exception()

template<typename CppException >
exception< CppException > & pybind11::register_local_exception ( handle  scope,
const char *  name,
handle  base = PyExc_Exception 
)

Registers a Python exception in m of the given name and installs a translator to translate the C++ exception to the created Python exception using the what() method. This translator will only be used for exceptions that are thrown in this module and will be tried before global exception translators, including those registered with register_exception. This is intended for simple exception translations; for more complex translation, register the exception object and translator directly.

◆ register_local_exception_translator()

void pybind11::register_local_exception_translator ( ExceptionTranslator &&  translator)
inline

Add a new module-local exception translator. Locally registered functions will be tried before any globally registered exception translators, which will only be invoked if the module-local handlers do not deal with the exception.

◆ reinterpret_borrow()

template<typename T >
T pybind11::reinterpret_borrow ( handle  h)

\rst Declare that a handle or PyObject * is a certain type and borrow the reference. The target type T must be object or one of its derived classes. The function doesn't do any conversions or checks. It's up to the user to make sure that the target type is correct.

.. code-block:: cpp

PyObject *p = PyList_GetItem(obj, index);
py::object o = reinterpret_borrow<py::object>(p);

or py::tuple t = reinterpret_borrow<py::tuple>(p); // <– p must be already be a tuple \endrst

◆ reinterpret_steal()

template<typename T >
T pybind11::reinterpret_steal ( handle  h)

\rst Like reinterpret_borrow, but steals the reference.

.. code-block:: cpp

PyObject *p = PyObject_Str(obj); py::str s = reinterpret_steal<py::str>(p); // <– p must be already be a str \endrst

Variable Documentation

◆ name

const detail::type_info const char* pybind11::name
Initial value:
{
return detail::get_type_override(this_ptr, this_type, name)
Annotation for function names.
Definition: attr.h:44