Contributing
platformdirs is developed on GitHub under the tox-dev organization, and every development task runs through tox. This page summarizes the workflow from the project's CONTRIBUTING.md: setting up, running tests and checks, writing changelog fragments, and submitting a pull request.
Getting Started
Fork the repository on GitHub, clone your fork, and create a branch from main with a descriptive name such as fix/issue-123, feat/new-directory-type or docs/improve-readme.
Install tox and list the available environments:
pip install tox
tox list
The project's tox.toml requires tox>=4.64.7 and skips Python versions that are not installed.
tox Environments
| Command | What it does |
|---|---|
tox r -e 3.14 |
Run the test suite with pytest under Python 3.14 (also 3.11 to 3.15, 3.15t and pypy3.11) |
tox r -e 3.14,3.13,3.12,coverage |
Run tests on several versions, then combine coverage and compare it with origin/main (override with DIFF_AGAINST) |
tox r -e fix |
Run the pre-commit hooks, including ruff formatting and linting, and fix what they can |
tox r -e type |
Type-check with ty |
tox r -e docs |
Check the prose with proselint and build the Sphinx documentation with warnings as errors; the result is in .tox/docs_out/html/index.html |
tox r -e pkg_meta |
Build the package and validate its metadata and description rendering |
tox r -e dev |
Create a development environment with an editable install and all dependencies |
tox r |
Run everything, as you should before opening a pull request |
Some environments (dev, docs, type) use dependency groups that require Python 3.15.
Tests and Coverage
Add tests for every feature and bug fix; they must pass on all supported Python versions. The project targets 100% coverage. Each test run also prints a diff-cover report of the lines your branch changed. The test suite includes tests/test_comp_with_appdirs.py, which installs appdirs and checks that platformdirs stays compatible with it.
Platform-specific code should be tested on the target platform. The per-platform logic lives in src/platformdirs/<platform>.py (unix.py, macos.py, windows.py, android.py, ios.py), with shared XDG handling in _xdg.py.
Code Style
Follow the patterns already in the code base. All code must pass tox r -e fix (ruff) and carry type annotations, which tox r -e type checks. Keep functions focused and explicit.
Documentation
For user-facing changes, update the reStructuredText files in docs/ (platform behavior goes in docs/platforms.rst), add docstrings to new public functions, and run tox r -e docs.
Changelog Fragments
Each user-facing change needs one fragment file in docs/changelog/. The name starts with + and ends with a category, for example +linux-runtime.bugfix.rst or +python-315.feature.rst. Write only the change itself:
Skip an XDG runtime directory owned by another user.
Do not add a PR number or credits; the news check rejects them, and the release tooling adds the PR link and author byline when a release is prepared.
| Category | Use for |
|---|---|
feature |
New capabilities and Python support changes |
change |
Changed behavior |
bugfix |
Bug fixes |
doc |
Documentation that affects users |
security, performance, deprecation, removal, breaking, packaging |
When that distinction matters to users |
Maintenance-only work stays out of the changelog. If a pull request needs no entry, apply the skip news label (it can be added after opening the PR).
Commit Messages
Use Commitizen conventions, <type>: <summary>, with an optional body explaining motivation and approach. Common types are feat, fix, docs, refactor and test:
fix: handle missing XDG_RUNTIME_DIR on FreeBSD
Falls back to /var/run/user/<uid> when /run/user/<uid> does not exist,
addressing issues on FreeBSD systems that don't create the runtime directory.
Pull Requests
Make sure tox r passes, push to your fork, and open a pull request against main. Fill in the template with a description, related issues and how you tested. Then wait for CI and address review feedback.
Build and Versioning
The package is built with hatchling; its version comes from the git tag through hatch-vcs, which generates src/platformdirs/version.py at build time. That is why a plain source checkout without a build has no version.py: install it (for example with tox r -e dev or pip install -e .) before importing.
Security
Security issues are handled according to the project's security policy. The repository also documents its threat model in THREAT_MODEL.md.
License
platformdirs is released under the MIT License; by contributing, you agree that your contributions are licensed under it.