local-python-code-protector

The Local Python Code Protector Script is a command-line tool designed to provide source code protection and secure code sharing for Python scripts. It allows developers to obfuscate their Python code. This script supports both Python source files (.py) and compiled Python files (.pyc), offering flexible options for code obfuscation and encryption.

https://github.com/alphabetanetcom/local-python-code-protector

Science Score: 67.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 2 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (12.9%) to scientific vocabulary

Keywords

alpha-beta-network code-protection code-sharing encryption intellectual-property license-management obfuscation obfuscation-tool python python-security secure-sharing security security-tools
Last synced: 4 months ago · JSON representation ·

Repository

The Local Python Code Protector Script is a command-line tool designed to provide source code protection and secure code sharing for Python scripts. It allows developers to obfuscate their Python code. This script supports both Python source files (.py) and compiled Python files (.pyc), offering flexible options for code obfuscation and encryption.

Basic Info
  • Host: GitHub
  • Owner: alphabetanetcom
  • License: other
  • Language: Python
  • Default Branch: main
  • Homepage: https://alphabetanet.com/
  • Size: 24.6 MB
Statistics
  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • Open Issues: 0
  • Releases: 2
Topics
alpha-beta-network code-protection code-sharing encryption intellectual-property license-management obfuscation obfuscation-tool python python-security secure-sharing security security-tools
Created about 1 year ago · Last pushed 8 months ago
Metadata Files
Readme License Citation

README.md

Local Python Code Protector Script Documentation

DOI License Python Version Cross-Platform Source Protection Code Security Python Obfuscator License Management Secure Distribution

Version: 1.3\ © 2025 αβ.net (alphabetanet.com) - Alpha Beta Network. All Rights Reserved.


Note: This project is currently in Beta Testing and available for free.

Table of Contents


1. Introduction

The Local Python Code Protector Script is a command-line tool designed to provide source code protection and secure code sharing for Python scripts. It allows developers to obfuscate their Python code, making it more difficult for others to understand or reverse-engineer. This script supports both Python source files (.py) and compiled Python files (.pyc), offering flexible options for code obfuscation and encryption.

Key features of the script include:

  • Code Obfuscation and Encryption: Implements multi-level protection with dynamic encryption and obfuscation techniques.

  • Device-Specific Restrictions: Allows restricting code execution to specific devices based on hardware IDs.

  • Expiration Date Settings: Enables setting an expiration date after which the code will not run.

  • Cross-Platform Compatibility: Works on Windows, macOS, Linux/Unix, and other operating systems where Python 3.6+ is installed.

  • No Internet Connection Required: The protected code runs locally without needing an internet connection.

This tool is ideal for developers who need to protect their Python code when sharing it with clients, colleagues, or deploying it on servers, ensuring Python code security best practices are upheld.

The Local Python Code Protector Script can also be effectively used to further protect licensed source code files created by the Alpha Beta Network cloud platform (more advanced and flexible source code protection solutions such as Python Obfuscator Online and Secure Python Code Manager Script).


2. Installation

Before using the Local Python Code Protector Script, ensure that you have Python 3.6+ installed on your system.

2.1 Installing Required Packages

The script requires the following Python packages:

  • requests

  • psutil

  • cryptography

  • decompyle3

  • xdis

  • astor

You can install them using pip:

```bash

pip install requests psutil cryptography decompyle3 xdis astor ``` Ensure that you are using the correct version of pip associated with your Python 3 installation. If you are using a virtual environment, activate it before installing the packages.


3. Main Functions of the Script

The Local Python Code Protector Script provides the following main functionalities:

3.1 Obfuscating Python Source Files

Obfuscate and protect Python source files (.py) by applying multi-level encryption and obfuscation techniques.

3.2 Obfuscating Compiled Python Files

Protect previously compiled Python files (.pyc) using a unique recompilation technology that enhances their security.


4. Detailed Description of Each Function

4.1 Obfuscating Python Source Files

The script can obfuscate Python source files, making them harder to read and reverse-engineer.

Command Syntax

```bash

python localpythoncodeprotector.py -f FILEPATH [OPTIONS] ``` Description of Parameters

  • -f FILEPATH or --file FILEPATH: (Required) Specifies the path to the Python source file (.py) to protect.

  • -d DEVICES or --device DEVICES: (Optional) A comma-separated list of hardware IDs (HWIDs) to restrict the code execution to specific devices.

  • -e DATE or --expiration DATE: (Optional) Sets an expiration date in YYYY-MM-DD format, after which the code will not run.

  • -m MESSAGE or --message MESSAGE: (Optional) A custom message to display when the protected code is executed.

4.2 Obfuscating Compiled Python Files

The script can obfuscate compiled Python files (.pyc) by converting them back to a safe code representation and re-protecting them.

Command Syntax

```bash

python localpythoncodeprotector.py -f FILEPATH [OPTIONS] ``` Note: The parameters are the same as for source files.


5. Additional Features

5.1 Restricting Code Execution to Specific Devices

