Skip to main content

Vendor-namespaced XDG Base Directory paths for Linux desktop apps.

Project description

   ~/  codechu-xdg
   ├── .config/    <vendor>/<product>/   settings live here
   ├── .cache/     <vendor>/<product>/   throwaway, regenerable
   ├── .local/share/  <vendor>/<product>/   user data, keep it
   ├── .local/state/  <vendor>/<product>/   logs, history
   └── $XDG_RUNTIME_DIR/<vendor>/<product>/  sockets, pids

Vendor-namespaced XDG Base Directory paths — five dirs, one rule.

codechu-xdg

Vendor-namespaced XDG Base Directory paths for Linux desktop apps. Tiny — ~80 LOC, stdlib-only, no dependencies.

pip install codechu-xdg

What it gives you

  • 5 standard XDG path types: config, cache, data, state, runtime
  • Mandatory vendor + product namespace — every path is $XDG_BASE/<vendor>/<product>/, so multiple products from the same publisher live under one directory (one ~/.config/<vendor>/ reveals all your products)
  • ensure()mkdir -p for all 5 dirs
  • migrate() — idempotent legacy → new path mover (run once at startup to upgrade users from earlier layouts)

Quick examples

Basic

from codechu_xdg import App

app = App(vendor="codechu", product="disk-cleaner")
app.ensure()  # create all 5 dirs

# Paths
settings  = app.config_dir  / "settings.json"
db_cache  = app.cache_dir   / "du_cache.db"
snapshots = app.data_dir    / "snapshots.db"
log_file  = app.state_dir   / "app.log"
pid_file  = app.runtime_dir / "watchdog.pid"
sock_file = app.runtime_dir / "control.sock"

Convenience helpers

For common file types, helpers eliminate dir / "name" boilerplate:

app.settings_file()                # config_dir / settings.json (default name)
app.settings_file("themes.json")   # config_dir / themes.json
app.cache_file("du_cache.db")
app.data_file("snapshots.db")
app.log_file()                     # state_dir / app.log
app.runtime_file("watchdog.pid")

Cleanup at shutdown / on demand

# Wipe stale sockets and pid files — recreated on next run.
app.remove_runtime()

# Or full cache wipe (regeneratable). Returns count of removed entries.
n = app.remove_cache()
print(f"cleared {n} cache entries")

Migration from earlier layouts

When you change directory conventions across versions, migrate() moves files idempotently — runs safely on every startup:

from pathlib import Path

moved = app.migrate({
    # v0.0 layout: everything under ~/.config/<product>/
    Path.home() / ".config" / "disk_cleaner" / "settings.json":
        app.config_dir / "settings.json",
    Path.home() / ".config" / "disk_cleaner" / "du_cache.db":
        app.cache_dir / "du_cache.db",
    Path.home() / ".config" / "disk_cleaner" / "snapshots.db":
        app.data_dir / "snapshots.db",
})
print(f"migrated {moved} files")

Files at the new path are never overwritten — if new exists, the old is left in place. This makes it safe to run on every startup.

Why a vendor namespace

Single-vendor apps put files at ~/.config/<product>/ — fine for one product. Multi-product publishers benefit from grouping:

~/.config/codechu/
├── disk-cleaner/
├── file-explorer/
└── system-monitor/

One directory, full inventory. Pattern used by JetBrains (~/.config/JetBrains/) and Mozilla (~/.mozilla/).

Path resolution

Standard XDG environment variables:

Path Env var Default
config XDG_CONFIG_HOME ~/.config
cache XDG_CACHE_HOME ~/.cache
data XDG_DATA_HOME ~/.local/share
state XDG_STATE_HOME ~/.local/state
runtime XDG_RUNTIME_DIR /run/user/$UID

Honored at module import time. Re-import / reload for env changes during tests.

Validation

  • vendor and product must be non-empty and not contain /.
  • All directories use safe mkdir -p semantics — no race-on-create.

Multi-platform?

This library is Linux-only (XDG is a Linux/Unix spec). For macOS or Windows in addition to Linux, see platformdirs on PyPI — note that it does not enforce a vendor namespace on Linux.

License

MIT — see LICENSE.

Part of Codechu.

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

codechu_xdg-0.2.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

codechu_xdg-0.2.0-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file codechu_xdg-0.2.0.tar.gz.

File metadata

  • Download URL: codechu_xdg-0.2.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_xdg-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c26cdd1cb685a0d69bf74f6d90641095e8255b62273202f0beb8a5979c549bd4
MD5 c4f40d2c714db0e8f4194197a1ad1f32
BLAKE2b-256 8e9a2aabb6c343d5858c1985a8813ac5b07322cbfe6f342a0a8813ce85a0bcd2

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_xdg-0.2.0.tar.gz:

Publisher: release.yml on codechu/xdg-py

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

File details

Details for the file codechu_xdg-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: codechu_xdg-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for codechu_xdg-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aab904f75a3ab56dc41e08a8ef1dce59525a9ea97cd5ee2b94bc679f0e585810
MD5 89bccb038e715428ca583df46991420c
BLAKE2b-256 bf630cd9e4976e4c0a63547e67b1fe55417a608bd0e011da498f3b52151a968a

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_xdg-0.2.0-py3-none-any.whl:

Publisher: release.yml on codechu/xdg-py

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