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 -S uvx autopep723
import requests
import numpy as np
# Your script here...
Note: The -S flag is required for env to properly handle arguments with spaces. Without it, you'll get an error like No such file or directory.
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 PIL→pillow) - 🚀 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
- PEP 723 - Inline script metadata specification
- uv tools guide - Using uv for tool management
- uv issue #6283 - Autodetect dependencies mode proposal
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autopep723-0.1.1.tar.gz.
File metadata
- Download URL: autopep723-0.1.1.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c74c8509538adcea596ef2606649975a6994def03f7782e0538fd73c18366b
|
|
| MD5 |
787ccd9d93e6f4496dabb5fa66a5dea0
|
|
| BLAKE2b-256 |
d2dc925384a41241d172b80007b70588ba845743d393e1cb8f1e4101329fff6e
|
Provenance
The following attestation bundles were made for autopep723-0.1.1.tar.gz:
Publisher:
cd.yml on mgaitan/autopep723
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autopep723-0.1.1.tar.gz -
Subject digest:
a6c74c8509538adcea596ef2606649975a6994def03f7782e0538fd73c18366b - Sigstore transparency entry: 294690053
- Sigstore integration time:
-
Permalink:
mgaitan/autopep723@0038d249d01af1e3b0eacadef43ea4ef3a844c21 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/mgaitan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@0038d249d01af1e3b0eacadef43ea4ef3a844c21 -
Trigger Event:
release
-
Statement type:
File details
Details for the file autopep723-0.1.1-py3-none-any.whl.
File metadata
- Download URL: autopep723-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d29421442da4ec541323b54eccaa4e50d7c42ac608f576c5d362d67c1ded25f
|
|
| MD5 |
04f98a57e6b81e017aa6090d54dc5275
|
|
| BLAKE2b-256 |
eaa35f5459c47d44adad8022e576195260f07bdad9d204f1f7a26b6e07bdd71b
|
Provenance
The following attestation bundles were made for autopep723-0.1.1-py3-none-any.whl:
Publisher:
cd.yml on mgaitan/autopep723
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autopep723-0.1.1-py3-none-any.whl -
Subject digest:
0d29421442da4ec541323b54eccaa4e50d7c42ac608f576c5d362d67c1ded25f - Sigstore transparency entry: 294690066
- Sigstore integration time:
-
Permalink:
mgaitan/autopep723@0038d249d01af1e3b0eacadef43ea4ef3a844c21 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/mgaitan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cd.yml@0038d249d01af1e3b0eacadef43ea4ef3a844c21 -
Trigger Event:
release
-
Statement type: