Skip to main content

Package Developer Experience (DX) Toolkit [Pkgdx]

PyPI - Version Python Version from PEP 621 TOML Checked with mypy prek uv Ruff

I created pkgdx as a way to improve DX for my Python projects. The package is installed as as a development dependency, providing a command-line interface (CLI) for canonical standards configuration.

Overview

pkgdx centralises creation and implementation of coding standards across projects, providing a single source of truth for toolchain configuration:

  1. Mypy (Python static type checking)
  2. Ruff (Python linting & formatting)
  3. PyMarkdown (Markdown linting)
  4. detect-secrets (secret detection)
  5. Prek (hook framework)

Quick start

  1. Run uv add --dev pkgdx for a consuming project
  2. Run uv run pkgdx init to configure hooks and install Git shims
  3. Run uv run pkgdx config --export to export toolchain config files

The config files; hooks.toml, mypy.ini, pymarkdown.toml and ruff.toml are exported to $PKGDX_CONFIG_DIR | %APPDATA%/pkgdx | $XDG_CONFIG_HOME/pkgdx | ~/.config/pkgdx.

  1. Modify these files to maintain a new global canonical standards config
  2. Delete a file to revert to the repsective, bundled config
  3. Run uv run pkgdx config to check config detection and location

To quickly demo pkgdx, clone this repository, cd into ./pkgdx/ and run the command below:

just consumer-demo

Demo Preview

Further installation and setup guidance is available below.

Why?

Other methods of maintaining standards include templating tools like Cookiecutter or Copier, which inject configurations directly into the project pyproject.toml and/or root directory.

pkgdx automates the implementation of a common standard through pre-commit hooks and CI/CD, removing the need for extensive pyproject.toml boilerplate.

How?

Configuration files and CLI are contained in the standards/ subpackage and developments tools have console scripts ([project.scripts]) and pre-commit hooks (.pre-commit-hooks.yaml), which are installed through the CLI via Prek.

When Prek runs a hook (e.g. pkgdx-lint), the CLI intercepts the command and executes the corresponding tool with a bundled configuration.

As pkgdx is versioned and tagged, updates can be implemented across all projects via standard dependency updates and prek update command.

Consuming projects can add project-specific requirements to the pyproject.toml, which can be implemented through commands such as uv run mypy.

To apply the canonical standards to a project, run the init command:

uv run pkgdx init

To see verbose logging output, use the --debug or -d option, before or after the command:

uv run pkgdx init -d

To overwrite or reset an existing prek.toml in the project root, use the --reset option:

uv run pkgdx init --reset

Exit codes are 0 for success (with or without warnings), 1 for a failure, 2 for a usage error, 70 for an unexpected error - a bug, please report it - and 130 for Ctrl-C. The pre-commit hooks exit with the wrapped tool's code, and print error: <message> for a pkgdx failure, such as a wrapped tool not found on PATH.

To see which configuration file each hook uses, run the config command. See Adopting your own standards.

uv run pkgdx config

Installation

This project is hosted on GitLab and each release is published to PyPI and the GitLab project Package Registry. The project is also mirrored on GitHub.

PyPI

uv add --dev pkgdx

Package registry

uv add pkgdx --dev --index gitlab=https://gitlab.com/api/v4/projects/82928123/packages/pypi/simple

Project URL

uv add --dev git+https://gitlab.com/andyrids/pkgdx.git
uv add --dev git+https://gitlab.com/andyrids/pkgdx.git@v0.6.0

CI/CD integration

Pkgdx can be included in GitLab/Github CI/CD pipelines to enforce centralised standards without heavy boilerplate across each CI/CD YAML config.

Adopting your own standards (external users)

pkgdx ships bundled canonical standards. To change them without forking, place your own files in a user config directory. Forking remains an option for teams that want versioned, tagged standards (see Fork the repo).

(1) Know where the user config directory is

pkgdx looks for the user config directory in this order:

  1. The directory named by the PKGDX_CONFIG_DIR environment variable, if it is set and non-empty.
  2. The platform default:
    • Windows: %APPDATA%\pkgdx
    • Linux, macOS and other OSes: $XDG_CONFIG_HOME/pkgdx if XDG_CONFIG_HOME is an absolute path, otherwise ~/.config/pkgdx

