Skip to main content

PyGLM

OpenGL Mathematics (GLM) library for Python

GLSL + Optional features + Python = PyGLM
A mathematics library for graphics programming.

PyGLM is a Python extension written in C++.
By using GLM by G-Truc under the hood, it manages to bring glm's features to Python.
Some features are unsupported (such as unstable extensions) - Please see [Unsupported Functions] below.
If you encounter any issues or want to request a feature, please create an issue on the issue tracker.

Tiny Documentation

Why PyGLM?

Besides the obvious - being mostly compatible with GLM - PyGLM offers a variety of features for vector and matrix manipulation.
It has a lot of possible use cases, including 3D-Graphics (OpenGL, DirectX, ...), Physics and more.

At the same time, it has great performance, being between 2x and 15x as fast as numpy! (see end of page)
(depending on the individual function)

Installation

PyGLM supports Windows, Linux, MacOS and other operating systems with either x86 (32-bit) or x64 (64-bit) architecture,
running Python 3.5 or higher. (Prior versions of Python - such as Python 2 - were supported up to PyGLM version 0.4.8b1)

It can be installed from the PyPI using pip:
pip install pyglm
And finally imported and used:
import glm

Using PyGLM

PyGLM's syntax is very similar to the original GLM's syntax.
There is no need to import anything but glm, as it already contains the entire package.
License requirements
Please make sure to include the license for GLM in your project when you use PyGLM!
(this also includes binary distributions, e.g. *.exe)

You can do so by copying either the COPYING or GLM_LICENSE file (or their contents) to your project.
Differences to glm
Instead of using double colons (::) for namespaces, periods (.) are used, so
glm::vec2 becomes glm.vec2.

PyGLM supports the buffer protocol, meaning its compitible to other objects that support the buffer protocol,
such as bytes or numpy.array
(for example you can convert a glm matrix to a numpy array and vice versa).
PyGLM is also capable of interpreting iterables (such as tuples) as vectors, so e.g. the following equasion is possible:
result = glm.vec2(1) * (2, 3)

PyGLM doesn't support precision qualifiers. All types use the default precision (packed_highp).

If a glm function normally accepts float and double arguments, the higher precision (double) is used.

There is no way to set preprocessor definitions (macros).
If - for example - you need to use the left handed coordinate system, you have to use *LH, so
glm.perspective becomes glm.perspectiveLH.

All types are initialized by default to avoid memory access violations.
(i.e. the macro GLM_FORCE_CTOR_INIT is defined)

In case you need the size of a PyGLM datatype, you can use
glm.sizeof(<type>)

The function glm.identity requires a matrix type as it's argument.

The function glm.frexp(x, exp) returns a tuple (m, e), if the input arguments are numerical.
This function may issue a UserWarning. You can silence this warning using glm.silence(1).

The function glm.value_ptr(x) returns a ctypes pointer of the respective type.
I.e. if the datatype of x is float, then a c_float pointer will be returned.
Likewise the reverse-functions (such as make_vec2(ptr)) will take a ctypes pointer as their argument
and return (in this case) a 2 component vector of the pointers underlying type.

glm.silence(ID) can be used to silence specific warnings.
Supplying an id of 0 will silence all warnings.

There is currently no documentation for PyGLM.
Please refer to the source (in Python: *.__doc__) and GLM manuals, references and tutorials.

Unsupported functions
Aside from the unstable extensions,
PyGLM doesn't support the following extensions and methods, due to compatibility issues:
The GLM_GTC_bitfield extension,
glm::log2 from GLM_GTC_integer.
glm::packUnorm and glm::packSnorm from GLM_GTC_packing.

Build options
PyGLM can be built from source in a couple of different ways.
In PyGLM.cpp there is a preprocessor option PyGLM_BUILD which is set to PyGLM_DEFAULT by default.
PyGLM_DEFAULT will build all of PyGLM's functions and features.

A few other flags exist:
PyGLM_FAST removes PyGLM's iterable and GetBuffer checking, thus making it incompatible with tuples, numpy arrays and bytes objects while increasing overall performance.

PyGLM_NO_FUNCTIONS removes all of the functions of glm and only builds the bare types.

PyGLM_MINIMAL combines PyGLM_FAST and PyGLM_NO_FUNCTIONS.

Example

>>> import glm
>>> v = glm.vec3()
>>> v.x = 7
>>> print(v.xxy)
vec3(            7,            7,            0 )

>>> m = glm.mat4()
>>> print(m)
[            1 |            0 |            0 |            0 ]
[            0 |            1 |            0 |            0 ]
[            0 |            0 |            1 |            0 ]
[            0 |            0 |            0 |            1 ]

>>> v = glm.vec4(1, 2, 3, 4)
>>> print(v + (8, 7, 6, 5))
vec4(            9,            9,            9,            9 )

Speed comparison to numpy

How PyGLM's performance roughly compares to NumPy's performance:
instruction     | np speed (%)  | glm speed (%)
import          |   4.76        |  100.00
mat4()          |   9.76        |  100.00
dot(vec3, vec3) |  28.92        |  100.00
transpose(mat4) |  25.64        |  100.00
vec4 * vec4     |  27.89        |  100.00
mat4 * vec4     |  17.68        |  100.00
mat4[0]         |  49.99        |  100.00

Metadata

