py2sec
May 29, 2020 · View on GitHub
OS Support
Linux && MacOS && Windows
P.S. Windows User May encounter the error
error: command 'cl.exe' failed: No such file or directory
Please install Visual C++ Build Tools matches your Win version
What is py2sec
- py2sec is a Cross-Platform, Fast and Flexible tool to change the .py to .so(Linux and Mac) or .pdy(Win).
- You can use it to hide the source code of py.
- Py2Sec can also speed up the running time of the code, up to 30 times than before.
- py2sec can transfer a single file, more of this, it can certainly transfer the whole project at one time!.
- The .so(or .pyd) file generated by the .py file can be called by the main func as "from module import * ".
- py2sec can detect the .py file and transfer to .so(or .pyd) file, also you can determin which file or directory you don't want to change.
- py2sec doesn't affect the origin code, it generate a new file or directory.
- py2sec work well with python2 and python3, use -p(--py) to change the python version you want to encrypt.
- Provide the multithread option to accelerate the speed of py encryption.
How to config it
Please copy the directory or files to the root path of the py2sec.
pip install requirements.txt
How to use py2sec
Usage
python py2sec.py [options] ...
Options
-v, --version Show the version of the py2sec
-h, --help Show the help info
-p, --python Python version, default is based on the version of python you bind with command "python"
Example: -p 3 (means you tends to encrypt python3)
-d, --directory Directory of your project (if use -d, you encrypt the whole directory)
-f, --file File to be transfered (if use -f, you only encrypt one file)
-m, --maintain List the file or the directory you don't want to transfer
Note: The directories should be suffix by path separate char ('\\' in Windows or '/'),
and must be the relative path to -d's value
Example: -m setup.py,mod/__init__.py,exclude_dir/
-x, --nthread number of parallel thread to build jobs
-q --quiet Quiet Mode, Default: False
-r --release Release Mode, clear all the tmp files, only output the result, Default: False
Example
python py2sec.py -f test.py
python py2sec.py -f example/test1.py -r
python py2sec.py -d example/ -m test1.py,bbb/
# some OS use command "python3" to run python3, like Ubuntu, you can use -p to solve it
python3 py2sec.py -p 3 -d example/
Project Structure
- build/ temp files, .o, .so files
- tmp_build/ temp files, .c files
- result/ the final result dir, the results store here
- result/log.txt the log file
- py2sec.py main run file
- py2sec_build.py.template to generate setup.py file
- requirements.txt env to run py2sec
LICENSE
The Project follow the MIT LICENSE.
Demo
The whole project before:

After py2sec:
