Skip to main content

Auto-generate PEP 723 metadata for Python scripts by analyzing imports

Project description

autopep723

A CLI tool that automatically generates PEP 723 metadata for Python scripts by analyzing their imports and dependencies.

What it does

autopep723 parses Python scripts to detect third-party package imports and generates the appropriate PEP 723 inline script metadata. This metadata allows tools like uv run to automatically install and manage dependencies when executing scripts.

Installation

You can run the tool directly using uvx:

uvx autopep723

To install it permanently:

uv tool install autopep723

Quick Start

# Run script with automatically detected dependencies
autopep723 script.py

# Print PEP 723 metadata to stdout  
autopep723 check script.py

# Update the script file with metadata
autopep723 upgrade script.py

Shebang Integration

You can use autopep723 directly as a shebang:

#!/usr/bin/env uvx autopep723
import requests
import numpy as np

# Your script here...

This allows scripts to be executable without explicitly declaring dependencies. The tool detects imports and runs the script using uv run with the required packages installed on-the-fly in an ephemeral environment.

Features

  • 🔍 Automatic dependency detection via AST analysis
  • 📦 Import name mapping (e.g., import PILpillow)
  • 🚀 Multiple output modes (print, update, or run)
  • PEP 723 compliant metadata generation
  • 🛡️ Built-in module filtering excludes standard library
  • 🔧 Graceful error handling for syntax errors

Documentation

For detailed usage, examples, and API reference, see the full documentation.

Related

Contributing

Pull requests are welcome! 🎉

  • One change per PR - Keep it focused
  • Tests required - Maintain coverage standards
  • Follow conventions - Use pytest and pytest-mock
  • Be thoughtful - This is a minimal wrapper, new dependencies need strong justification

AI assistance is encouraged (this project is ~100% AI-generated), but contributions must meet quality standards.

We follow a zero-tolerance policy for harassment of any kind. Be respectful and inclusive.

License

MIT - see LICENSE file for details.

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

autopep723-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

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

autopep723-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file autopep723-0.1.0.tar.gz.

File metadata

  • Download URL: autopep723-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for autopep723-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8c40d4a4706b2353e08014831a708a428455f87fb03c0e5647b24a1b4f92c6b8
MD5 fbef3874f54fd8e9b7249c4b55bfb488
BLAKE2b-256 431f42a95ba0a2e4a1b89091959ad744eb0dac234d26954a14b57c3a421fa03b

See more details on using hashes here.

Provenance

The following attestation bundles were made for autopep723-0.1.0.tar.gz:

Publisher: cd.yml on mgaitan/autopep723

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autopep723-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: autopep723-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for autopep723-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 da1584da18dcb670842fda1f9bb75abf763547d724efbb9a6c199c22b0fc78e1
MD5 5b7d5832b0b566ebf37c14acb6379343
BLAKE2b-256 88508aed8dc8b93cfb33d1af93bc26c2d348399945b632c40d05a3018b937cc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for autopep723-0.1.0-py3-none-any.whl:

Publisher: cd.yml on mgaitan/autopep723

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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