You can restrict the execution of the protected code to specific devices by specifying their hardware IDs (HWIDs). Only devices with the listed HWIDs will be able to run the code.

Parameter

  • -d DEVICES or --device DEVICES: A comma-separated list of HWIDs.

Example

```bash

python localpythoncodeprotector.py -f myscript.py -d 123456789012345678,987654321098765432 ```

5.2 Setting an Expiration Date

Set an expiration date for the protected code. After this date, the code will refuse to run.

Parameter

  • -e DATE or --expiration DATE: The expiration date in YYYY-MM-DD format.

Example

```bash

python localpythoncodeprotector.py -f myscript.py -e 2024-01-01 ```

5.3 Adding Custom Messages

Add a custom message that will be displayed when the protected code is executed. This could be a disclaimer or any pertinent information.

Parameter

  • -m MESSAGE or --message MESSAGE: The custom message text.

Example

```bash

python localpythoncodeprotector.py -f myscript.py -m "This is a licensed instance #123456789012345678. Unauthorized use, reproduction, or distribution is prohibited."

```

6. Usage Examples

6.1 Basic Obfuscation of a Source File

Obfuscate a Python source file without any additional restrictions.

Command

```bash

python localpythoncodeprotector.py -f myscript.py ``` Output

  • The protected file will be saved in the Local_Protected directory as a compiled .pyc file.

6.2 Obfuscation with Device Restrictions

Restrict the execution of the protected code to specific devices.

Command

```bash

python localpythoncodeprotector.py -f myscript.py -d 123456789012345678,987654321098765432 ``` Notes

  • Replace the numbers with the actual HWIDs of the devices.

  • Only the devices with the specified HWIDs can execute the protected code.

6.3 Obfuscation with Expiration Date

Set an expiration date for the protected code.

Command

```bash

python localpythoncodeprotector.py -f myscript.py -e 2024-01-01 ``` Notes

  • After January 1, 2024, the code will not run.

6.4 Obfuscation with All Features

Combine device restrictions, expiration date, and a custom message.

Command

```bash

python localpythoncodeprotector.py -f myscript.py -d 123456789012345678 -e 2024-01-01 -m "License valid until 2024-01-01." ``` Notes

  • The code will only run on the device with HWID 123456789012345678 and before January 1, 2024.

  • Upon execution, the message \"License valid until 2024-01-01.\" will be displayed.


7. Recommendations and Best Practices

  • Add Multiple Protection Layers: To enhance security, you can obfuscate the already protected code again using the script.

  • Use Latest Python Versions: If possible, use the latest Python versions for which decompilers are not readily available.

  • Utilize Virtual Environments: Create virtual environments for different Python versions to generate protected versions compatible with various Python installations.

  • Combine with Cloud Protection: For more robust protection, consider using cloud-based solutions like Secure Python Code Manager and Python Obfuscator Online.


Appendix A: Installation of Required Packages

The localpythoncode_protector.py script requires the following Python packages:

  • requests

  • psutil

  • cryptography

  • decompyle3

  • xdis

  • astor

Installing Packages with pip

You can install these packages using the following command:

```bash

pip install requests psutil cryptography decompyle3 xdis astor ``` Ensure that you are using the correct version of pip associated with your Python 3 installation. If you are working within a virtual environment, activate it before installing the packages.


Appendix B: Generating Hardware IDs

To restrict code execution to specific devices, you need to obtain the hardware IDs (HWIDs) of those devices. Use the systemhardwareid_generator.py script to generate the HWID.

Usage:

  1. Run the script on the target device:

```bash

python systemhardwareid_generator.py ``` 2. The script will display the HWID:

```bash

Your Hardware ID (HWID) is: 123456789012345678 ``` 3. Use this HWID with the -d or --device parameter when obfuscating your code.


Appendix C: Real-World Example - Universal Python Module with Multi-Version Compatibility

In this appendix, we present a real-world example of applying the Local Python Code Protector Script to create a secure, cross-platform, and multi-version compatible Python module.

C.1 Overview

The file systemhardwareid_generator.pyz is a universal Python module that encapsulates multiple protected .pyc files, each corresponding to a different Python version. It is optimized for cross-platform and multi-version compatibility, automatically detecting the current Python interpreter version and executing the appropriate protected module.

C.2 Construction of the Universal Module

C.2.1 Protected .pyc Files

Eight protected .pyc files were generated for different Python versions using the Local Python Code Protector Script. The protection process was applied twice to each file to strengthen the security.

Protected files:

  • systemhardwareidgeneratorpython36.pyc (Python 3.6)

  • systemhardwareidgeneratorpython37.pyc (Python 3.7)

  • systemhardwareidgeneratorpython38.pyc (Python 3.8)

  • systemhardwareidgeneratorpython39.pyc (Python 3.9)

  • systemhardwareidgeneratorpython310.pyc (Python 3.10)

  • systemhardwareidgeneratorpython311.pyc (Python 3.11)

  • systemhardwareidgeneratorpython312.pyc (Python 3.12)

  • systemhardwareidgeneratorpython313.pyc (Python 3.13)

