hyprland-socket
Typed Python library for Hyprland IPC via Unix sockets.
Covers both read and write operations — querying state, applying settings live, batch commands, and monitoring events.
Installation
pip install hyprland-socket
Usage
Query state
import hyprland_socket
# Check if Hyprland is running
if hyprland_socket.is_running():
# Read monitors
for mon in hyprland_socket.get_monitors():
print(f"{mon.name}: {mon.width}x{mon.height} @ {mon.refresh_rate}Hz")
# List all windows
for win in hyprland_socket.get_windows():
print(f"{win.class_name}: {win.title} (workspace {win.workspace_name})")
# List workspaces
for ws in hyprland_socket.get_workspaces():
print(f"Workspace {ws.name}: {ws.windows} windows on {ws.monitor}")
# Read a live option and extract its typed value
option = hyprland_socket.get_option("general:gaps_in")
gaps = hyprland_socket.extract_ipc_value(option, hint=0)
print(f"gaps_in = {gaps}")
# Read keybinds
for bind in hyprland_socket.get_binds():
mods = hyprland_socket.modmask_to_str(bind.modmask)
print(f"{mods} + {bind.key} -> {bind.dispatcher} {bind.arg}")
Apply settings
import hyprland_socket
# Set a single option
hyprland_socket.keyword("general:gaps_in", 5)
# Batch multiple settings (single IPC call)
hyprland_socket.keyword_batch([
("general:gaps_in", "5"),
("general:gaps_out", "10"),
("decoration:rounding", "8"),
])
# Execute a dispatcher
hyprland_socket.dispatch("workspace", "2")
# Set the live cursor theme and size
hyprland_socket.set_cursor("Bibata-Modern-Classic", 24)
# Reload config from disk
hyprland_socket.reload()
Monitor events
import hyprland_socket
# Blocking iterator over compositor events
for event in hyprland_socket.listen():
print(f"{event.name}: {event.data}")
# e.g. "workspace: 2", "monitoradded: DP-3"
For integration with GTK/GLib event loops, use the raw socket:
sock = hyprland_socket.connect_event_socket()
fd = sock.fileno()
# Use GLib.io_add_watch(fd, ...) or similar
For typed event dispatch with named fields instead of raw strings, see hyprland-events which builds on this library.
Error handling
All functions raise typed exceptions instead of returning None:
from hyprland_socket import SocketError, CommandError
try:
hyprland_socket.keyword("invalid:option", "value")
except SocketError:
print("Hyprland is not running")
except CommandError as e:
print(f"Rejected: {e}")
Models
| Function | Returns |
|---|---|
get_monitors() |
list[Monitor] |
get_windows() |
list[Window] |
get_workspaces() |
list[Workspace] |
get_binds() |
list[Bind] |
get_animations() |
tuple[list[Animation], list[BezierCurve]] |
get_devices() |
dict |
get_option(key) |
dict (use extract_ipc_value() to unwrap) |
get_version() |
Version |
All models are frozen dataclasses with a from_dict() classmethod for
construction from Hyprland's JSON responses.
Socket lifecycle
Hyprland processes command-socket connections synchronously — an unclosed connection freezes the compositor until a five-second timeout expires. All functions in this library open and close the command socket within a single call, so normal usage is safe.
The event socket (connect_event_socket()) is a separate, long-lived
connection and is safe to keep open indefinitely.
Requirements
- Python >= 3.12
- A running Hyprland session (the
HYPRLAND_INSTANCE_SIGNATUREenvironment variable must be set)
License
MIT
Metadata
Release files for hyprland-socket 0.12.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| hyprland_socket-0.12.2.tar.gz | 10.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| hyprland_socket-0.12.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.3 kB
Release files / hyprland_socket-0.12.2.tar.gz
| Download URL | hyprland_socket-0.12.2.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b45778940710d0667d372f227bc53452fdf123d71d1dcbd652a97677ecbfc70b
|
|
BLAKE2b-256 checksum How to use checksums |
3d98f5d09c4dc2f9a4f361c9a0aa6201178feea3083475a1640586dcf15b3931
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 8, 2026.
Transparency logRelease files / hyprland_socket-0.12.2-py3-none-any.whl
| Download URL | hyprland_socket-0.12.2-py3-none-any.whl |
|---|---|
| Size | 13.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f1d007b7f9165447c39c66c578012bd2628331aeadb3a81c2fe2229711dc4d7
|
|
BLAKE2b-256 checksum How to use checksums |
e474e156c61e041b357591749aa480257b129e4c9a186faed98fd72551c68049
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 8, 2026.
Transparency log