Python bindings for ANARI
Project description
pynari - Python Bindings for ANARI
This project provides a python interface for the Khronos ANARI rendering API. This implementation currently requires a CUDA capable GPU (support for other backends will be added at a later time).
Usage - Quickstart
Assuming you already know how the ANARI API works (and that you have pip-installed this package) you can use ANARI in python as follows: First, import this package
import pynari as anari
(for all the steps below we assume you imported pynari as anari;
this is not required, but please take this in mind for the examples below).
Once the package has been imported you can then create a ANARI "device" using
device = anari.newDevice('default')
(the 'default' will later allow for selecting between different back-ends, but this current implementation is hard-coded to the 'barney' backend, see https://github.com/ingowald/barney).
You can then create various ANARI actor objects through creator-methods on that device, such as, for example
world = device.newWorld()
mesh = device.newGeometry('triangle')
array = device.newArray(anari.FLOAT32_VEC3,vertex)
etc.
Large arrays (such as vertex or index arrays for a triangle mesh)
are expected to be populated using numpy, and wrapped in the ANARI 'array' type:
import numpy as np
...
vertex = np.array(...,dtype=np.float32)
mesh.setParameter('vertex.position',anari.ARRAY,
device.newArray(anari.FLOAT32_VEC3,vertex));
index = np.array(...,dtype=np.uint32)
mesh.setParameter('primitive.index',anari.ARRAY,
device.newArray(anari.UINT32_VEC3,index));
The ANARI API, and how it is exposed in pynari
For a full description of what ANARI Objects are, what kind of objects exist, and how they work, please refer to the ANARI API Spec at https://registry.khronos.org/ANARI/specs/1.0/ANARI-1.0.html .
Since the official ANARI API is a plain C API we could not
implement this literally, but had to make certain changes to make ti
more "pythonic". Basically, these rules were applied (we will assume
that the pynari module was imported under the alias as anari):
-
If there is a C constant/enum of name
ANARI_XYZ, it is exposed asanari.XYZ. Example: the C enum ofANARI_FLOAT32isanari.FLOAT32in pynari. -
If there is a C API function of
anariFunctionXyz(ANARIDevice device, ...)it will be exposed asdevice.functionXyz(...). Note that in order to remain as close to the C-style API as possible we use CAML-case for function names, not python-casing. I.e., pynari usesdevice.functionXyz(...), notdevice.function_xyz(...).
Examples
For a list of several samples, please visit the pynari github repo https://github.com/ingowald/pynari
For any issues, please use the github pynari issue tracker.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pynari-1.3.0-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: pynari-1.3.0-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 16.8 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55dc698622e2a9d8c99e1c29064a4faa07e3494a3b9e900922c96a91dd51b960
|
|
| MD5 |
81a5fe8f7d925876a24d605187dd0dff
|
|
| BLAKE2b-256 |
666e3b407e4cd3d3ecd56f18372436a948fa8f04c9fe3bb753236e2207f7d166
|
File details
Details for the file pynari-1.3.0-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: pynari-1.3.0-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 16.8 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3d105cdde065396e847ec3bad2ce45e2c5b66ba544c697b2fbbd921c39eb9ae
|
|
| MD5 |
3babcd513234cccc71f47bb95cd66c22
|
|
| BLAKE2b-256 |
77a469ef470aaae09ad0550606210f24723968bd219c12d7e26010641d8fcce6
|
File details
Details for the file pynari-1.3.0-cp39-cp39-win_amd64.whl.
File metadata
- Download URL: pynari-1.3.0-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 16.8 MB
- Tags: CPython 3.9, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eba7f63131fbb3563c08b0b6588776e1fc79354e080543026046e08f259e22c0
|
|
| MD5 |
042b1741df047554fd893320a8d91a44
|
|
| BLAKE2b-256 |
5340d49089409eb309cda9150cb15fcca4886e3705cbfa580ba8705de79b246b
|