Compile Python code to binary for distribution
Project description
py2dist
py2dist is a tool that uses Cython to compile Python source code into binary extension modules (.so/.pyd), primarily for source code protection.
Features
- Compile single
.pyfiles or entire directories into binary files. - Preserve directory structure.
- Support excluding specific files or directories.
- Automatically detect and use
ccacheto accelerate compilation. - Provide both CLI and Python API.
Installation
pip install py2dist
Usage
Command Line Interface (CLI)
Compile a single file:
py2dist -f myscript.py
Compile an entire directory:
py2dist -d myproject -o dist
Arguments:
-f, --file: Specify a single.pyfile to compile.-d, --directory: Specify the directory to compile.-o, --output: Output directory (default isdist).-m, --maintain: Files or directories to exclude (comma-separated).-x, --nthread: Number of compilation threads (default is 1).-q, --quiet: Quiet mode.-r, --release: Release mode (cleans up temporary build files).-c, --ccache: Use ccache (auto-detect by default, or specify path).
Python API
from py2dist import compile_file, compile_dir
# Compile a single file
compile_file("myscript.py", output_dir="dist")
# Compile a directory
compile_dir(
"myproject",
output_dir="dist",
exclude=["tests", "setup.py"],
nthread=4
)
⚠️ Important Note: Python Version Consistency
The compiled binary extension modules (.so/.pyd) are bound to a specific Python version. You must ensure that the Python version used for compilation is exactly the same as the Python version used at runtime (including minor version numbers; for example, 3.10 and 3.11 are incompatible).
If the versions do not match, you may encounter errors like the following when importing the module:
ImportError: ... undefined symbol: _PyThreadState_UncheckedGet
or
ModuleNotFoundError: No module named ...
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 py2dist-0.1.2.tar.gz.
File metadata
- Download URL: py2dist-0.1.2.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f5330e9223e279dfbf2095cb324cd8f7975a2c351174b84c3628658c0298ed78
|
|
| MD5 |
b6a25688c4116ade74440703ead68dc5
|
|
| BLAKE2b-256 |
b92679ceffc07829d868446218afd7da1b8f829a8aff6940d095f1edc3363ae0
|
Provenance
The following attestation bundles were made for py2dist-0.1.2.tar.gz:
Publisher:
publish.yml on xxnuo/py2dist
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2dist-0.1.2.tar.gz -
Subject digest:
f5330e9223e279dfbf2095cb324cd8f7975a2c351174b84c3628658c0298ed78 - Sigstore transparency entry: 782083657
- Sigstore integration time:
-
Permalink:
xxnuo/py2dist@8a12726a34f4650f4e0c8a82d1edea5584b7c173 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/xxnuo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a12726a34f4650f4e0c8a82d1edea5584b7c173 -
Trigger Event:
push
-
Statement type:
File details
Details for the file py2dist-0.1.2-py3-none-any.whl.
File metadata
- Download URL: py2dist-0.1.2-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc1829d0177727d4daabeccbba6792ea0755126ab9a2f64535a91fa2f6ee89bd
|
|
| MD5 |
94fdcb755acb3ffd8b3323a5dd2bf846
|
|
| BLAKE2b-256 |
4a06e101acae0347cd29114f87dc304e328522dae54ca1879a46458f9eaa1543
|
Provenance
The following attestation bundles were made for py2dist-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on xxnuo/py2dist
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
py2dist-0.1.2-py3-none-any.whl -
Subject digest:
cc1829d0177727d4daabeccbba6792ea0755126ab9a2f64535a91fa2f6ee89bd - Sigstore transparency entry: 782083658
- Sigstore integration time:
-
Permalink:
xxnuo/py2dist@8a12726a34f4650f4e0c8a82d1edea5584b7c173 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/xxnuo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8a12726a34f4650f4e0c8a82d1edea5584b7c173 -
Trigger Event:
push
-
Statement type: