https://github.com/omaralalwi/laravel-py
interact with python in Laravel applications .
https://github.com/omaralalwi/laravel-py
deepseek-r1 laravel laravel-python laravelapi laravelintegration laravelpy laravelpython php-py phppy python-in-php python-laravel python-with-laravel
Last synced: about 1 month ago
JSON representation
interact with python in Laravel applications .
- Host: GitHub
- URL: https://github.com/omaralalwi/laravel-py
- Owner: omaralalwi
- License: mit
- Created: 2025-02-07T19:37:16.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-03-02T13:39:14.000Z (7 months ago)
- Last Synced: 2025-04-02T16:02:56.181Z (6 months ago)
- Topics: deepseek-r1, laravel, laravel-python, laravelapi, laravelintegration, laravelpy, laravelpython, php-py, phppy, python-in-php, python-laravel, python-with-laravel
- Language: PHP
- Homepage:
- Size: 24.4 KB
- Stars: 43
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Laravel Py - Laravel Python ๐๐
Laravel wrapper for **[php-py package](https://github.com/omaralalwi/php-py)** package, to Seamless enabling secure and efficient execution of Python scripts within Laravel applications without spread multiple applications and or setup API.
## ๐ Table of Contents
- [๐ง Requirements](#requirements)
- [๐ Installation](#installation-)
- [๐ Quick Start](#-quick-start)
- [โจ Features](#-features)
- [๐ Changelog](#-changelog)
- [๐งช Testing](#-testing)
- [๐ Security](#-security)
- [๐ค Contributors](#-contributors)
- [๐ License](#-license)---
## Requirements
- PHP 8.1+ .
- [python3](https://www.python.org/) must be installed in server .## Installation ๐ ๏ธ
You can install the package via Composer:
```bash
composer require omaralalwi/laravel-py
```## Publishing Configuration File
```bash
php artisan vendor:publish --tag=laravel-py
```---
## ๐ Quick Start
1. ๐ Create a folder for scripts, e.g., `phpPyScripts` in your project root directory.
2. ๐ 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).
3. ๐ง make script file executable, `chmod +x script_file_path` .### โก Easy Usage
```php
loadScript($script)
->withArguments($arguments)
->run();
print_r($result); // 60.0
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
}
}
```### ๐ฅ Advanced Usage
```php
'phpPyScripts',
'python_executable' => '/usr/bin/python3',
'max_timeout' => 120,
]);$result = $laravelPy
->setConfig($config)
->loadScript($script)
->withArguments($numbers)
->withEnvironment(['FIRST_ENV_VAR' => 10, 'SECOND_ENV_VAR' => 'second var value'])
->timeout(60)
->asJson()
->run();print_r(json_encode($result));
} catch (\Exception $e) {
print_r("Error: " . $e->getMessage());
}
}
}
```---
## โจ Features
### ๐ Secure Execution
- **Path Validation** โ Ensures scripts are within allowed directories.
- **Argument & Environment Validation** ๐ Restricts unauthorized input.
- **Timeout Control** โณ Prevents long-running scripts.
- **black list** for these vars `PATH,PYTHONPATH,LD_LIBRARY_PATH,LD_PRELOAD,PYTHONHOME`, can not passed .
- **Uses `proc_open` as an alternative to `shell_exec`**.### ๐ง Flexible Configuration
- Centralized settings via `ConfigManager`.
- Customizable execution parameters.### ๐ค Output Handling
- Supports JSON parsing.
- Captures and reports script errors.### ๐จ Error Management
- Detailed exception handling for debugging.
- Standardized error reporting.### ๐ Extensibility
- Modular execution through `CommandExecutor`.
- Customizable for advanced use cases.---
### Important Critical Note:โ Never pass user-controlled input directly script, just pass scripts that you will need as a administrator (Just from Your side) .
---
## ๐ Changelog
See detailed release notes in [CHANGELOG.md](CHANGELOG.md) ๐
---
## ๐งช Testing
```bash
./vendor/bin/pest
```---
## ๐ Security
**Report Vulnerabilities**: Contact [omaralwi2010@gmail.com](mailto:omaralwi2010@gmail.com) ๐ฉ
---
## ๐ค Contributors
A huge thank you to these amazing people who have contributed to this project! ๐๐
![]()
Omar AlAlwi
๐ Creator
**Want to contribute?** Check out the [contributing guidelines](./CONTRIBUTING.md) and submit a pull request! ๐
---
## ๐ License
This package is open-source software licensed under the [MIT License](LICENSE.md). ๐