Skip to main content

Compile Python source files into .pyd or .so extension modules for distribution and source protection.

Project description

py2pydso

Compile Python source files into .pyd / .so native extensions for distribution and source protection.

PyPI version Python License


✨ Features

  • 🔒 源码保护 — 将 .py 编译为 .pyd/.so 原生扩展,不暴露源码
  • 📦 三种编译模式 — 单文件 / 模块目录 / 完整 wheel 包
  • 🗂️ 智能过滤 — 自动保留 __init__.py 等元文件,支持自定义排除
  • 📝 类型提示 — 自动生成 .pyi 存根文件,保留 IDE 补全体验
  • 🌍 跨平台Windows (.pyd) / Linux / macOS (.so) 全支持

安装

pip install py2pydso

安装完成后,可通过以下命令验证:

python -m py2pydso --help

依赖

py2pydso 会自动安装以下 Python 依赖:

依赖 用途
Cython .py 转译为C代码并编译为原生扩展
setuptools 驱动编译流程
mypy 通过 stubgen 生成 .pyi 类型提示文件
tomli 解析 pyproject.toml(Python < 3.11 时自动安装)

C 编译器

编译原生扩展需要 C 编译器,请根据平台安装:

  • Windows: Visual Studio Build Tools(勾选 "C++ build tools")
  • macOS: xcode-select --install
  • Linux: sudo apt install build-essential gcc

使用方式

1. 编译单个文件

# 输出到源文件同目录
python -m py2pydso file -i demo.py

输出 demo.pyd(或 demo.so),位于 demo.py 同目录。

# 指定输出目录
python -m py2pydso file -i demo.py -o output

输出 output/demo.pyd

python -m py2pydso file -i utils/demo.py

输出 utils/demo.pyd(或 utils/demo.so)。

2. 编译整个模块目录

python -m py2pydso module -i utils -o output

输入:

utils/
  __init__.py
  __main__.py
  tools.py
  config.py

输出:

output/
  utils/
    __init__.py      ← 原样保留(__开头)
    __main__.py      ← 原样保留(__开头)
    config.py        ← 原样保留(--exclude-files 指定)
    tools.pyd        ← 编译产物
  • __开头的 .py 文件(如 __init__.py__main__.py)原样保留,不参与编译
  • 支持 --exclude-files 指定额外排除的文件(可多个):
    python -m py2pydso module -i utils -o output --exclude-files config.py constants.py
    
  • 支持子目录递归编译

3. 构建完整 wheel 包

python -m py2pydso package --package-name loki_service

构建保护版本的 wheel 包(.pyi 类型提示 + .pyd/.so 原生扩展),不暴露源码。

# 跳过 stubgen,异常时保留临时目录用于调试
python -m py2pydso package --package-name loki_service --skip-stubgen --keep-tmp

# 指定输出目录
python -m py2pydso package --package-name loki_service --output-dir /path/to/wheelhouse

输出:<package_name>-x.x.x-cpYY-cpYY-<platform>.whl

公共参数

参数 说明
--keep-tmp 保留临时编译目录,用于调试

命令行帮助

python -m py2pydso --help
python -m py2pydso file --help
python -m py2pydso module --help
python -m py2pydso package --help

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

py2pydso-1.2.0-cp314-cp314-win_amd64.whl (116.7 kB view details)

Uploaded CPython 3.14Windows x86-64

py2pydso-1.2.0-cp314-cp314-manylinux_2_17_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp313-cp313-win_amd64.whl (115.0 kB view details)

Uploaded CPython 3.13Windows x86-64

py2pydso-1.2.0-cp313-cp313-manylinux_2_17_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp312-cp312-win_amd64.whl (115.0 kB view details)

Uploaded CPython 3.12Windows x86-64

py2pydso-1.2.0-cp312-cp312-manylinux_2_17_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp311-cp311-win_amd64.whl (119.9 kB view details)

Uploaded CPython 3.11Windows x86-64

py2pydso-1.2.0-cp311-cp311-manylinux_2_17_x86_64.whl (1.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp310-cp310-win_amd64.whl (119.8 kB view details)

Uploaded CPython 3.10Windows x86-64

py2pydso-1.2.0-cp310-cp310-manylinux_2_17_x86_64.whl (986.6 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp39-cp39-win_amd64.whl (130.4 kB view details)

Uploaded CPython 3.9Windows x86-64

py2pydso-1.2.0-cp39-cp39-manylinux_2_17_x86_64.whl (983.3 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

py2pydso-1.2.0-cp38-cp38-win_amd64.whl (133.3 kB view details)

Uploaded CPython 3.8Windows x86-64

py2pydso-1.2.0-cp38-cp38-manylinux_2_17_x86_64.whl (975.9 kB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file py2pydso-1.2.0-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 116.7 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 1e37b9dad312b2552ad61226ab1467b974cfb18be88d5c68b851414756647124
MD5 cc8199f78945e52e18e3487ffcca2dfd
BLAKE2b-256 0ad5e40a6605e96399942417148e8c6a1d96d52f04612800c822080a945f0721

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp314-cp314-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp314-cp314-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp314-cp314-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 c7fa5c25f37838da51ed7acfc27072cda9a383eaa8dd8e4b58c2397b1f72edd0
MD5 3c912a5e39958314fed3b27b7fbeb11f
BLAKE2b-256 eb22fe615bd1d5d040be9d079e9f19abf5ebb49d44dcf54724737ac0456acc70

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp314-cp314-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 115.0 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ff5ec34d09bfd3f9771824792a1887070d33cd5ff324312068a4a0fdfbe94649
MD5 9f08abd620d8a8e33fb997fe5d0207ad
BLAKE2b-256 55da1066f1a5e39a4e2df53c1aea4273d27f5889d1658dcf2ba9076f027200da

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp313-cp313-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp313-cp313-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp313-cp313-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 89179ac03a9dc506aa1e09ad0f53b5aed74fea02983b47485ac3320492236c1e
MD5 85cc973c7644d8ea6ae280244a90bf38
BLAKE2b-256 9b534b6e5a6e76ec290d9d0344693ef48c39729528d7cfbfd9407d5c69673289

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp313-cp313-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 115.0 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b7f87d5ee7527a76e21d76595e0f5ca4ea4de49864ffd5f178bcdab9c7a3eadc
MD5 8428cc9449f8299de969dc6731918f22
BLAKE2b-256 8391cad23571904fb0da84cc660bc9b1204839917e9a94c82fd5ea0c9959cae8

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp312-cp312-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp312-cp312-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp312-cp312-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 af0d2606ebb37e818d5e9d699a692d41718a9c04c297e0963c86d232a237170f
MD5 cf1af2696973ae15eabcc1207fb85f34
BLAKE2b-256 b6fe781a1103bce49957aacba47264e1bfb0c6f75bde0e216019f9ab9bac1092

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp312-cp312-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 119.9 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f936be00195278169dd45a7031d7222843a68c8a9decbaad30c20bda7539f4d3
MD5 289c96467669739ec0fa04a23fb58d1b
BLAKE2b-256 c888c9d70ec027cc52ca21b5cad7433aea37dedde675384ece12b71ec329b18b

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp311-cp311-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp311-cp311-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp311-cp311-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 08c62c4de2c3f92bdf634c6302f40d7fee92cd56dcf197bd926d189635883e93
MD5 beaa4a3a2ea6b64955464231013ca5e0
BLAKE2b-256 66f4675902eef3aa277f000eafe81dc0e8a401205acbc63c9aabbc0c5b8c5984

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp311-cp311-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 119.8 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 d49a8ff80a9268131f1106af3c9d96de37f1a9f2db7abbd0872e7af2c82b010a
MD5 763a556a85e489e374e4b01669224ad6
BLAKE2b-256 dcbc8ed2db68017a824748fa5fddd206934d86fcef2029ee0394c1a37cc3ec45

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp310-cp310-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp310-cp310-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp310-cp310-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 93629838c9cc8977a9eaf84370e156a942a3d4329ff600b418c07d37169e494b
MD5 33209a218ca906b84fe5841096b34ccd
BLAKE2b-256 2300b1b3bb27e0d5a6e75bc78ea791c3b3b95d43d64ba689da5e2b321082c060

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp310-cp310-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 130.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 2b67351bc7e92ea6a883095a60b19738c0aab4f5804d356e27e22c9f508478b1
MD5 fb94f3a5e36bbdf2f96cc76da5606f5d
BLAKE2b-256 c3e8b06460d367662b6cca1829cba6a75c1b17280dd3646067bc4eb39b87a5fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp39-cp39-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp39-cp39-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp39-cp39-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 bd0afbd1f32a0f786dbce26f6c4678e0cfdfafac6ca2f323381ba21476134559
MD5 4d521f15ff8052c415e0cc9997589c89
BLAKE2b-256 3d2b536f50a7b2ed2b6c7a43b8b8b708503ee91c928199695dff951be70f7378

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp39-cp39-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: py2pydso-1.2.0-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 133.3 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for py2pydso-1.2.0-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 015aef2cbfb4d359f375389df87fb9f5f3b0c56a6797b256f9e6e09055576a29
MD5 13de6aafee5e9f96728f9af0076d3dc4
BLAKE2b-256 a17f420bf9934ee37cbfa85ef010ffb2831e499d63681c5a06570e70b28b3501

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp38-cp38-win_amd64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file py2pydso-1.2.0-cp38-cp38-manylinux_2_17_x86_64.whl.

File metadata

File hashes

Hashes for py2pydso-1.2.0-cp38-cp38-manylinux_2_17_x86_64.whl
Algorithm Hash digest
SHA256 7400125248e8bc4485c2ca0f4e9236c96d8d55de61afda9a4e57112c6b2a8505
MD5 fc0a083e05c3b3abd330abaa53818fcd
BLAKE2b-256 5ddc7ce5ad99d735023ee31a81bc9b1b5edd04d1b5973bc2e6e18ab03f13ddb3

See more details on using hashes here.

Provenance

The following attestation bundles were made for py2pydso-1.2.0-cp38-cp38-manylinux_2_17_x86_64.whl:

Publisher: wheels.yml on zhenzi0322/py2pydso

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page