If PKGDX_CONFIG_DIR is set but is not an existing directory, the lint, format, typing and markdown hooks, pkgdx init and pkgdx config fail with exit code 1 and a single error message without a traceback. A missing platform directory is normal and is ignored.

(2) Add your configuration files

Place any of these files in the user config directory:

  • ruff.toml - Ruff linting & formatting rules
  • mypy.ini - Mypy static typing rules
  • pymarkdown.toml - PyMarkdown linting rules
  • hooks.toml - Prek config template

Each file is chosen independently. If the user config directory holds a file with one of these names, pkgdx uses it; otherwise it uses the bundled file. A directory holding only ruff.toml overrides Ruff and nothing else.

detect-secrets has no configuration file, so it always uses its bundled settings.

(3) Check and seed with pkgdx config

uv run pkgdx config

This prints one row per file on standard output: its name, its source (user or bundled) and its resolved path. A summary line on standard error names the user config directory and whether PKGDX_CONFIG_DIR set it.

To start from the bundled files, export them into the user config directory:

uv run pkgdx config --export

--export creates the platform directory if needed, copies each bundled file that is missing and never overwrites an existing file. It prints one line per file, created or unchanged, in the same format as pkgdx init.

(4) CI & team parity

The user config directory lives on your machine. Without further action, CI and collaborators fall back to the bundled config, so results can differ between local runs and pipelines.

Recommended pattern:

  1. Keep the four files in your own standards Git repository.
  2. Clone that repository locally and either use it as the user config directory or point PKGDX_CONFIG_DIR at it.
  3. In CI, clone the same repository and export PKGDX_CONFIG_DIR to the clone.
lint-job:
  variables:
    PKGDX_CONFIG_DIR: $CI_PROJECT_DIR/.pkgdx-standards
  before_script:
    - git clone --depth 1 https://gitlab.com/your-group/your-standards.git "$PKGDX_CONFIG_DIR"
  script:
    - uv run pkgdx-lint-hook

Alternative: commit the four files to each project (for example in .pkgdx/) and set PKGDX_CONFIG_DIR=.pkgdx. A relative path is resolved against the working directory.

Fork the repo (alternative for teams)

Use a fork when you want standards that are versioned and released with the package.

  1. Fork the repo to your own namespace.
  2. Modify the files in src/pkgdx/standards/ (mypy.ini, pymarkdown.toml, ruff.toml and hooks.toml).
  3. In src/pkgdx/standards/hooks.toml, change the repo value from "https://gitlab.com/andyrids/pkgdx" to your forked repo URL, and set rev to the tag you will create.
  4. Tag a new release. The CI/CD pipeline builds and publishes the package to your Package Registry, which you can install as a dev dependency via the repo URL or Package Registry URL.
  5. The publish-pypi-job uploads to PyPI from protected v* tags only. To publish your fork there, rename the package and register your own PyPI trusted publisher; otherwise delete the job.

Contribution

Contributions are welcome and these should be made through the GitLab repository.

Metadata

Release files for pkgdx 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pkgdx 0.6.0
File Size Uploaded Provenance Actions
pkgdx-0.6.0.tar.gz 29.1 kB Without provenance Details for pkgdx-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pkgdx 0.6.0
File Interpreter ABI Platform Actions
pkgdx-0.6.0-py3-none-any.whl Python 3 none any Details for pkgdx-0.6.0-py3-none-any.whl

Total release size: 58.3 kB

Release files / pkgdx-0.6.0.tar.gz

Download URL pkgdx-0.6.0.tar.gz
Size 29.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c984a9788768d779393e1c593c829c4af08113c7a01b53b5277ba4a52e68718b
BLAKE2b-256 checksum
How to use checksums
4470c2a3409f1ef271aaea71dafe962c6fba0f17c79cc72e5776db0bfdaa848a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pkgdx-0.6.0-py3-none-any.whl

Download URL pkgdx-0.6.0-py3-none-any.whl
Size 29.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6fce50c9c5fe74f16307e176010ab774b0295526b694db7e8d3779a4d10b9e5d
BLAKE2b-256 checksum
How to use checksums
8f047e466062e2c6e587a7be97cefe230364c3f3b4efb9e8a28789cc3b1d013c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pkgdx 0.6.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page