PyXDG

0.28 · active · verified Sat Apr 11

PyXDG is a Python library that provides implementations of various freedesktop.org standards. These standards define common desktop operations and components, such as determining file MIME types, getting icons for applications, and accessing application menus. It is currently at version 0.28 and is actively maintained, with releases addressing compatibility and bug fixes.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `xdg.BaseDirectory` to get standard XDG paths and `xdg.Mime` to determine a file's MIME type.

import os
from xdg import BaseDirectory, Mime

# Get user's data home directory
data_home = BaseDirectory.xdg_data_home
print(f"XDG Data Home: {data_home}")

# Get preferred configuration directories
config_dirs = BaseDirectory.xdg_config_dirs
print(f"XDG Config Dirs: {config_dirs}")

# Find the MIME type of a file (example with a dummy file)
# Create a dummy file for demonstration
dummy_file_path = os.path.join(data_home, 'test.txt')
with open(dummy_file_path, 'w') as f:
    f.write('Hello, PyXDG!')

mime_type = Mime.get_type(dummy_file_path)
print(f"MIME type of '{dummy_file_path}': {mime_type}")

# Clean up dummy file
os.remove(dummy_file_path)

view raw JSON →