Skip to main content

PEP 723 wrapper for linting Python scripts

Project description

pep723-loader

A CLI wrapper that auto-installs PEP 723 inline script dependencies before executing linters and other tools.

The Problem

Python scripts with PEP 723 inline metadata declare their dependencies directly in the file:

# /// script
# requires-python = ">=3.11"
# dependencies = [
#   "requests>=2.31.0",
#   "rich>=13.0.0",
# ]
# ///

import requests
from rich import print
# ...

But when you run type checkers or linters on these scripts, they fail because the dependencies aren't installed:

$ mypy script.py
script.py:8: error: Cannot find implementation or library stub for module named "requests"
script.py:9: error: Cannot find implementation or library stub for module named "rich"

The Solution

pep723-loader wraps your linter and automatically installs the inline dependencies first:

$ pep723-loader mypy script.py
# Dependencies installed, then mypy runs successfully

Installation

pip install pep723-loader

Or with uv:

uv tool install pep723-loader

Usage

Command Line

# Wrap any linter or tool
pep723-loader mypy script.py
pep723-loader basedpyright script.py
pep723-loader ruff check script.py
pep723-loader bandit script.py

# Pass any arguments through to the wrapped command
pep723-loader mypy --strict --warn-unreachable script.py

# Works with directories too
pep723-loader mypy scripts/

Pre-commit Integration

There are two ways to use pep723-loader with pre-commit:

Simple: If tools are already installed

First, add the tools to your project's dev dependencies:

uv add --dev pep723-loader mypy

Then configure the hook:

- repo: local
  hooks:
    - id: mypy
      name: mypy
      entry: pep723-loader mypy
      language: system
      types: [python]
      pass_filenames: true

Recommended: Self-contained with uv

This approach keeps tools out of your project's dependencies - uv provides them on-demand:

- repo: local
  hooks:
    - id: mypy
      name: mypy
      entry: uv run -q --no-sync --with pep723-loader --with mypy pep723-loader mypy
      language: system
      types: [python]
      pass_filenames: true

    - id: basedpyright
      name: basedpyright
      entry: uv run -q --no-sync --with pep723-loader --with basedpyright pep723-loader basedpyright
      language: system
      types: [python]
      pass_filenames: true

What do these flags do?

Flag Purpose
-q Quiet mode - suppresses uv's output so only linter output is shown
--no-sync Skip syncing the project's dependencies - faster, we only need the tools
--with <pkg> Temporarily add a package for this invocation

The --with packages are ephemeral - they're not installed into your project's virtualenv. However, they're cached by uv, so after the first run there's no download overhead.

How It Works

  1. Scans Python files passed as arguments for PEP 723 # /// script metadata blocks
  2. Extracts dependencies using uv export --script
  3. Installs dependencies via uv pip install
  4. Executes the wrapped command with all original arguments
  5. Propagates the wrapped command's exit code

Requirements

  • Python 3.10+
  • uv (used for dependency extraction and installation)

License

Apache License 2.0

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

pep723_loader-0.5.0.tar.gz (25.3 kB view details)

Uploaded Source

Built Distribution

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

pep723_loader-0.5.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file pep723_loader-0.5.0.tar.gz.

File metadata

  • Download URL: pep723_loader-0.5.0.tar.gz
  • Upload date:
  • Size: 25.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pep723_loader-0.5.0.tar.gz
Algorithm Hash digest
SHA256 b641bc0fad510473b5013daa5f9ef4ff1880c38718808e7c2d394f457fe6522b
MD5 e94199ad072e4a5ec9033e4c3e611e69
BLAKE2b-256 74e8f768d23fd8612e9a6fb0b464e1279c9f96af4e4cc2dcd7b5c21434713e70

See more details on using hashes here.

File details

Details for the file pep723_loader-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pep723_loader-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pep723_loader-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d020fdcc13b73c5c8edc2424994efd94d0c142ff8188d9190aa7215e6534ea4
MD5 03728297c205e6f663dbf95fe03cf54e
BLAKE2b-256 17087a41d8939ae6f789dbf9bb53718d38beae3a4653fe1285eb0baabb8e9a71

See more details on using hashes here.

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