High-performance Python bindings for the glam Rust linear algebra library. A simple, fast, SIMD-optimized 3D math library for games, graphics, and simulations.
pyglam is a thin, zero-cost Python interface for bitshifter/glam-rs — the industry-leading Rust math library used in Bevy, macroquad, and many Rust game engines.
It brings native Rust performance directly into Python with:
-
Clean Pythonic API
-
Full
f32/f64support -
SIMD acceleration on x86 / x86_64 / aarch64
-
Column-major matrices & column vectors
-
Zero-overhead function calls
-
Vectors:
Vec2,Vec3,Vec4 -
Matrices:
Mat3,Mat4 -
Quaternion:
Quat
-
Vectors:
DVec2,DVec3,DVec4 -
Matrices:
DMat3,DMat4 -
Quaternion:
DQuat
All types exactly match the glam API behavior and memory layout.
-
Addition, subtraction, scalar multiply/divide
-
Dot product
-
Length & normalization
-
Component access (
x,y,z,w)
-
Construction & identity
-
Matrix multiplication (
@) -
Scalar multiplication
-
Transpose
-
Inverse
-
From axis-angle
-
Quaternion multiplication
-
Vector rotation
-
Inversion & normalization
from pyglam.mat4 import Mat4
from pyglam.vec4 import Vec4
mat = Mat4.identity()
mat2 = Mat4.identity()
mat_mul = mat @ mat2
vec = Vec4(1.0, 2.0, 3.0, 1.0)
result = mat @ vec
print("mat × vec:", result.x, result.y, result.z, result.w)
inv_mat = mat.inverse()
tp_mat = mat.transpose()-
Column-major memory order
-
Coordinate system agnostic
-
No generic hacks — clean, static types
-
1:1 API compatibility with glam
-
SIMD optimized where available
-
Zero Python overhead for basic math
-
Same performance characteristics as Rust glam
This project is licensed under either of:
-
Apache License, Version 2.0
-
MIT license
Contributions are welcome! Unless you explicitly state otherwise, any contribution you submit will be dual-licensed as above.
All math internals are ported from:
-
glam-rs © bitshifter
-
DirectXMath © Microsoft
-
Realtime Math © Nicholas Frechette