DataBpy 2

https://github.com/BradyAJohnston/databpy

import importlib.metadata
import sys
from pathlib import Path

import bpy
import databpy as db
import numpy as np
import polars as pl

# The kernel runs inside Blender (not in the notebook folder), so add the docs helpers to sys.path
sys.path.append(str(Path.home() / "projects/bpy-gallery/docs/utils"))
from gallery_utils import ASSETS

print("Blender version:", bpy.app.version_string)
print("Databpy version:", importlib.metadata.version("databpy"))
Blender version: 5.3.0 Beta
Databpy version: 0.10.1
vertex = np.array([[0, 0, 0]])  
obj = db.create_bob(vertex, name="Mesh1")
obj.name
'Mesh1'
obj.position
AttributeArray(name='position', object='Mesh1', mesh='Mesh1', domain=POINT, type=FLOAT_VECTOR, shape=(1, 3), dtype=float32)
array([[0., 0., 0.]], dtype=float32)
coords = np.random.rand(20, 3)  
obj = db.create_bob(coords, name="Mesh2")
obj.name
'Mesh2'
obj.position[:3] # first three
AttributeArray(name='position', object='Mesh2', mesh='Mesh2', domain=POINT, type=FLOAT_VECTOR, shape=(3, 3), dtype=float32)
array([[0.10132604, 0.65126437, 0.7202371 ],
       [0.63704145, 0.47889748, 0.62918323],
       [0.07869091, 0.06703191, 0.13930504]], dtype=float32)
%%time

# Generate 2 million random 3D points
coords = np.random.rand(2_000_000, 3)

# Create a mesh object using databpy
obj = db.create_bob(coords, name="Mesh2M")
print(obj.name)
Mesh2M
CPU times: user 28.6 ms, sys: 3.54 ms, total: 32.2 ms
Wall time: 32.2 ms

Setting Attributes

To run the code below, first install the Blender extension from the following link: https://extensions.blender.org/add-ons/csv-importer/

# import only works when installed from the extension store, not when installed from local zip file.
from bl_ext.blender_org.csv_importer.csv import load_csv
from bl_ext.blender_org.csv_importer.parsers import polars_df_to_bob

df = pl.DataFrame(
    {
        "Intensity": [10, 20],
    }
)
bob = polars_df_to_bob(df, name="MeshInt")
df = pl.DataFrame(
    {
        "opacity": [0.34, 0.92],
    }
)
bob = polars_df_to_bob(df, name="MeshFloat")
df = pl.DataFrame(
    {
        "Is_Visible": [True, False],
    }
)
bob = polars_df_to_bob(df, name="MeshBool")
df = pl.DataFrame({
    "Star": [
        [3.4, 3.5, 0.0],
        [3.1, 5.6, 0.0]
    ]
})
obj = polars_df_to_bob(df, name="MeshVector")
df = pl.DataFrame({
    "String": ["Hello", "World"],
})
# Stings are not supported
obj = polars_df_to_bob(df, name="MeshVector")
# all together

df = pl.DataFrame({
    "Intensity": [10, 20],
    "opacity": [0.34, 0.92],
    "Is_Visible": [True, False],
    "Star": [
        [3.4, 3.5, 0.0],
        [3.1, 5.6, 0.0]
    ]
})
obj = polars_df_to_bob(df, name="MeshAll")
# `load_csv` is like `polars_df_to_bob`, but with a csv path input
obj = load_csv(ASSETS / "data_california_housing_normalized.csv")

print(obj.name)
CSV_data_california_housing_normalized