Skip to content

Object Handle

Demonstrates Python object handles — keeping Python objects in-process and referencing them by numeric ID across calls. Handles avoid serializing the entire object on every call.

View source

Key Points

  • ref() returns a PythonHandle without serializing the object
  • handle.call("method", args...) — invoke methods on the held object
  • handle.getAttr("name") — read attributes
  • handle.refId() / handle.pythonType() — inspect the handle
  • handle.release() / handle.close() — explicit release (AutoCloseable)
  • Handles are automatically released when PythonEmbed is closed

Run It

./gradlew :python-embed-examples:object-handle:run