Skip to main content

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")

    # Read a live option
    option = hyprland_socket.getoption("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"),
])

# 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

Error handling

All functions raise typed exceptions instead of returning None:

from hyprland_socket import ConnectionError, CommandError

try:
    hyprland_socket.keyword("invalid:option", "value")
except ConnectionError:
    print("Hyprland is not running")
except CommandError as e:
    print(f"Rejected: {e}")

Models

Function Returns
get_monitors() list[Monitor]
get_binds() list[Bind]
get_animations() tuple[list[Animation], list[dict]]
getoption(key) dict

All models are mutable dataclasses with a from_dict() classmethod for construction from Hyprland's JSON responses.

Requirements

  • Python >= 3.12
  • A running Hyprland session (the HYPRLAND_INSTANCE_SIGNATURE environment variable must be set)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hyprland_socket-0.1.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyprland_socket-0.1.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file hyprland_socket-0.1.0.tar.gz.

File metadata

  • Download URL: hyprland_socket-0.1.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hyprland_socket-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e476161553cfdef088e1dea6d5459ab812d58f21583d220b17d99667bd4bcdec
MD5 233d0601bfd68e1c77300945babb6e11
BLAKE2b-256 8e96a74c522afa784c3ce39e90c06694dcec524406b47c7604600542e90ec634

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_socket-0.1.0.tar.gz:

Publisher: publish.yml on BlueManCZ/hyprland-socket

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hyprland_socket-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hyprland_socket-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61450d9e31af4b9ea9a13aa76ce4f5130b44cbbc7d130968d50ba9d13871525c
MD5 c93ea655d45901aeec1801622dd25542
BLAKE2b-256 0f780d2729eb9702e7b9fbb4f62136af8bc068482346a44ec9f7feb246d9c4da

See more details on using hashes here.

Provenance

The following attestation bundles were made for hyprland_socket-0.1.0-py3-none-any.whl:

Publisher: publish.yml on BlueManCZ/hyprland-socket

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page