Vendorpy is a command-line tool that automates the process of vendoring Python packages for Cloudflare Workers. It simplifies the vendoring process by handling the creation of virtual environments, generating requirements.txt with pruned built-in packages, and installing vendored packages.
- Github repository: https://github.com/bitnom/vendorpy/
- Documentation https://bitnom.github.io/vendorpy/
WARNING: Any pre-1.0 release of this application may contain unvetted vibe-code
pip install vendorpy- Python 3.12 or higher (required for Cloudflare Workers compatibility)
uvpackage manager (for generating requirements.txt)
The easiest way to vendor packages is using the auto-vendor command, which automatically detects which packages need to be vendored and handles the entire process in a single step:
vendorpy auto-vendorThis will:
- Analyze your project dependencies using the lockfile
- Determine which packages are built-in vs. which need vendoring
- Create the vendor.txt file automatically
- Generate a requirements.txt file with built-in packages pruned
- Set up the necessary virtual environments
- Vendor the required packages to src/vendor
- Automatically configure your wrangler.toml or wrangler.jsonc file
Example output:
╭───────── Step 1: Package Detection ─────────╮
│ Detecting packages that need to be vendored │
╰─────────────────────────────────────────────╯
Analyzing project dependencies...
Package Analysis Results
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━━━━━┓
┃ Package Type ┃ Count ┃ Packages ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━━━━━┩
│ Need Vendoring │ 2 │ jinja2, markupsafe│
│ Built-in (No Vendoring Required) │ 1 │ fastapi │
└──────────────────────────────────┴───────┴───────────────────┘
╭────────── Step 2: Vendor File Creation ──────────╮
│ Creating vendor.txt with 2 packages that need │
│ vendoring │
╰────────────────────────────────────────────────────╯
✅ Created vendor.txt
...
╭────────── Step 5: Wrangler Configuration ──────────╮
│ Configuring wrangler for vendoring │
╰────────────────────────────────────────────────────╯
✅ Successfully configured wrangler.toml for vendoring
If you prefer more control, you can also use the individual commands:
# Check if a package is built-in or needs to be vendored
vendorpy isbuiltin <package_name>
# For example
vendorpy isbuiltin jinja2 # Not built-in, needs vendoring
vendorpy isbuiltin fastapi # Built-in, no need to vendorCreate a vendor.txt file with the packages that need to be vendored:
jinja2
markupsafe
# Add other packages that need to be vendored
vendorpy vendor --vendor-file vendor.txt --vendor-dir src/vendorTo see all built-in packages available in Cloudflare Workers:
vendorpy list-built-inTo check if a specific package is built-in or needs to be vendored:
vendorpy isbuiltin <package_name>For example:
vendorpy isbuiltin fastapi # Built-in package
vendorpy isbuiltin flask # Not built-in, needs vendoringYou can also automatically add non-built-in packages to your vendor.txt file:
vendorpy isbuiltin flask --add # Checks and adds to vendor.txt if neededOptions:
-r, --requirements-file PATH Path to the requirements.txt file to
generate [default: requirements.txt]
-v, --vendor-file PATH Path to the vendor.txt file to generate
[default: vendor.txt]
-d, --vendor-dir PATH Directory to install vendored packages to
[default: src/vendor]
-p, --python-version TEXT Python version to use for vendoring (must be
3.12 for Cloudflare Workers) [default: 3.12]
--help Show this message and exit.
Options:
-v, --vendor-file PATH Path to the vendor.txt file containing
packages to vendor [default: vendor.txt]
-r, --requirements-file PATH Path to the requirements.txt file to
generate [default: requirements.txt]
-d, --vendor-dir PATH Directory to install vendored packages to
[default: src/vendor]
-p, --python-version TEXT Python version to use for vendoring (must be
3.12 for Cloudflare Workers) [default: 3.12]
--skip-built-in / --include-built-in
Skip built-in Cloudflare packages in
requirements.txt [default: skip-built-in]
--help Show this message and exit.
Options:
-a, --add Add the package to vendor.txt if it's not built-in
-v, --vendor-file PATH Path to the vendor.txt file
[default: vendor.txt]
--help Show this message and exit.
After vendoring your packages, Vendorpy will automatically configure your wrangler.toml or wrangler.jsonc file to include the vendor directory:
[[rules]]
globs = ["vendor/**"]
type = "Data"
fallthrough = trueIf no wrangler configuration file is found, Vendorpy will show instructions for manual configuration.
Vendorpy includes comprehensive error handling to help diagnose and resolve issues:
-
Python Version: Ensure you have Python 3.12 installed as it's required for Cloudflare Workers compatibility.
-
Missing Dependencies: If you encounter errors about missing dependencies, make sure
uvis installed:pip install uv
-
Empty vendor.txt: Your vendor.txt file must contain at least one package to vendor.
-
Package Not Found: If a package can't be found, check if it's available on PyPI or if it's a built-in package:
vendorpy isbuiltin <package_name>
-
Permission Issues: If you encounter permission errors when creating virtual environments, try running the command with appropriate permissions.
The tool provides detailed error messages to help diagnose issues. If you encounter persistent problems, please open an issue on GitHub.
git clone https://github.com/bitnom/vendorpy.gitThen, install the environment and the pre-commit hooks with
make installThis will also generate your uv.lock file
Initially, the CI/CD pipeline might be failing due to formatting issues. To resolve those run:
uv run pre-commit run -aLastly, commit the changes made by the two steps above to your repository.
git add .
git commit -m 'Fix formatting issues'
git push origin mainThe CI/CD pipeline will be triggered when you open a pull request, merge to main, or when you create a new release.
To finalize the set-up for publishing to PyPI, see here. For activating the automatic documentation with MkDocs, see here. To enable the code coverage reports, see here.
- Create an API Token on PyPI.
- Add the API Token to your projects secrets with the name
PYPI_TOKENby visiting this page. - Create a new release on Github.
- Create a new tag in the form
*.*.*.
For more details, see here.
Repository initiated with fpgmaas/cookiecutter-uv.