~/ 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 -pfor all 5 dirsmigrate()— 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
docs/API.md— full API referencedocs/MIGRATION.md— v0.1 → v0.2 upgrade guidedocs/RECIPES.md— common patterns (testing, legacy migration, multi-user runtime dirs, vendor-namespacing rationale)
Validation
vendorandproductmust be non-empty and not contain/.- All directories use safe
mkdir -psemantics — 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.
Metadata
Release files for codechu-xdg 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| codechu_xdg-0.3.0.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| codechu_xdg-0.3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.5 kB
Release files / codechu_xdg-0.3.0.tar.gz
| Download URL | codechu_xdg-0.3.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1bbb93a70ece7a27b87a3b4ec916ebb7c4387f922b0c7d162117fc32db528a78
|
|
BLAKE2b-256 checksum How to use checksums |
a2a392145d1f0dfcb414cf2733afa2a638ed0130d78c94ab436b6bfbfa362c30
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2026.
Transparency logRelease files / codechu_xdg-0.3.0-py3-none-any.whl
| Download URL | codechu_xdg-0.3.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7c424ea93597a7c4a80ef42f8a73bece5f562d4279726186004aaa78f74967cc
|
|
BLAKE2b-256 checksum How to use checksums |
ef38e05a1a984af1ac7ef7450b2961789f44b456d73e07fdfced39a426b55137
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2026.
Transparency log