Registry / http-networking / glcontext

glcontext

JSON →
library3.0.0pypypi✓ verified 88d ago

glcontext is a Python library providing portable headless OpenGL context creation, making it possible to run OpenGL applications without a display server or window. It supports various backends like standalone, EGL, OSMesa, WGL, and GLX. The current version is 3.0.0, with a release cadence tied to the moderngl ecosystem and bug fixes.

pip install glcontext
INSTALL
IMPORT
SIG · GLCONTEXT
G
glcontext
http-networkingpythonv3.0.0
Install
1.6s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default_backend
✓ from glcontext import default_backend
✗ from glcontext import create_context
get_backend_by_name
✓ from glcontext import get_backend_by_name
os
✓ from glcontext import os

This example demonstrates how to create a basic headless OpenGL context using the `create_context` function and the `standalone=True` argument. It also shows how to retrieve basic context information and correctly release resources.

import glcontext # Create a headless OpenGL context using the standalone backend. # This is the recommended way for most headless environments. # Other backends like 'egl', 'osmesa', 'wgl', 'glx' can be specified # via the 'backend' argument, e.g., create_context(backend='egl') try: ctx = glcontext.create_context(standalone=True) print(f"Successfully created glcontext: {ctx}") print(f"OpenGL Version: {ctx.version_string}") # The context is now available for OpenGL operations. # For example, if using with moderngl: # ctx.make_current() # import moderngl # mgl_ctx = moderngl.create_context(require=ctx.version_code) # print(f"ModernGL context created with version: {mgl_ctx.version_code}") ctx.release() # Release the context when done except Exception as e: print(f"Failed to create glcontext: {e}") print("Ensure appropriate OpenGL drivers or Mesa libraries are installed for headless operation.")
Debug
Known issues
breakingThe `glcontext.headless_context` function was removed and replaced by `glcontext.create_context`. To create a standalone headless context, use `create_context(standalone=True)`.
fix
Replace calls to `glcontext.headless_context()` with `glcontext.create_context(standalone=True)`.
affects: 3.0.0 and newer
gotchaContext creation can fail if the required OpenGL drivers or backend libraries (e.g., EGL, OSMesa, GLX) are not available or correctly configured on the system. Error messages can sometimes be generic or misleading.
fix
Ensure your system has the necessary OpenGL drivers and libraries (e.g., Mesa for `osmesa`, appropriate vendor drivers for `egl`/`glx`) installed and accessible. Check `glcontext.available` for supported backends before attempting to create a context.
affects: All versions
gotchaNot explicitly releasing OpenGL contexts can lead to resource leaks, especially in applications that create and destroy many contexts or run for extended periods.
fix
Always call `ctx.release()` on the `Context` object when you are finished with it to free up underlying system resources.
affects: All versions
Upgrade
Version history
3.0.0latest on PyPI · released Aug 10, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
glcontext — pip install glcontext · libregistry