CodeSafe Package Documentation

Package documentation for CodeSafe. An open-source Python library for code encryption, decryption, and safe evaluation using Python's built-in AST module, with complete control over execution.

Changelog

Installation

You can install CodeSafe using PyPi, please make sure that you are using Python 3.6 or later before installing CodeSafe:

pip install codesafe
circle-exclamation
circle-info

CodeSafe is intended to quickly encrypt/decrypt code files, and run them (only for Python script files / other formats that Python understands) while in their encrypted form, but not as a means for powerful encryption, just for code obfuscation. We have also included a safe_eval function, that can safely evaluate expressions within a safe and controlled environment.


Example Usage

Safe Eval

from codesafe import safe_eval

if __name__ == '__main__':
    # Run a normal, safe expression
    expression = "1 + 1"
    disallowed_expression = "os.getcwd()"

    result1 = safe_eval(expression, timeout=10, immediate_termination=True)
    result2 = safe_eval(disallowed_expression, timeout=10, immediate_termination=True)
circle-info

Attribute inspection is disabled when using safe_eval. You can read more about how to use safe_eval from here.

Encrypt & Run Code

Last updated

Was this helpful?