Skip to main content

Blender’s Embedded Python

  • Chapter
  • First Online:
Core Blender Development
  • 1009 Accesses

Abstract

CPython is a C-based implementation of Python. It even contains an API. This allows CPython to be used as an external library and linked with a separate application written in C. Functions defined by an “embedding” program may be called via Python script, running on the embedded interpreter. As such, Blender itself embeds a Python interpreter, providing access to some of its own functions. Python-callable functions must be registered using the Python API. This is done by Blender’s python module.

This is a preview of subscription content, log in via an institution to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 49.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 64.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

Notes

  1. 1.

    At the time of this publication, Python 3.7 is the bundled version with Blender 2.83. The corresponding python.org documentation is https://docs.python.org/3.7/extending/embedding.html.

  2. 2.

    You will see reference counting used in the methods added as part of Blender’s extended Python for Blender. The CPython API functions Py_INCREF() and Py_DECREF() are used for counting PyObject references.

  3. 3.

    Incidentally, there is also a call to BaseMath_WriteCallback() in Vector_normalize(). Each PyObject subtype in mathutils may have a callback function. Callbacks are used by mathutils.Matrix (in MatrixObject) and implemented in functions with the suffix *_cb. The Vector_CreatePyObject_cb() allocation function, from mathutils_Vector.c, allocates a mathutils.Vector instance when the callback is invoked.

  4. 4.

    Class methods of mathutils.Vector, i.e., ones that can be called without an instance of the mathutils.Vector class (known as static member functions in C++), have C_* prepended to their identifiers. Python class methods may update class state, but not object state.

Author information

Authors and Affiliations

Authors

Rights and permissions

Reprints and permissions

Copyright information

© 2021 The Author(s), under exclusive license to APress Media, LLC , part of Springer Nature

About this chapter

Check for updates. Verify currency and authenticity via CrossMark

Cite this chapter

Hollister, B.E. (2021). Blender’s Embedded Python. In: Core Blender Development. Apress, Berkeley, CA. https://doi.org/10.1007/978-1-4842-6415-7_5

Download citation

Publish with us

Policies and ethics