This release is a pre-release and may not be stable for production use.
Quatham
Quatham (import as hammy) is a lightweight, high-performance quaternion mathematics package for 3D rotations. Built with NumPy and Numba acceleration, it provides efficient quaternion operations for both single quaternions and batched arrays.
Features
- Numba-accelerated operations — Low-level quaternion math functions are JIT-compiled for maximum performance
- Batch processing — All operations support both single quaternions and arrays of quaternions
- Comprehensive conversions — Convert between quaternions and:
- Euler angles (proper/classic, 6 sequences)
- Tait-Bryan angles (Cardan/nautical, 6 sequences including yaw-pitch-roll)
- Rotation matrices
- Axis-angle representations
- Spherical coordinates
- Intuitive API — Clean, Pythonic interface with operator overloading
- Scalar-first convention — Consistent
[w, x, y, z]ordering throughout
Installation
pip install quatham
Note: The package name and import are both quatham:
import quatham
from quatham import Quaternion
Requirements
- Python 3.12+
- NumPy >= 2.0
- Numba >= 0.60
Quick Start
Basic Usage
from quatham import Quaternion
import numpy as np
# Create a quaternion from components
q = Quaternion([1.0, 0.0, 0.0, 0.0]) # Identity quaternion
# Create from Euler angles (intrinsic rotations, radians by default)
q = Quaternion.from_euler([np.pi/4, 0, 0], seq='xyz')
# Create from axis-angle representation
axis = np.array([0, 0, 1]) # Z-axis
angle = np.pi / 2 # 90 degrees
q = Quaternion.from_axisangle(axis, angle)
# Create from axis-angle in degrees
q = Quaternion.from_axisangle([0, 0, 1], 90, degrees=True)
Quaternion Operations
# Quaternion multiplication (Hamilton product)
q1 = Quaternion([1.0, 0.0, 0.0, 0.0])
q2 = Quaternion.from_euler([np.pi/4, 0, 0], seq='xyz')
q3 = q1 * q2
# Scalar multiplication
q_scaled = q1 * 2.0
# Quaternion division
q_div = q1 / q2
# Conjugate
q_conj = q1.conjugate
# Normalise to unit quaternion
q_norm = q1.normalise()
# Magnitude
magnitude = q1.magnitude
Vector Rotation
# Rotate a 3D vector using quaternion
q = Quaternion.from_axisangle([0, 0, 1], np.pi / 2)
v = np.array([1.0, 0.0, 0.0])
v_rotated = q * v # Results in [0.0, 1.0, 0.0]
Conversions
# To rotation matrix (3x3)
R = q.to_rotation_matrix()
# To flat rotation matrix (9 elements)
R_flat = q.get_rotation_matrix_flat()
# To axis-angle representation
axis, angle = q.to_axis_angle()
axis, angle_deg = q.to_axis_angle(degrees=True)
# To Euler angles (proper, e.g., 'zxz' sequence)
euler = q.to_euler(seq='zxz', degrees=True)
# To Tait-Bryan angles (yaw-pitch-roll, intrinsic z-y-x)
ypr = q.to_yaw_pitch_roll(degrees=True)
# To Tait-Bryan with custom sequence
tait_bryan = q.to_tait_bryan(seq='xyz', degrees=True, intrinsic=True)
Batch Operations
Hammy efficiently handles arrays of quaternions:
# Create multiple quaternions at once
quats = Quaternion([
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
])
# Batch Euler angle conversion
angles = np.array([
[np.pi/4, 0, 0],
[0, np.pi/3, 0],
[0, 0, np.pi/6],
])
q_batch = Quaternion.from_euler(angles, seq='xyz')
# Batch vector rotation
v = np.array([1.0, 0.0, 0.0])
rotated = q_batch * v # Shape: (3, 3)
# Access individual quaternions
q_first = Quaternion(q_batch[0])
Supported Rotation Sequences
Proper Euler Angles (2 distinct axes)
xzx,xyx,yxy,yzy,zxz,zyz
Tait-Bryan Angles (3 distinct axes)
xyz,xzy,yxz,yzx,zxy,zyx
Both intrinsic (local/body axes) and extrinsic (fixed/global axes) conventions are supported.
API Reference
Quaternion Class
Constructors
Quaternion(value)— Create from array-like[w, x, y, z]or[[w, x, y, z], ...]Quaternion.from_euler(angles, seq, degrees, intrinsic)— From Euler/Tait-Bryan anglesQuaternion.from_axisangle(v, theta, degrees)— From axis-angle representationQuaternion.from_spherical(theta, phi, degrees)— From spherical coordinates
Properties
scalar/w— Real (scalar) componentvector— Imaginary (vector) component[x, y, z]x,y,z— Individual vector componentsconjugate— Conjugate quaternion (negated vector part)magnitude— Euclidean normnum_quaternions— Number of quaternions stored
Methods
normalise()/normalize()— Return unit quaternionto_rotation_matrix()— Convert to 3×3 rotation matrixget_rotation_matrix_flat()— Convert to flat 9-element arrayto_axis_angle(degrees)— Convert to axis-angle representationget_rotation_vector()— Get rotation vector (axis × angle)to_euler(seq, degrees, intrinsic)— Convert to proper Euler anglesto_tait_bryan(seq, degrees, intrinsic)— Convert to Tait-Bryan anglesto_yaw_pitch_roll(degrees)— Convert to yaw-pitch-roll (zyx sequence)vector_norm()— L2 norm of vector componenttolist()— Convert to Python list
Operators
+,-— Addition/subtraction with quaternions or arrays*— Quaternion multiplication, scalar multiplication, or vector rotation/— Quaternion division or scalar division-q— Negationq[idx]— Index/slice access
Conventions
- Scalar-first: Quaternions use
[w, x, y, z]ordering - Intrinsic rotations: Default for
from_euler(),to_euler(),to_tait_bryan() - Double-cover SO(3):
qand-qrepresent identical spatial rotations - Right-handed coordinate system: Standard 3D rotation convention
Performance
Quatham uses Numba JIT compilation for core mathematical operations, providing near-C performance for batch operations. For optimal performance:
- Use batch operations instead of loops when possible
- Ensure arrays are contiguous in memory
- The first call includes JIT compilation overhead; subsequent calls are fast
Examples
See the documentation for more detailed examples and tutorials.
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests on GitHub.
License
Distributed under the BSD-3-Clause License. See LICENSE for more information.
Citation
If you use Quatham in your research, please cite:
@software{quatham2026,
author = {Morrissey, JP},
title = {Quatham: NumPy/Numba-accelerated quaternion mathematics},
year = {2026},
url = {https://github.com/jpmorr/quatham}
}
Metadata
Release files for quatham 0.2.0rc0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quatham-0.2.0rc0.tar.gz | 170.2 kB | Without provenance | Details for quatham-0.2.0rc0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quatham-0.2.0rc0-py3-none-any.whl | Python 3 | none | any | Details for quatham-0.2.0rc0-py3-none-any.whl |
Total release size: 186.2 kB
Release files / quatham-0.2.0rc0.tar.gz
| Download URL | quatham-0.2.0rc0.tar.gz |
|---|---|
| Size | 170.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
92c6c3bad7d218241862f1028bf6ae54b6a810c76454efa700279d79406645c6
|
|
BLAKE2b-256 checksum How to use checksums |
96120663a0cad08a764636b2e240b2542352d2fd46c6153b235c70edeea7bde8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / quatham-0.2.0rc0-py3-none-any.whl
| Download URL | quatham-0.2.0rc0-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2613abdd17eb01fafa10cc18e06f78945e390b27442b58373ccb2f2a14ba57e6
|
|
BLAKE2b-256 checksum How to use checksums |
7711b5d866923b8f465a9d7105c4d9da87df10ebb06b0e31d9d3f8e1e446b946
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.7 {"installer":{"name":"uv","version":"0.13.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for quatham 0.2.0rc0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.