Skip to main content

A zero-dependency tool to add PEP 723 metadata to Python scripts.

Project description

depscripter

depscripter is a zero-dependency CLI tool and library that automatically adds PEP 723 inline script metadata to Python scripts. It scans imports, resolves installed versions from the current environment, and injects the appropriate metadata block.

Installation

Using uv:

uv tool install depscripter
# or run directly
uv run depscripter script.py

Usage

CLI

Pass the path to a python script to generate the metadata. By default, it prints to stdout.

# Preview changes
depscripter script.py

# Modify the file in-place
depscripter script.py --in-place

# Save output to a specific file
depscripter script.py -o output.py

# Specify python version requirement
depscripter script.py --python ">=3.9"

# Manually specify dependencies (override or add)
depscripter script.py --manual "numpy>=2.0" --manual "pandas"

# Disable version pinning (just list packages)
depscripter script.py --no-pin

The tool will:

  1. Parse the script to find imports (ignoring relative imports).
  2. Look up the installed package for each import in the current environment.
  3. Generate a PEP 723 metadata block.
  4. Insert it at the top of the script (preserving shebangs and encoding cookies).

Library

You can also use depscripter as a library:

from depscripter import scan_imports, resolve_packages, generate_script_metadata

code = "import requests"
modules = scan_imports(code)
# {'requests'}

deps = resolve_packages(modules, pin_versions=True)
# {'requests': '2.31.0'}

metadata = generate_script_metadata(deps)
print(metadata)
# /// script
# requires-python = ">=3.12"
# dependencies = [
#     "requests==2.31.0",
# ]
# ///

Development

This project uses uv for management.

# Install dependencies
uv sync

# Run tests
uv run pytest

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

depscripter-0.2.0.tar.gz (182.1 kB view details)

Uploaded Source

Built Distribution

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

depscripter-0.2.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file depscripter-0.2.0.tar.gz.

File metadata

  • Download URL: depscripter-0.2.0.tar.gz
  • Upload date:
  • Size: 182.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"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 depscripter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0e664f1dd8c1dbb73ec5a827499edd8bc63a34ea0724c14df9c47a11745cf700
MD5 8757021d556d9ae36ae8bd9453305459
BLAKE2b-256 340387f0cf6deafcffb8e20added1ae69598655194bd8967d12333a14513e628

See more details on using hashes here.

File details

Details for the file depscripter-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: depscripter-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"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 depscripter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e96f35cf3db4f1836f79cb8d1140d259b9f953bcd70b15f73f32ddc2b502b4c9
MD5 73ec4608d6a53117b8e0d7bd9be3ff19
BLAKE2b-256 c84418370fe2ae24958e38939d433622478c492805620350227760e0c3529dc3

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