python-obfuscator 1.0.0

Python Obfuscator Web API interface can help you obfuscate and protect Python .py source code against analysis, reverse engineering and technology theft. Python Obfuscator provides advanced Python source code parsing based on AST trees, multiple advanced obfuscation, virtualization and protection strategies are available.
Documentation
/******************************************************************************
 * Python Obfuscator WebApi interface usage example.
 *
 * In this example we will obfuscate sample source with default options.
 *
 * Version        : v1.0.0
 * Language       : Rust
 * Author         : Bartosz Wójcik
 * Web page       : https://www.pelock.com
 *
 *****************************************************************************/

use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    //
    // include Python Obfuscator class
    //

    //
    // when developing from a repository clone without installing the package use:
    //
    // use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
    // (path dependency in Cargo.toml pointing to this crate)

    //
    // create Python Obfuscator class instance (we are using our activation key)
    //
    let my_python_obfuscator =
        PythonObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));

    //
    // source code in Python format
    //
    let script_source_code = r#"label = 'SecretKey'
port = 443

def get_sum(a, b):
    return a + b

print(label, port)
r = get_sum(11, 31)
print(r)"#;

    //
    // by default all obfuscation options are enabled, so we can just simply call:
    //
    let result = my_python_obfuscator
        .obfuscate_script_source(script_source_code, true)
        .await;

    //
    // it's also possible to pass a Python script file path instead of a string e.g.
    //
    // let result = my_python_obfuscator
    //     .obfuscate_script_file(std::path::Path::new("/path/to/project/script.py"), true)
    //     .await;

    //
    // result object holds the obfuscation results as well as other information
    //
    // result.error         - error code
    // result.output        - obfuscated code
    // result.demo          - demo mode (empty/invalid key); strategy flags ignored; always integers_to_arrays, mba_binops, encrypt_strings (no virt; 1000 char limit)
    // result.license_expiration - license end date (Y-m-d), empty if none
    // result.usages_total  - total obfuscations for this activation code
    //
    match result {
        Some(PythonObfuscatorResponse::Object(obj)) => {
            //
            // display obfuscated code
            //
            if obj.error == PythonObfuscator::ERROR_SUCCESS {
                println!("{}", obj.output.unwrap_or_default());
            } else {
                return Err(
                    format!("An error occurred, error code: {}", obj.error).into(),
                );
            }
        }
        Some(PythonObfuscatorResponse::Json(_)) => {}
        None => {
            return Err("Something unexpected happen while trying to obfuscate the code.".into());
        }
    }

    Ok(())
}