{"id":15442502,"url":"https://github.com/infinitode/codesafe","last_synced_at":"2025-10-03T13:20:14.239Z","repository":{"id":257802583,"uuid":"864016127","full_name":"Infinitode/CodeSafe","owner":"Infinitode","description":"An open-source Python library for code encryption, decryption, and safe evaluation using Python's built-in AST module, complete with allowed functions, variables, built-in imports, timeouts, and blocked access to attributes.","archived":false,"fork":false,"pushed_at":"2025-01-18T13:22:37.000Z","size":34,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-29T12:35:11.169Z","etag":null,"topics":["code-evaluation","code-obfuscation","codesafe","eval","python","safe-eval","safe-evaluation"],"latest_commit_sha":null,"homepage":"https://infinitode.netlify.app","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Infinitode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-27T10:37:10.000Z","updated_at":"2025-02-01T19:02:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"987bf362-347e-49eb-938f-f2c816054826","html_url":"https://github.com/Infinitode/CodeSafe","commit_stats":{"total_commits":1,"total_committers":1,"mean_commits":1.0,"dds":0.0,"last_synced_commit":"139e05252a2d0c8ba52d8ddeb2e7e735d1688e77"},"previous_names":["infinitode/codesafe"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinitode%2FCodeSafe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinitode%2FCodeSafe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinitode%2FCodeSafe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Infinitode%2FCodeSafe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Infinitode","download_url":"https://codeload.github.com/Infinitode/CodeSafe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016668,"owners_count":21198834,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-evaluation","code-obfuscation","codesafe","eval","python","safe-eval","safe-evaluation"],"created_at":"2024-10-01T19:28:11.324Z","updated_at":"2025-10-03T13:20:14.234Z","avatar_url":"https://github.com/Infinitode.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeSafe\n![Python Version](https://img.shields.io/badge/python-3.12-blue.svg)\n[![Code Size](https://img.shields.io/github/languages/code-size/infinitode/codesafe)](https://github.com/infinitode/codesafe)\n![Downloads](https://pepy.tech/badge/codesafe)\n![License Compliance](https://img.shields.io/badge/license-compliance-brightgreen.svg)\n![PyPI Version](https://img.shields.io/pypi/v/codesafe)\n\nAn open-source Python library for code encryption, decryption, and safe evaluation using Python's built-in AST module, complete with allowed functions, variables, built-in imports, timeouts, and blocked access to attributes.\n\n*CodeSafe is an experimental library, and we're still running some tests on it. If you encounter any issues, or have an edge use case, please let us know.*\n\n\u003e [!NOTE]\n\u003e **CodeSafe** is intended to quickly encrypt/decrypt code files, and run them (only for Python script files) while in their encrypted form, but not as a means for powerful encryption, just code obfuscation. We have also included a `safe_eval` function, that can safely evaluate expressions within a safe environment.\n\n### Changelog v0.0.3:\n- Added an `allow_attributes` parameter to `safe_eval` and set `immediate_termination` to be `True` by default for safer function calling.\n\n### Changelog v0.0.2:\n- Fixed function returns.\n- Added error handling to `CodeSafe`, removed some print statements with edits from `@0XC7R`.\n\n### Changelog v0.0.1:\n- Initial release\n\n## Installation\n\nYou can install CodeSafe using pip:\n\n```bash\npip install codesafe\n```\n\n## Supported Python Versions\n\nCodeSafe supports the following Python versions:\n\n- Python 3.6\n- Python 3.7\n- Python 3.8\n- Python 3.9\n- Python 3.10\n- Python 3.11/Later (Preferred)\n\nPlease ensure that you have one of these Python versions installed before using CodeSafe. CodeSafe may not work as expected on lower versions of Python than the supported.\n\n## Features\n\n- **Safe Eval**: Safely allow `eval()` expressions to run, while maintaining complete control over the entire evaluation process.\n- **Code Encryption/Decryption**: Quickly encrypt your code. This is meant for code obfuscation, and not high-level encryption.\n- **Run encrypted code at runtime**: Run your encrypted code files, without needing to expose your code to end-users.\n\n\u003e [!NOTE]\n\u003e Running encrypted files at runtime using `run()` are only available in formats that can be understood by Python.\n\n\u003e [!IMPORTANT]\n\u003e When running `safe_eval`, make sure to wait for the Python file to finish its bootstrapping phase. This can be done by simply waiting for:\n\u003e ```python\n\u003e if __name__ == '__main__':\n\u003e    # Run eval, etc.\n\u003e ```\n\u003e If you're planning on including `safe_eval` in executables:\n\u003e ```python\n\u003e import multiprocessing\n\u003e if __name__ == '__main__':\n\u003e       multiprocessing.freeze_support()\n\u003e       # Call safe_eval afterwards\n\u003e ```\n\u003e You can read more about why this needs to be done here: https://pytorch.org/docs/stable/notes/windows.html#multiprocessing-error-without-if-clause-protection\n\n## Usage\n\n### Safe Eval\n\n```python\nfrom codesafe import safe_eval\n\nif __name__ == '__main__':\n    # Run a normal, safe expression\n    expression = \"1 + 1\"\n    disallowed_expression = \"os.getcwd()\"\n\n    result1 = safe_eval(expression, timeout=10, immediate_termination=True)\n    result2 = safe_eval(disallowed_expression, timeout=10, immediate_termination=True)\n```\n\n\u003e [!NOTE]\n\u003e Attribute inspection is disabled when using `safe_eval`. You can read more about how to use `safe_eval` from [here](https://infinitode-docs.gitbook.io/documentation/package-documentation/codesafe-package-documentation).\n\n### Encrypt \u0026 Run Code\n\n```python\nfrom codesafe import encrypt_to_file, decrypt_to_file, run\n\ncode = \"\"\"\ngreetJohnny = \"Hello Johnny!\"\n\ndef greet_someone(greeting):\n    print(greeting)\n\ngreet_someone(greetJohnny)\n\"\"\"\n\n# Encrypt the code\nencrypted_file_path = \"encrypted_code.encrypt\"\nencrypt_to_file(code, encrypted_file_path)\n\n# Run the encrypted code\nrun(encrypted_file_path) # Hello Johnny!\n\n# Decrypt code to another file\noutput_file = \"decrypted_code.py\"\ndecrypt_to_file(encrypted_file_path, output_file)\n```\n\n## Contributing\n\nContributions are welcome! If you encounter any issues, have suggestions, or want to contribute to CodeSafe, please open an issue or submit a pull request on [GitHub](https://github.com/infinitode/codesafe).\n\n## License\n\nCodeSafe is released under the terms of the **MIT License (Modified)**. Please see the [LICENSE](https://github.com/infinitode/codesafe/blob/main/LICENSE) file for the full text.\n\n**Modified License Clause**\n\nThe modified license clause grants users the permission to make derivative works based on the CodeSafe software. However, it requires any substantial changes to the software to be clearly distinguished from the original work and distributed under a different name.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinitode%2Fcodesafe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfinitode%2Fcodesafe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfinitode%2Fcodesafe/lists"}