Skip to main content

stgl — Simple Text-based Graphical Library

PyPI version Python License: MIT CI

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

Metadata

Release files for stgl 1.0.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 stgl 1.0.2
File Size Uploaded Provenance Actions
stgl-1.0.2.tar.gz 14.0 kB Without provenance Details for stgl-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stgl 1.0.2
File Interpreter ABI Platform Actions
stgl-1.0.2-py3-none-any.whl Python 3 none any Details for stgl-1.0.2-py3-none-any.whl

Total release size: 28.8 kB

Release files / stgl-1.0.2.tar.gz

Download URL stgl-1.0.2.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f6d46c9248fc7988a241b1bf9e0628116f55761c1a2c94756f8feb2c20315178
BLAKE2b-256 checksum
How to use checksums
31ee58e162c9e912d8592fe1a1dcb4b50843b7498d1635d66ecae48a066d5a75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Release files / stgl-1.0.2-py3-none-any.whl

Download URL stgl-1.0.2-py3-none-any.whl
Size 14.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff8e1e455e53ba6e73fadce396adcca4f77f5e1e768fc07a997812a38c7dbac7
BLAKE2b-256 checksum
How to use checksums
fde569e6eada73c28f13d8fb050517abcda9749290d4a0dc217a6151f7abe5f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.5

Security for stgl 1.0.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.0.2 This release

2 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