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"],
    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"],
    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"],
    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.1.tar.gz (6.3 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.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pybuildhelper-0.0.1.tar.gz
  • Upload date:
  • Size: 6.3 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.1.tar.gz
Algorithm Hash digest
SHA256 df4c28f79dd773bedfcb65bb85a4c64410d910b1d076b8cb7350c92f454041f4
MD5 bd2d55eb42e58c2dc249d1dc344d47f9
BLAKE2b-256 960cd8dc37314c3bada6d5536d237c054c935fd469d2d2056c6ad8d47aa72f98

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pybuildhelper-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66eb95efac5227b5ee2239a56f260f1e8e677b0d548599ca8c3014be1e4a80cf
MD5 7c163d30bf71b653d1d58dc0f45fe4bf
BLAKE2b-256 78cfc800ae55dc86e83d0d786164c92048adf7be72c4767fa6e743d598917c0f

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