Skip to main content

Image

License: MIT PyPI Ruff CodeFactor Downloads CI Coverage

A lightweight, open-source tool for Python code obfuscation. CodeEnigma helps protect your logic from reverse engineering and unauthorized access, making it secure to distribute your Python applications.

🔒 Why CodeEnigma?

After searching extensively for a free and open-source Python obfuscation tool, I realized that most available options were either paid, closed-source, or opaque in how they worked. I wasn't comfortable letting a black-box tool obfuscate my production code without knowing exactly what it was doing — especially when it had access to sensitive logic.

So I built CodeEnigma — a transparent, self-contained solution that gives you full control over the obfuscation process, with no hidden logic and no external servers involved.

This project is inspired by PyArmor but with a different approach.

High Level Architecture

Image

The working principle of CodeEnigma is simple:

  1. The user provides the path to the Python module to obfuscate.
  2. CodeEnigma reads the module's source code.
  3. An AES-256 key is generated using a secure random number generator and set in private.py
  4. Obfuscation runs file by file running the following steps:
    • 4.1. Compile using compile(code, str(file_path), "exec")
    • 4.2. Compress the byte code using zlib.compress(compiled_code)
    • 4.3. Encode the compressed byte code using base64.b64encode(compressed_code)
    • 4.4. Encrypt the encoded byte code using AESGCM(SECRET_KEY).encrypt(NONCE, obfuscated, associated_data=None) refer for more details:
  5. CodeEnigma creates a new module with the obfuscated code.
  6. A codeenigma_runtime.pyx file is created with the deobfuscation logic to decrypt and execute the obfuscated code.
  7. The runtime is compiled to a Python extension module using Cython. Also generates a codeenigma_runtime.whl file for distribution.
  8. End of process, the obfuscated module is ready to be distributed as wheel files.

Features

  • 🔒 Strong encryption using AES-256
  • 🔄 Simple API for obfuscating any python module
  • 🔑 Secure and dynamic key generation
  • 🛠️ Command-line interface for easy integration into build processes
  • 📦 Lightweight and dependency-minimal

Installation

Using Poetry:

poetry add codeenigma

Using pip:

pip install codeenigma

Usage

CodeEnigma comes with a user-friendly command-line interface powered by Typer. The CLI provides helpful prompts and rich output.

Basic Usage

To obfuscate a Python module:

codeenigma obfuscate /path/to/your/module

Command Line Options

  • --expiration, -e: Set an expiration date for the obfuscated code (YYYY-MM-DD)
  • --output, -o, --dist: Specify output directory (default: 'dist')
  • --verbose, -v: Show detailed output

Examples

Obfuscate with an expiration date:

The following example will obfuscate the module and set the expiration date to December 31, 2025, at 23:59:59+0530 (IST).

codeenigma obfuscate /path/to/your/module -e "2025-12-31 23:59:59+0530"

Specify custom output directory:

codeenigma obfuscate /path/to/your/module -o custom_output

Version Information

To check the installed version:

codeenigma version

Contributing

Contributions are welcome! This is a complete free and open-source project. If you have any suggestions or find any bugs, please open an issue.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with ❤️ using Python
  • Uses cryptography for secure encryption
  • Uses Cython for compiling the runtime
  • Logo Credits, Claude 🫡

Metadata

Release files for codeenigma 1.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codeenigma 1.2.2
File Size Uploaded Provenance Actions
codeenigma-1.2.2.tar.gz 15.5 kB Without provenance Details for codeenigma-1.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for codeenigma 1.2.2
File Interpreter ABI Platform Actions
codeenigma-1.2.2-py3-none-any.whl Python 3 none any Details for codeenigma-1.2.2-py3-none-any.whl

Total release size: 37.8 kB

Release files / codeenigma-1.2.2.tar.gz

Download URL codeenigma-1.2.2.tar.gz
Size 15.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a342af8691de7c57d58891107dfb0a6174a494b6ca5073f1dec4a2d7de6f45a6
BLAKE2b-256 checksum
How to use checksums
3550fddb7652fb2285aafd9409af33b8dd4d255807e8470eaffbc3cf9bf6b635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.6 Darwin/25.6.0

Release files / codeenigma-1.2.2-py3-none-any.whl

Download URL codeenigma-1.2.2-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2589b4cfa2366e26cd6f283d2ae1620044253d8bd6dd9efbf6b8440f1a782565
BLAKE2b-256 checksum
How to use checksums
2f8be78d35c6834c3a9eb6821bc50378d11ef2918c4d808fa771e001850a6c82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.2 CPython/3.12.6 Darwin/25.6.0

Security for codeenigma 1.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page