Protect your python script, encrypt it as .pye and decrypt when import it
Protect your python script, encrypt it as .pye and decrypt when import it
Protect your python script, encrypt .pyc to .pye and decrypt when import it
pyconcrete and read the MAIN.pye which encrypted by your passphrase.import MODULE, pyconcrete import hook will try to find MODULE.pye first
and then decrypt MODULE.pye via _pyconcrete.pyd and execute decrypted data (as .pyc content)_pyconcrete.pyd (like DLL or SO)
the secret key would be hide in binary code, can't see it directly in HEX view.pyz (zip archive) files containing encrypted .pye modules,
it extracts and decrypts __main__.pye from the archive, and modules inside the .pyz can import each other via the PyeZipImporter hookPyconcrete has transitioned to using meson-python as its build backend starting from version 1.0.0. This provides a more powerful build mechanism and supports newer Python versions.
For older Python support:
For unix base
For windows base
Due to security considerations, you must provide a passphrase to create a secret key for encrypting Python scripts:
Build Process
-C or --config-settings.--no-cache-dir to avoid use pip's cached package which already built by old passphrase.# basic usage
$ pip install pyconcrete \
--no-cache-dir \
--config-settings=setup-args="-Dpassphrase="
# assign multiple options
$ pip install pyconcrete \
--no-cache-dir \
--config-settings=setup-args="-Dpassphrase=" \
--config-settings=setup-args="-Dmode=exe" \
--config-settings=setup-args="-Dinstall-cli=true"--config-settings=setup-args="-D="passphrase: (Mandatory) To generate secret key for encryption.ext: Able to assign customized encrypted file extension. Which default is .pye.mode: exe or lib. Which default is exe.install-cli: Determine to install pyecli or not. Which default is true.py to *.pye$ pyecli compile --pye -s=
$ pyecli compile --pye -s=
$ pyecli compile --pye -s= -e=*.py *.pyc or copy *.pye to other folderpython.
You must use pyconcrete to process the main.pye script.
pyconcrete(exe) will be installed in your system path (ex: /usr/local/bin)pyconcrete main.pye
src/*.pye # your libsmode=lib when installationmain.py # import pyconcrete and your lib
pyconcrete/* # put pyconcrete lib in project root, keep it as original files
src/*.pye # your libs.pye modules into a single .pyz zip archive for easy distribution.pyz archive can be executed directly by pyconcrete# basic: pack a source directory into a .pyz (requires __main__.py in source)
$ pyecli build-zip --source= --output=app.pyz
# specify an entry point (generates __main__.py automatically)
$ pyecli build-zip --source= --output=app.pyz --main=pkg.mod:fn
# use custom encrypted file extension
$ pyecli build-zip --source= --output=app.pyz --ext=.pyebuild-zip arguments--source: (Mandatory) Source directory containing .py files to package--output: (Mandatory) Output path. Use .pyz for executable archive or .zip for library archive--main: Entry point in pkg.mod:fn format. Generates __main__.py that calls the specified function--ext: Custom encrypted file extension (default: .pye)--ignore-file-list: File patterns to ignore during build$ pyconcrete app.pyz [args...]pyconcrete detects the .pyz file, extracts __main__.pye from the archive, decrypts and executes itpyconcrete app.pyz # execute the encrypted zip archivesys.path are importable — pyconcrete's PyeZipImporter hook automatically finds and decrypts .pye modules inside zip filesimport sys
import pyconcrete
sys.path.insert(0, 'libs.zip')
import mylib # loads mylib.pye from libs.zipmain.pye # your entry script
libs.zip # zip containing encrypted .pye modules$ pytest tests$ just test$ just test 3.10Example environment: Windows 11, Visual Studio 2022
..\meson.build:1:0: ERROR: Unknown compiler(s): [['icl'], ['cl'], ['cc'], ['gcc'], ['clang'], ['clang-cl'], ['pgcc']]..\meson.build:23:31: ERROR: Python dependency not foundhttps://mesonbuild.com/SimpleStart.html
pyconcrete is an experimental project, there is always a way to decrypt .pye files, but pyconcrete just make it harder.
No open issues yet, or sync has not completed.