How To: Protect a Python Wheel¶
PyLocket can protect .whl (wheel) packages, allowing you to distribute encrypted Python libraries through private package indexes.
Prerequisites¶
- PyLocket CLI installed and authenticated
- An app registered with PyLocket
- A built wheel file (
.whl)
Build a Wheel¶
This creates a .whl file in dist/:
Protect¶
pylocket protect \
--app <APP_ID> \
--artifact dist/mylib-1.0.0-py3-none-any.whl \
--platform linux-x64 \
--python 3.12
Download¶
The output is a new .whl file with encrypted bytecode.
Installing the Protected Wheel¶
End-users install the protected wheel with pip:
The PyLocket runtime is bundled inside the wheel. When the library is imported, the bootstrap code activates and validates the license.
Private Package Index¶
For automated distribution, host the protected wheel on a private PyPI server:
# Upload to a private index
twine upload --repository private dist/protected/mylib-1.0.0-py3-none-any.whl
End-users install from your private index:
Notes¶
- All
.pycfiles inside the wheel are encrypted. Non-Python files (data, configs) are passed through unchanged. - The protected wheel includes the PyLocket runtime as a bundled extension module.
- The
--pythonversion should match the target environment where the wheel will be installed. - Platform-specific wheels (
cp312-cp312-manylinux) are also supported.