Cloudflare Python workers vendoring CLI tool.
Project description
vendorpy
Cloudflare Python Workers Vendoring CLI Tool
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/
Installation
pip install vendorpy
Requirements
- Python 3.12 or higher (required for Cloudflare Workers compatibility)
uvpackage manager (for generating requirements.txt)
Usage
Automatic Vendoring (Recommended)
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-vendor
This 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
Manual Vendoring Process
If you prefer more control, you can also use the individual commands:
1. Check Which Packages Need Vendoring
# 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 vendor
2. Create a Vendor.txt File
Create a vendor.txt file with the packages that need to be vendored:
jinja2
markupsafe
# Add other packages that need to be vendored
3. Run the Vendor Command
vendorpy vendor --vendor-file vendor.txt --vendor-dir src/vendor
List Built-in Packages
To see all built-in packages available in Cloudflare Workers:
vendorpy list-built-in
Check if a Package is Built-in
To 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 vendoring
You can also automatically add non-built-in packages to your vendor.txt file:
vendorpy isbuiltin flask --add # Checks and adds to vendor.txt if needed
Command Options
Auto-Vendor Command
Options:
-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.
Vendor Command
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.
IsBuiltin Command
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.
Cloudflare Worker Configuration
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 = true
If no wrangler configuration file is found, Vendorpy will show instructions for manual configuration.
Error Handling and Troubleshooting
Vendorpy includes comprehensive error handling to help diagnose and resolve issues:
Common 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.
Getting started with development
1. Clone Repository
git clone https://github.com/bitnom/vendorpy.git
2. Set Up Your Development Environment
Then, install the environment and the pre-commit hooks with
make install
This will also generate your uv.lock file
3. Run the pre-commit hooks
Initially, the CI/CD pipeline might be failing due to formatting issues. To resolve those run:
uv run pre-commit run -a
4. Commit the changes
Lastly, commit the changes made by the two steps above to your repository.
git add .
git commit -m 'Fix formatting issues'
git push origin main
The 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.
Releasing a new version
- 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.
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 vendorpy-0.1.0.tar.gz.
File metadata
- Download URL: vendorpy-0.1.0.tar.gz
- Upload date:
- Size: 51.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e68a26eb36e732902f57b388ab8b8d0bf51b2d73b8fc9729bc0a8cbd37fe25f0
|
|
| MD5 |
4e206fae2ceeca96b60ecd6c64ff6842
|
|
| BLAKE2b-256 |
4e476608c1789a77853d812d1a781588e5d4b84c52b7dacdfbeca0d6036a6ea7
|
File details
Details for the file vendorpy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: vendorpy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cc188f2cfec7fed5d467a227b8474eaf742f627c4384e71c1ed12d14cc204cb
|
|
| MD5 |
1f2ecaec10bafd48892fce7dd18fb078
|
|
| BLAKE2b-256 |
0bc64dae63cabf8093950f6de307a691eacab8348bc1017cdf2bda214423f0b9
|