Skip to content

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

pip install build
python -m build --wheel

This creates a .whl file in dist/:

dist/mylib-1.0.0-py3-none-any.whl

Protect

pylocket protect \
  --app <APP_ID> \
  --artifact dist/mylib-1.0.0-py3-none-any.whl \
  --platform linux-x64 \
  --python 3.12

Download

pylocket fetch --build <BUILD_ID> --out dist/protected/

The output is a new .whl file with encrypted bytecode.


Installing the Protected Wheel

End-users install the protected wheel with pip:

pip install mylib-1.0.0-py3-none-any.whl

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:

pip install --index-url https://pypi.yourcompany.com/simple/ mylib

Notes

  • All .pyc files 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 --python version should match the target environment where the wheel will be installed.
  • Platform-specific wheels (cp312-cp312-manylinux) are also supported.

See Also