Skip to main content

A python build helper library to compile (obfuscate) and pack Python files using Cython and PyInstaller

Project description

Python Build Helper

Overview

A python build helper library to compile (obfuscate) and pack Python files using Cython and PyInstaller.

This Python module, build_helper.py, provides a set of functions to simplify the process of compiling Python code using Cython and packaging it into a single package using PyInstaller. It allows you to manage the compilation and packaging process with ease, including handling data files, excluding specific files or directories, and specifying hidden imports.

Features

  • Cython Compilation (Obfuscation): Compile (Obfuscate) Python files to C extensions using Cython.
  • PyInstaller Packaging: Package the compiled files into a single package using PyInstaller.
  • Data File Management: Include data files and directories in the compilation and packaging process.
  • Exclusion Support: Exclude specific files or directories from compilation and packaging.
  • Hidden Imports: Specify additional modules to be included in the package.

Installation

You can install using pip:

pip install pybulidhelper

or you can install from source:

python setup.py install

Usage

Compiling Python Files

To compile all Python files in a directory using Cython, you can use the compile function:

from build_helper import compile

compile(
    main_file="main.py",
    data_files=["data", "**/*.json"],
    exclude_files=["test"],
    source_dir=".",
    intermediate_dir="build",
    dist_dir="dist"
)

Packaging into a Single Package

To package the compiled files into a single package using PyInstaller, you can use the pack function:

from build_helper import pack

pack(
    main_file="main.py",
    data_files=["data", "**/*.json"],
    exclude_files=["test"],
    hidden_imports=["numpy"],
    executable_name="my_app",
    onefile=True,
    source_dir=".",
    intermediate_dir="build",
    dist_dir="dist"
)

hidden_imports is an optional parameter that allows you to specify additional modules to be included in the package. Maybe you have a requirements.txt file, instead of specifying each module manually, you can use hidden_imports_from_requirements="requirements.txt" to specify the modules in the requirements.txt file.

onefile is set to False by default, but you can set it to True to create a single executable file.

Compiling and Packaging

To perform both compilation and packaging in one step, you can use the compile_and_pack function:

from build_helper import compile_and_pack

compile_and_pack(
    main_file="main.py",
    data_files=["data", "**/*.json"],
    exclude_files=["test"],
    hidden_imports=["numpy"],
    executable_name="my_app",
    onefile=True,
    source_dir=".",
    compile_intermediate_dir="build/compile",
    compile_dist_dir="build/compile_dist",
    pack_intermediate_dir="build/pack",
    pack_dist_dir="dist"
)

License

This project is licensed under the MIT License.

Project details


Download files

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

Source Distribution

pybuildhelper-0.0.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

pybuildhelper-0.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pybuildhelper-0.0.2.tar.gz.

File metadata

  • Download URL: pybuildhelper-0.0.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for pybuildhelper-0.0.2.tar.gz
Algorithm Hash digest
SHA256 21586664ac65c8219597cf91bbe190e938016828b283110c735551b5a3a279a3
MD5 55e9145c162b8265241430fc351a8ec1
BLAKE2b-256 80374a615ab8da8392927ebef1900a26c7fcfaaf48b125f7576e5d14a5eeb443

See more details on using hashes here.

File details

Details for the file pybuildhelper-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: pybuildhelper-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.0

File hashes

Hashes for pybuildhelper-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 985bc147e79ded66872ce608761ef9e678d46108a4a9e6df00c77ea30b047f94
MD5 f5499ad95bc4ec348713fbfc8ee824a9
BLAKE2b-256 16769de7fa807d43b15a349bb38706dd5fb78900dc94102df35a93e90f95bf63

See more details on using hashes here.

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