stgl — Simple Text-based Graphical Library
stgl is an MLX-like terminal graphics library for Python. It is a thin,
opinionated wrapper around tinting
(markup-based ANSI coloring) and blessed
(terminal input/event loop), exposing an API where each function has an
equivalent in the MinilibX (MLX)
library.
In MLX you draw pixels in a window; in stgl a "pixel" is a single
character cell, a "color" is a tinting palette name ("RED", "BLK"...),
an "image" is a grid of styled cells, and the "loop" is the blessed event
loop. It is pure text — but the math and the shapes are the same idea,
just given different names.
Install
pip install stgl
# or, from the repo:
pip install ./stgl
Requires Python >= 3.10. Dependencies: tinting>=0.1.0, blessed>=1.47.0.
Quick start
import stgl
win = stgl.new_window("BLK", "BLK") # bg, canvas_bg
stgl.use_image(win, my_canvas) # my_canvas subclasses stgl.Image
stgl.loop(win) # run the event loop
Subclass stgl.Image to build a scene:
import stgl
class HelloCanvas(stgl.Image):
def base_canvas(self, refresh=False) -> list[str]:
return ["@WHT[Hello, stgl!]@"]
def update(self, ticks, s_yx, e_yx) -> list[str]:
canvas = self.base_canvas()
self.base_style = stgl.style_grid_noesc(canvas)
self.grid = [list(stgl.ttext(r, False)) for r in canvas]
self.grid_og = [list(stgl.ttext(r, False)) for r in canvas]
return stgl.grid_apply(self.grid, self.base_style, [],
start_x=s_yx[1], end_x=e_yx[1],
start_y=s_yx[0], end_y=e_yx[0])
def key_press(self, key) -> bool:
return False
MLX → stgl reference
| MLX | stgl |
|---|---|
mlx_init |
stgl.init |
mlx_release |
stgl.release |
mlx_new_window |
stgl.new_window |
mlx_clear_window |
stgl.clear_window |
mlx_destroy_window |
stgl.destroy_window |
mlx_pixel_put |
stgl.pixel_put |
mlx_string_put |
stgl.string_put |
mlx_new_image |
stgl.new_image |
mlx_get_data_addr |
stgl.get_data_addr |
mlx_put_image_to_window |
stgl.put_image_to_window |
mlx_destroy_image |
stgl.destroy_image |
mlx_xpm_file_to_image |
stgl.xpm_file_to_image |
mlx_png_file_to_image |
stgl.png_file_to_image |
mlx_loop |
stgl.loop |
mlx_loop_exit |
stgl.loop_exit |
mlx_key_hook |
stgl.key_hook |
mlx_mouse_hook |
stgl.mouse_hook |
mlx_expose_hook |
stgl.expose_hook |
mlx_loop_hook |
stgl.loop_hook |
mlx_hook |
stgl.hook |
mlx_mouse_hide/show/move |
stgl.mouse_hide/mouse_show/mouse_move |
mlx_mouse_get_pos |
stgl.mouse_get_pos |
mlx_do_key_autorepeatoff/on |
stgl.do_key_autorepeatoff/do_key_autorepeaton |
mlx_get_screen_size |
stgl.get_screen_size |
mlx_do_sync / mlx_sync |
stgl.do_sync / stgl.sync |
Colors: 0xAARRGGBB integers become tinting palette names exposed as
constants (stgl.BLK, stgl.WHT, stgl.RED, ...). Use stgl.color(r, g, b, a=255) to build the MLX-style integer if you need it.
License
MIT — see LICENSE for full text.
Author
Italo Almeida — italoalmeida@hezz.it
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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 stgl-1.0.2.tar.gz.
File metadata
- Download URL: stgl-1.0.2.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6d46c9248fc7988a241b1bf9e0628116f55761c1a2c94756f8feb2c20315178
|
|
| MD5 |
6e3b5ddf7f867a5a301cb87de4c7bbee
|
|
| BLAKE2b-256 |
31ee58e162c9e912d8592fe1a1dcb4b50843b7498d1635d66ecae48a066d5a75
|
File details
Details for the file stgl-1.0.2-py3-none-any.whl.
File metadata
- Download URL: stgl-1.0.2-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff8e1e455e53ba6e73fadce396adcca4f77f5e1e768fc07a997812a38c7dbac7
|
|
| MD5 |
2453cc4dbeed811dcd3231b303ddf9db
|
|
| BLAKE2b-256 |
fde569e6eada73c28f13d8fb050517abcda9749290d4a0dc217a6151f7abe5f8
|