Skip to main content

pipx_isolate

a pipx script installer supporting inline script metadata for python scripts

The purpose for this is to be able to isolate the dependencies for small scripts into a virtual environment.

Inline Script Metadata looks like this:

#!/usr/bin/env python3
# /// script
# requires-python = ">=3.13"
# dependencies = [
#     "beautifulsoup4",
#     "click>=8.3.1",
# ]
# ///

import os
import sys
import contextlib
from typing import Sequence, NamedTuple
import click
from bs4 import BeautifulSoup, Doctype

You could either manually add that to your script, or use uv like: uv add --script <PATH> click beautifulsoup4. pipx_isolate add-metadata <PATH> shows you all the import statements and wraps uv add --script.

Once you have a script that has metadata, you can use pipx run --path /path/to/script, which parses the metadata at the top, installs anything that is needed into a venv into ~/.cache/pipx, and then runs the script in that environment.

Running pipx_isolate install <name> looks up the name of the script in your $PATH, and creates a wrapper script that looks like this:

#!/bin/sh
exec /home/username/.local/bin/pipx run --path /full/path/to/name "$@"

This way, if you ever update the metadata at the top, pipx picks up the new changes, and runs it with the correct dependencies in a virtual environment. If you want to pass arguments to pipx run in the generated script, you can do so like: pipx_isolate install <file> --run --no-cache

pipx_isolate install by default creates a bin directory at ~/.local/share/pipx_isolate/bin/ so in order to call the wrapper scripts instead of the original, you should update your $PATH to put that directory near the front of your $PATH:

export PATH="$HOME/.local/share/pipx_isolate/bin:$PATH"

To find/install all the scripts with inline script metadata, I run a command like this:

rg --files-with-matches -e '/// script' | xargs -I{} sh -c "test -x {} && uv export --script {} --quiet >/dev/null && echo {}" | parallel pipx_isolate install

See rg and parallel

Installation

Requires python3.10+

To install with pip, run:

pip install pipx_isolate

Usage

pipx_isolate --help

Tests

git clone 'https://github.com/purarue/pipx_isolate'
cd ./pipx_isolate
pip install '.[testing]'
flake8 ./pipx_isolate
mypy ./pipx_isolate

Metadata

Release files for pipx-isolate 0.1.1

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

Source distribution (sdist)

Source distribution for pipx-isolate 0.1.1
File Size Uploaded
pipx_isolate-0.1.1.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pipx-isolate 0.1.1
File Interpreter ABI Platform
pipx_isolate-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 11.2 kB

Release files / pipx_isolate-0.1.1.tar.gz

Download URL pipx_isolate-0.1.1.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4c4bf97e4f000e86d25fed1eac7e56292bd4029da6791f3e1819d412dfa6e1fc
BLAKE2b-256 checksum
How to use checksums
8ccdbaa5ba7d10082ad7a98a39db2523752c74f339dd0e91a5e4020c88b87d7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / pipx_isolate-0.1.1-py3-none-any.whl

Download URL pipx_isolate-0.1.1-py3-none-any.whl
Size 5.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2449b127a60db779fc04e4f63a6d9c1812709c887b71689bbcdd0e15b4b47c12
BLAKE2b-256 checksum
How to use checksums
ecb4765a349edd1e2dce99af34fa243a486aa9d3eda1c86d8d81f26f02fb6f22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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