{"id":25284741,"url":"https://github.com/omaralalwi/php-py","last_synced_at":"2025-06-15T11:39:29.727Z","repository":{"id":276372473,"uuid":"929089795","full_name":"omaralalwi/php-py","owner":"omaralalwi","description":"Interact with python in PHP applications","archived":false,"fork":false,"pushed_at":"2025-02-08T14:24:14.000Z","size":46,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-05T16:21:23.292Z","etag":null,"topics":["deepseek-r1","php","php-ai","php-python-scripts","pyp-excute-python","python","python-in-php","python-lambda"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/omaralalwi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","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":"2025-02-07T19:38:21.000Z","updated_at":"2025-04-25T00:58:41.000Z","dependencies_parsed_at":"2025-02-07T20:36:18.580Z","dependency_job_id":"9d7c8767-969f-4f43-ba38-1efb3a4c0cb2","html_url":"https://github.com/omaralalwi/php-py","commit_stats":null,"previous_names":["omaralalwi/php-py"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaralalwi%2Fphp-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaralalwi%2Fphp-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaralalwi%2Fphp-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaralalwi%2Fphp-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/omaralalwi","download_url":"https://codeload.github.com/omaralalwi/php-py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/omaralalwi%2Fphp-py/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":257259012,"owners_count":22515966,"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":["deepseek-r1","php","php-ai","php-python-scripts","pyp-excute-python","python","python-in-php","python-lambda"],"created_at":"2025-02-12T20:52:24.882Z","updated_at":"2025-06-15T11:39:29.697Z","avatar_url":"https://github.com/omaralalwi.png","language":"PHP","readme":"# PhpPy - PHP Python 🚀🐍\nSeamlessly enabling secure and efficient execution of Python scripts within PHP applications without spread multiple applications and or setup  API.\n\n\n### 🛠 [Laravel py package](https://github.com/omaralalwi/laravel-py)\n\n---\n\n## 📌 Table of Contents\n\n- [📖 Overview](#-overview)\n- [🔧 Requirements](#requirements)\n- [🚀 Installation](#installation-)\n- [🚀 Quick Start](#-quick-start)\n- [✨ Features](#-features)\n- [🛠 Framework Integration](#-framework-integration)\n- [📋 Changelog](#-changelog)\n- [🧪 Testing](#-testing)\n- [🔒 Security](#-security)\n- [🤝 Contributors](#-contributors)\n- [📄 License](#-license)\n\n---\n\n## 📖 Overview\n\nThe `PhpPy` package provides seamless integration between PHP and Python without API, enabling secure and efficient execution of Python scripts within PHP applications. It ensures structured script execution while managing configurations, arguments, environment variables, and error handling.\n\n---\n\n## Requirements\n\n- PHP 8.1+\n- [python3](https://www.python.org/) must be installed in server .\n\n---\n\n## Installation 🛠️\n\nYou can install the package via Composer:\n\n```bash\ncomposer require omaralalwi/php-py\n```\n\n---\n\n## 🚀 Quick Start\n\n1. 📂 Create a folder for scripts, e.g., `phpPyScripts` in your project root directory.\n2. 📝 Create a Python script file (`.py` extension) and write Python code. [See this script examples](https://github.com/omaralalwi/php-py/tree/master/example-scripts).\n3. 🔧 make script file executable, `chmod +x script_file_path` .\n\n### ⚡ Easy Usage\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Omaralalwi\\PhpPy\\PhpPy;\nuse Omaralalwi\\PhpPy\\Managers\\ConfigManager;\n\n$configManager = new ConfigManager([\n       'scripts_directory' =\u003e 'phpPyScripts',\n       'python_executable' =\u003e '/usr/bin/python3',\n       'max_timeout' =\u003e 120,\n]);\n\ntry {\n   $result = PhpPy::build()\n       -\u003esetConfig($configManager)\n       -\u003eloadScript('sum_calculator.py')\n       -\u003ewithArguments([10, 20, 30])\n       -\u003erun();\n    \n    print_r($result); // 60.0\n} catch (Exception $e) {\n    echo \"Error: \" . $e-\u003egetMessage();\n}\n```\n\n### 🔥 Advanced Usage\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Omaralalwi\\PhpPy\\PhpPy;\nuse Omaralalwi\\PhpPy\\Managers\\ConfigManager;\n\n$configManager = new ConfigManager([\n       'scripts_directory' =\u003e 'phpPyScripts',\n       'python_executable' =\u003e '/usr/bin/python3',\n       'max_timeout' =\u003e 120,\n]);\n\ntry {\n\n    $result = PhpPy::build()\n        -\u003esetConfig($configManager)\n        -\u003eloadScript('advanced_example.py')\n        -\u003ewithArguments([10, 20, 30])\n        -\u003ewithEnvironment(['FIRST_ENV_VAR' =\u003e 'some value', 'SECOND_ENV_VAR' =\u003e 'some value'])\n        -\u003etimeout(30)\n        -\u003easJson()\n        -\u003erun();\n\n    print_r(json_decode($result));\n} catch (Exception $e) {\n    echo \"Error: \" . $e-\u003egetMessage();\n}\n```\n\n### 🌍 Real-World Example\n\nExample: Running **DeepSeek AI** on your server while handling API requests using PHP.\n\n```php\n\u003c?php\nrequire_once 'vendor/autoload.php';\n\nuse Omaralalwi\\PhpPy\\PhpPy;\nuse Omaralalwi\\PhpPy\\Managers\\ConfigManager;\n\n$configManager = new ConfigManager([\n       'scripts_directory' =\u003e 'deepSeekScripts',\n       'python_executable' =\u003e '/usr/bin/python3',\n       'max_timeout' =\u003e 120,\n]);\n\nheader('Content-Type: application/json');\n$valid_tokens = ['USER1' =\u003e 'abcd1234', 'USER2' =\u003e 'efgh5678'];\n$token = $_POST['token'] ?? '';\nif (!isset($valid_tokens[$token])) {\n    echo json_encode(['error' =\u003e 'Invalid token']);\n    exit;\n}\n$prompt = $_POST['prompt'] ?? '';\nif (!empty($prompt)) {\n    $clean_prompt = escapeshellarg($prompt);\n    $response = PhpPy::build()\n       -\u003esetConfig($configManager)\n       -\u003eloadScript('model_worker.py')\n       -\u003ewithArguments($clean_prompt)\n       -\u003etimeout(30)\n       -\u003easJson()\n       -\u003erun();\n    echo json_encode(['response' =\u003e trim($response)]);\n} else {\n    echo json_encode(['error' =\u003e 'No prompt provided']);\n}\n```\n\n\n## ✨ Features\n\n### 🔐 Secure Execution\n- **Path Validation** ✅ Ensures scripts are within allowed directories.\n- **Argument \u0026 Environment Validation** 🔍 Restricts unauthorized input.\n- **Timeout Control** ⏳ Prevents long-running scripts.\n- **black list** for these vars `PATH,PYTHONPATH,LD_LIBRARY_PATH,LD_PRELOAD,PYTHONHOME`, can not passed . \n- **Uses `proc_open` as an alternative to `shell_exec`**.\n\n### 🔧 Flexible Configuration\n- Centralized settings via `ConfigManager`.\n- Customizable execution parameters.\n\n### 📤 Output Handling\n- Supports JSON parsing.\n- Captures and reports script errors.\n\n### 🚨 Error Management\n- Detailed exception handling for debugging.\n- Standardized error reporting.\n\n### 🔌 Extensibility\n- Modular execution through `CommandExecutor`.\n- Customizable for advanced use cases.\n\n---\n\n### Important Critical Note: \n❌ Never pass user-controlled input directly script, just pass scripts that you will need as a administrator (Just from Your side) .\n\n---\n\n## 📋 Changelog\n\nSee detailed release notes in [CHANGELOG.md](CHANGELOG.md) 📜\n\n---\n\n## 🧪 Testing\n\n```bash\n./vendor/bin/pest\n```\n\n---\n\n## 🔒 Security\n\n**Report Vulnerabilities**: Contact [omaralwi2010@gmail.com](mailto:omaralwi2010@gmail.com) 📩\n\n---\n\n## 🤝 Contributors\n\nA huge thank you to these amazing people who have contributed to this project! 🎉💖\n\n\u003ctable\u003e\n  \u003ctr\u003e\n    \u003ctd align=\"center\"\u003e\n      \u003ca href=\"https://github.com/omaralalwi\"\u003e\n        \u003cimg src=\"https://avatars.githubusercontent.com/u/25439498?v=4\" width=\"60px;\" style=\"border-radius:50%;\" alt=\"Omar AlAlwi\"/\u003e\n        \u003cbr /\u003e\n        \u003cb\u003eOmar AlAlwi\u003c/b\u003e\n      \u003c/a\u003e\n      \u003cbr /\u003e\n      🏆 Creator\n    \u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n**Want to contribute?** Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! 🚀\n\n---\n\n## 📄 License\n\nThis package is open-source software licensed under the [MIT License](LICENSE.md). 📜\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaralalwi%2Fphp-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fomaralalwi%2Fphp-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fomaralalwi%2Fphp-py/lists"}