Typed Python library for Hyprland IPC via Unix sockets
Project description
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
option = hyprland_socket.get_option("general:gaps_in")
print(option)
# Read keybinds
for bind in hyprland_socket.get_binds():
print(f"{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")
# Reload config from disk
hyprland_socket.reload()
Monitor events
import hyprland_socket
# Blocking iterator over compositor events
for event in hyprland_socket.events():
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[dict]] |
get_devices() |
dict |
get_option(key) |
dict |
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
Project details
Release history Release notifications | RSS feed
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 hyprland_socket-0.5.0.tar.gz.
File metadata
- Download URL: hyprland_socket-0.5.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09b34bcf24980f696f772ee428d3a3883780d617a5f0a1073e85b2f2499115ba
|
|
| MD5 |
f23cddb2b929878512e12397b1d73db7
|
|
| BLAKE2b-256 |
544c976bc658627704c521401ba12ec044970757a33aec2202e4ce6da7eae0ff
|
Provenance
The following attestation bundles were made for hyprland_socket-0.5.0.tar.gz:
Publisher:
publish.yml on BlueManCZ/hyprland-socket
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyprland_socket-0.5.0.tar.gz -
Subject digest:
09b34bcf24980f696f772ee428d3a3883780d617a5f0a1073e85b2f2499115ba - Sigstore transparency entry: 1155218499
- Sigstore integration time:
-
Permalink:
BlueManCZ/hyprland-socket@0e4e2be52ef2108cfe7fcebc82a9d28de242ec91 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/BlueManCZ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0e4e2be52ef2108cfe7fcebc82a9d28de242ec91 -
Trigger Event:
release
-
Statement type:
File details
Details for the file hyprland_socket-0.5.0-py3-none-any.whl.
File metadata
- Download URL: hyprland_socket-0.5.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0979f651528945a96db6ebdbcac3fcd51998b9c8547ad88d4ea3b34fb92f4c1e
|
|
| MD5 |
3cb3e19d469477240395a3cdfcfb2c57
|
|
| BLAKE2b-256 |
0d7a9fba751cb8f67f5c70bb23927ef5c807b241596d0b84f515d435b5d2b084
|
Provenance
The following attestation bundles were made for hyprland_socket-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on BlueManCZ/hyprland-socket
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hyprland_socket-0.5.0-py3-none-any.whl -
Subject digest:
0979f651528945a96db6ebdbcac3fcd51998b9c8547ad88d4ea3b34fb92f4c1e - Sigstore transparency entry: 1155218508
- Sigstore integration time:
-
Permalink:
BlueManCZ/hyprland-socket@0e4e2be52ef2108cfe7fcebc82a9d28de242ec91 -
Branch / Tag:
refs/tags/v0.5.0 - Owner: https://github.com/BlueManCZ
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0e4e2be52ef2108cfe7fcebc82a9d28de242ec91 -
Trigger Event:
release
-
Statement type: