自动Cython,使用Cython批量编译.py文件为.pyd文件!
Project description
AutoCython
自动将 Python 源码编译为 Cython 二进制扩展(
.so/.pyd),支持七重 AST 混淆、并发编译、跨平台运行。
概述
AutoCython 是一个 Python 源码保护工具,通过 Cython 编译 + AST 混淆双重手段,将 .py 文件转换为不可逆的二进制扩展模块。适用于商业项目源码保护、SDK 分发、知识产权保护等场景。
特性
- 一键编译 — 单文件 (
-f) 或整目录 (-p) 批量编译为.so/.pyd - 七重 AST 混淆 — docstring 移除、注解清除、局部变量重命名、字符串 XOR 加密、常量折叠、控制流平坦化、虚假分支注入
- 并发编译 — 基于
ThreadPoolExecutor的多线程并行编译,可配置并发数 - 实时进度面板 — 基于 Rich 的实时任务状态表格、进度条、耗时统计
- 跨平台 — 支持 Linux、macOS、Windows,自动适配
.so/.pyd扩展名 - 可复现构建 — 通过
--seed参数固定混淆随机种子 - 智能排除 — 自动跳过
__init__.py、虚拟环境、构建目录;支持# AutoCython No Compile标记豁免 - 中英双语 — CLI 帮助信息和进度面板自动适配系统语言
安装
pip install AutoCython-zhang
依赖
| 包 | 用途 |
|---|---|
cython |
Python → C 编译核心 |
setuptools |
构建扩展模块 |
rich |
终端实时进度面板 |
使用方法
编译单文件
AutoCython -f demo.py
编译整个目录
AutoCython -p ./my_project
常用选项
AutoCython -p ./src -c 4 # 4 线程并发编译
AutoCython -f main.py -d # 编译后删除源文件
AutoCython -p ./src --seed 42 # 固定混淆种子(可复现)
AutoCython -v # 查看版本
AutoCython -h # 查看帮助
排除文件
在文件头两行内添加注释即可跳过编译:
# AutoCython No Compile
作为库调用
from AutoCython.compile import compile_to_binary
# 编译单文件
output = compile_to_binary("demo.py", del_source=False, obfuscate=True, obfuscate_seed=42)
print(f"生成: {output}")
API 概览
核心函数
| 函数 | 模块 | 描述 |
|---|---|---|
compile() |
AutoCython.AutoCython |
主入口:解析参数并调度编译任务 |
compile_to_binary() |
AutoCython.compile |
将单个 .py 文件编译为二进制扩展 |
obfuscate_source() |
AutoCython.obfuscate |
对源码执行七重 AST 混淆变换 |
run_tasks() |
AutoCython.run_tasks |
并发任务执行引擎(含实时进度面板) |
find_python_files() |
AutoCython.tools |
递归扫描目录下的可编译 .py 文件 |
parse_arguments() |
AutoCython.tools |
CLI 参数解析(中英双语) |
get_platform_extension() |
AutoCython.compile |
返回当前平台的二进制扩展名 |
get_system_language() |
AutoCython.tools |
检测系统语言(zh/en) |
目录结构
AutoCython/
├── AutoCython/
│ ├── __init__.py # 包入口,导出 compile() 和 main()
│ ├── _version.py # 单一版本号来源
│ ├── AutoCython.py # 主编译调度逻辑
│ ├── compile.py # Cython 编译核心(临时目录隔离)
│ ├── obfuscate.py # 七重 AST 混淆引擎
│ ├── run_tasks.py # 并发任务执行 + Rich 实时面板
│ └── tools.py # CLI 参数解析、文件扫描、国际化
├── tests/
│ ├── test_autocython.py # 主入口集成测试
│ ├── test_compile.py # 编译功能单元测试
│ ├── test_obfuscate.py # 混淆引擎单元测试
│ ├── test_obfuscate_advanced.py # 混淆高级场景测试
│ ├── test_obfuscate_anti.py # 混淆反模式/边界测试
│ ├── test_compile_anti.py # 编译反模式测试
│ ├── test_run_tasks.py # 任务执行器测试
│ ├── test_tools.py # 工具函数测试
│ └── kd_dist/ # 知识蒸馏测试集(编译矩阵 + 行为等价)
├── pyproject.toml # 项目配置与构建定义
├── requirements.txt # 依赖清单
├── LICENSE # MIT 许可证
└── DESIGN.md # 设计文档
相关文档
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
autocython_zhang-2.3.2.tar.gz
(17.9 kB
view details)
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 autocython_zhang-2.3.2.tar.gz.
File metadata
- Download URL: autocython_zhang-2.3.2.tar.gz
- Upload date:
- Size: 17.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd4e1f16d9ffd7800034cae9b053631f498c97e6266243d71a9c294caad8e8cd
|
|
| MD5 |
0308dd781a49f51b673a4742908bb3ed
|
|
| BLAKE2b-256 |
28484f0ba85e2791c049fd732d7a7532b8ecaca804bc5cf63b392ffe460fad6c
|
File details
Details for the file autocython_zhang-2.3.2-py3-none-any.whl.
File metadata
- Download URL: autocython_zhang-2.3.2-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcce15f32e888d787d5ef3ac1ba24716eba0b484159a4ccc0992becb54d3bb7d
|
|
| MD5 |
8b69dd58ed15db31bcab10866af1ec88
|
|
| BLAKE2b-256 |
2dd8cd86e4cc38fc6e488e3467336183c2f3fadee624992d2e34daec001ada65
|