C.2.2 Multi-Version PYZ Builder

The integration of these files into a single .pyz archive was achieved using the Multi-Version PYZ Builder, a software solution that leverages Alpha Beta Network technologies.

Key Features:

  • Automatic Python Version Detection: The module determines the current Python interpreter version at runtime.

  • Version-Specific Execution: Executes the protected .pyc file corresponding to the detected Python version.

  • Cross-Platform Compatibility: Runs seamlessly on Windows, macOS, Linux/Unix, and other operating systems.

C.3 Advantages of Using a Universal .pyz File

  • Secure Code Sharing: The source code is deeply protected from analysis and recovery, ensuring high levels of Python code security and code obfuscation.

  • Simplified Distribution: Only one .pyz file needs to be distributed, regardless of the Python version or operating system of the end-user.

  • Enhanced Protection: By using pre-compiled and protected versions of the code, it adds an extra layer of security against decompilation and unauthorized access.

C.4 Using the Universal Module

To generate the Hardware ID (HWID) on any supported platform:

  1. Execute the .pyz file:

```bash

python systemhardwareid_generator.pyz ``` 2. The module will display the HWID:

```bash

Your Hardware ID (HWID) is: 123456789012345678 ``` Notes:

  • Ensures secure code execution without exposing the original source code.

  • Compatible with multiple Python versions, making it an ideal solution for environments with varied Python installations.

C.5 Building Your Own Universal Module

To create a similar universal Python module for your protected scripts:

  1. Protect Your Scripts: Use the Local Python Code Protector Script to obfuscate your .py files for each Python version you wish to support.

  2. Use Multi-Version PYZ Builder: Integrate the protected .pyc files into a single .pyz archive using the Multi-Version PYZ Builder.

  3. Distribute the .pyz File: Share the universal .pyz file with your users, ensuring they can run it on their platform and Python version without additional configurations.

Benefits:

  • Combines the strengths of code obfuscationencryption, and secure code sharing.

  • Facilitates cross-platform and multi-version support, enhancing user experience.

  • Aligns with Python code security best practices by minimizing exposure of sensitive code.

C.6 Conclusion

The use of a universal .pyz file exemplifies advanced techniques in source code protection and secure code sharing. By leveraging the Local Python Code Protector Script and the Multi-Version PYZ Builder, developers can create robust, secure, and versatile Python modules suitable for distribution across diverse environments.


Appendix D: Contact Information

If you experience issues or have questions not covered in this documentation, please contact the Alpha Beta Network Research Team.

  • Website: https://alphabetanet.com | https://αβ.net

  • Official Telegram Channel: https://t.me/alphabetanetcom

Stay connected to receive updates, provide feedback, and get early access to extended functionality.


© 2025 αβ.net (alphabetanet.com) - Alpha Beta Network. All Rights Reserved.

Owner

  • Name: Pavel Izosimov (Alpha Beta Network)
  • Login: alphabetanetcom
  • Kind: user

🚀 Creator of αβ.net - Python Code Sharing Platform 🔒 Focused on Secure Code Transfer 🌐 Open Source Enthusiast 🔬 Research & Development in Code Security

Citation (CITATION.cff)

cff-version: 1.2.0
title: Local Python Code Protector
message: >-
  If you use this software, please cite it using the
  metadata from this file.
type: software
authors:
  - given-names: Pavel
    family-names: Izosimov
    affiliation: Alpha Beta Network
    orcid: 'https://orcid.org/0009-0004-7126-6743'
    website: 'https://alphabetanet.com'
repository-code: >-
  https://github.com/alphabetanetcom/local-python-code-protector
url: 'https://alphabetanet.com/'
repository: >-
  https://gitlab.com/alphabetanetcom/local-python-code-protector
repository-artifact: >-
  https://github.com/alphabetanetcom/local-python-code-protector/releases
abstract: >-
  A command-line tool designed to provide source code protection
  and secure code sharing for Python scripts. It allows developers
  to obfuscate their Python code. This script supports both Python
  source files (.py) and compiled Python files (.pyc), offering
  flexible options for code obfuscation and encryption.
keywords:
  - secure code sharing
  - source code protection
  - python code encryption
  - code obfuscation
  - python security
  - license management
  - code protection
  - secure file transfer
  - python development
  - intellectual property protection
  - software licensing
  - code security
  - python obfuscator
  - secure distribution
version: v1.2.1-beta.1
date-released: '2024-11-14'
license-url: 'https://github.com/alphabetanetcom/local-python-code-protector/blob/main/LICENSE.md'

GitHub Events

Total
  • Release event: 2
  • Watch event: 8
  • Delete event: 1
  • Push event: 29
  • Gollum event: 3
  • Create event: 2
Last Year
  • Release event: 2
  • Watch event: 8
  • Delete event: 1
  • Push event: 29
  • Gollum event: 3
  • Create event: 2

Dependencies

requirements.txt pypi
  • astor *
  • cryptography *
  • decompyle3 *
  • psutil *
  • requests *
  • xdis *