Skip to content
BradyAJohnstonPublic

About

A set of data-oriented wrappers around the python API of Blender.

Resources

Stars

33 stars

Watchers

2 watching

Forks

Latest commit

 

History

124 Commits

Folders and files

Repository files navigation

databpy

pypi codecov CodSpeed deployment

databpy reads and writes the attributes of mesh, curves and point cloud objects in Blender as NumPy arrays, and creates those objects from arrays. It supports Blender 5.1 and later.

import numpy as np
import databpy as db

# create a mesh object from an (n, 3) array of vertex positions
bob = db.create_bob(np.random.rand(100, 3), name="Points")

# store and read attributes as NumPy arrays; the type is inferred from the dtype
bob.store_named_attribute(np.arange(100), "id")
ids = bob.named_attribute("id")

# attributes as arrays that write changes back to Blender
bob.position[:, 2] += 1.0
bob["id"][:10] = -1

store_named_attribute() and named_attribute() are named after the Store Named Attribute and Named Attribute nodes in Geometry Nodes.

Performance

databpy builds meshes by writing arrays straight to their attributes, rather than through Mesh.from_pydata(), and an attribute array writes back only the values that change:

Operation bpy databpy Speedup
Mesh from 100,000 vertices 37 ms 0.14 ms ~260x
Mesh from 100,000 vertices and 99,999 edges 62 ms 0.24 ms ~260x
Mesh from 90,000 vertices and 89,401 quads 101 ms 5.0 ms ~20x
Write 10 values of a 1,000,000 point attribute 0.28 ms 0.006 ms ~45x

The bpy column uses Mesh.from_pydata() for meshes, and for the attribute write a foreach_get and foreach_set round trip of the whole attribute. Times are medians of the workloads in benchmarks/test_benchmarks.py, measured with bpy 5.2.1 and Python 3.13 on an AMD Ryzen 9 9950X (Linux), and vary by machine. CodSpeed tracks the benchmarks on every pull request.

Installation

pip install databpy

bpy (Blender as a Python module) is an optional dependency, so installing databpy inside Blender doesn't install a second copy of bpy. To use databpy outside Blender, install bpy with it:

pip install "databpy[bpy]"

Supported Blender versions

Blender Tests
5.1 Blender 5.1
5.2 Blender 5.2
5.3 (beta) Blender 5.3
5.4 (alpha) Blender 5.4

databpy requires Python 3.13, the version Blender 5.1 and 5.2 use.

Documentation

databpy started inside Molecular Nodes and was split into a separate package for use in other projects, similarly to nodebpy.

About

A set of data-oriented wrappers around the python API of Blender.

Resources

Stars

33 stars

Watchers

2 watching

Forks

Releases

Used by

Contributors

Languages