Skip to main content
   ~/  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

Resolved per-call from the env mapping you pass to App (or to the base accessors). No ambient reads, no import-time snapshots — tests pass a plain dict and get full isolation. See docs/MIGRATION.md if you are upgrading from v0.1.

Documentation

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.

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.3.0.tar.gz (11.1 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.3.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codechu_xdg-0.3.0.tar.gz
  • Upload date:
  • Size: 11.1 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.3.0.tar.gz
Algorithm Hash digest
SHA256 1bbb93a70ece7a27b87a3b4ec916ebb7c4387f922b0c7d162117fc32db528a78
MD5 2eaf43a7bf1cb234233ee4a8bc5995fd
BLAKE2b-256 a2a392145d1f0dfcb414cf2733afa2a638ed0130d78c94ab436b6bfbfa362c30

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_xdg-0.3.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: codechu_xdg-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c424ea93597a7c4a80ef42f8a73bece5f562d4279726186004aaa78f74967cc
MD5 e1cd81af461a1d6d04e792a723731a37
BLAKE2b-256 ef38e05a1a984af1ac7ef7450b2961789f44b456d73e07fdfced39a426b55137

See more details on using hashes here.

Provenance

The following attestation bundles were made for codechu_xdg-0.3.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.

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 files

0.2.0

2 files

0.1.0

2 files

Supported by

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