Release files for pyglm 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyglm 1.1.2
File Size Uploaded Provenance Actions
PyGLM-1.1.2.tar.gz 281.9 kB Without provenance Details for PyGLM-1.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for pyglm 1.1.2
File Actions
PyGLM-1.1.2-cp38-cp38-win_amd64.whl CPython 3.8 CPython 3.8 Windows x86-64 Details for PyGLM-1.1.2-cp38-cp38-win_amd64.whl
PyGLM-1.1.2-cp38-cp38-win32.whl CPython 3.8 CPython 3.8 Windows x86-32 Details for PyGLM-1.1.2-cp38-cp38-win32.whl
PyGLM-1.1.2-cp37-cp37m-win_amd64.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-64 Details for PyGLM-1.1.2-cp37-cp37m-win_amd64.whl
PyGLM-1.1.2-cp37-cp37m-win32.whl CPython 3.7 CPython 3.7 pymalloc Windows x86-32 Details for PyGLM-1.1.2-cp37-cp37m-win32.whl
PyGLM-1.1.2-cp36-cp36m-win_amd64.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-64 Details for PyGLM-1.1.2-cp36-cp36m-win_amd64.whl
PyGLM-1.1.2-cp36-cp36m-win32.whl CPython 3.6 CPython 3.6 pymalloc Windows x86-32 Details for PyGLM-1.1.2-cp36-cp36m-win32.whl
PyGLM-1.1.2-cp35-cp35m-win_amd64.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-64 Details for PyGLM-1.1.2-cp35-cp35m-win_amd64.whl
PyGLM-1.1.2-cp35-cp35m-win32.whl CPython 3.5 CPython 3.5 pymalloc Windows x86-32 Details for PyGLM-1.1.2-cp35-cp35m-win32.whl

Total release size: 6.6 MB

Release files / PyGLM-1.1.2.tar.gz

Download URL PyGLM-1.1.2.tar.gz
Size 281.9 kB
Tags Source
SHA-256 checksum
How to use checksums
087dec46e1f8113204ed6897ac1d7e57a8411bf1515084a2a7801b74bc2e6060
BLAKE2b-256 checksum
How to use checksums
548549ad607a64fc0f60696a00f57282f8ebaa3cb5c6ac0f2c3f1e773026be5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp38-cp38-win_amd64.whl

Download URL PyGLM-1.1.2-cp38-cp38-win_amd64.whl
Size 861.1 kB
Tags CPython 3.8 Windows x86-64
SHA-256 checksum
How to use checksums
8e04e4374a19409102c782336317bdabc4137ffd64c85f31a1e8dde9923a99e6
BLAKE2b-256 checksum
How to use checksums
725accb33fe4f93e65093ddf2bc2781c49c6707173005df991411347bb88b088
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp38-cp38-win32.whl

Download URL PyGLM-1.1.2-cp38-cp38-win32.whl
Size 729.7 kB
Tags CPython 3.8 Windows x86-32
SHA-256 checksum
How to use checksums
a6308a2a5566e93fd76479e1fe3633d2aa0ae159bc86fa49e8604c9d8db224f9
BLAKE2b-256 checksum
How to use checksums
3ceda4bdfd9e3368f027eb1795cad587b10c87cf5e11aff3e55593f887644a6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp37-cp37m-win_amd64.whl

Download URL PyGLM-1.1.2-cp37-cp37m-win_amd64.whl
Size 855.8 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
7277c7fbe24af0771c5d636f995d6518c170b3c1f67b311a79be409d8629b90e
BLAKE2b-256 checksum
How to use checksums
870da0ae1dd03a9f5d2c994fa3ed18d226082b6b68a9e49078db6c0b700adb25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp37-cp37m-win32.whl

Download URL PyGLM-1.1.2-cp37-cp37m-win32.whl
Size 727.5 kB
Tags CPython 3.7 CPython 3.7 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
f542951c62c5f039c63fea88b16aaae24301587b08517fe3fd346185d3530d7c
BLAKE2b-256 checksum
How to use checksums
cb9080232bf842df38339fa9415191c1c0d7d7be34060588f71a9ede8e5bc49f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp36-cp36m-win_amd64.whl

Download URL PyGLM-1.1.2-cp36-cp36m-win_amd64.whl
Size 855.8 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
693388290ec561adec29035fcf40348a2ef30e865d4b10f15e799bfc31daa5ba
BLAKE2b-256 checksum
How to use checksums
ec0569b0370aa9d7cf17918ebe190d71a598d66ec1c763191d2a4381cb8a8f4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp36-cp36m-win32.whl

Download URL PyGLM-1.1.2-cp36-cp36m-win32.whl
Size 727.5 kB
Tags CPython 3.6 CPython 3.6 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
99ec702fd3ff180e96bf7e5380603f230908cc529c0069bffb88de91d9800cda
BLAKE2b-256 checksum
How to use checksums
7f15a78d474d2f97cbf6908c163f9577b081195d995847b1aadcd8483e06caca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp35-cp35m-win_amd64.whl

Download URL PyGLM-1.1.2-cp35-cp35m-win_amd64.whl
Size 868.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-64
SHA-256 checksum
How to use checksums
112349d89409d44dd1640505a7f2f6ec5dac0328674f382eebbe3f0fa9dadb27
BLAKE2b-256 checksum
How to use checksums
f0c1acea8f39fabc0ea4ef5a3bf25090e11699eb8aca8fc172cc366f1e6e0987
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Release files / PyGLM-1.1.2-cp35-cp35m-win32.whl

Download URL PyGLM-1.1.2-cp35-cp35m-win32.whl
Size 716.1 kB
Tags CPython 3.5 CPython 3.5 pymalloc Windows x86-32
SHA-256 checksum
How to use checksums
da4b34ee4976f2440685e811486f3be90b7e472b945a702f9e2f36065b403ee9
BLAKE2b-256 checksum
How to use checksums
91a366f0fc49194c8932e6a1371859144f50067b498a45828e780d1a9dfb5187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.8.0

Security for pyglm 1.1.2

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.

Release history Release notifications | RSS feed

This release

1.1.2 This release

9 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page