GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com โ€” GitHub - rakshitbharat/pythoninphp: PythonInPHP is a modern, lightweight Laravel integration wrapper that allows you to execute Python scripts securely and seamlessly from within your PHP applications.

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
.agents/skills/pythoninphp-developer
.agents/skills/pythoninphp-developer
 
 
.github
.github
 
 
.idea
.idea
 
 
config
config
 
 
docs
docs
 
 
src
src
 
 
tests
tests
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.scrutinizer.yml
.scrutinizer.yml
 
 
.styleci.yml
.styleci.yml
 
 
.travis.yml
.travis.yml
 
 
CHANGELOG.md
CHANGELOG.md
 
 
CONTRIBUTING.md
CONTRIBUTING.md
 
 
Dockerfile
Dockerfile
 
 
FUNDING.yml
FUNDING.yml
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
composer.json
composer.json
 
 
docker-compose.yml
docker-compose.yml
 
 
phpunit.xml.dist
phpunit.xml.dist
 
 

Repository files navigation

PythonInPHP Banner

Latest Stable Version Total Downloads Build Status License PHP Version Laravel Version


๐ŸŒŸ What is PythonInPHP?

PythonInPHP is a modern, lightweight Laravel integration wrapper that allows you to execute Python scripts securely and seamlessly from within your PHP applications.

Rather than deploying complex microservices, using HTTP APIs, or running raw execution commands prone to security risks, PythonInPHP provides:

  • ๐Ÿ”’ Secure Execution: Utilizing Symfony's robust Process component instead of exec() or popen() to ensure proper argument escaping and prevent command injection.
  • โšก Laravel Service Integration: Native Laravel auto-discovery Service Provider, Facades, and dynamic configuration.
  • โฑ๏ธ Timeout Safety: Prevent hanging processes via configurable timeouts.
  • ๐Ÿ› ๏ธ Testing Sandbox: A complete Docker test-runner out of the box for platform-independent package testing.

โœจ Features

  • Unified API: Execute scripts using the clean Python Facade: Python::run().
  • Argument Escaping: Arguments are safely escaped and passed as an array.
  • Custom Exceptions: Script runtime failures and timeouts throw a structured PythonExecutionException.
  • Configurable Runtime: Easily define your Python binary path and default process timeouts in config/pythoninphp.php.
  • PHP 8.2+ & Laravel 10/11: Fully built for modern PHP & Laravel stacks.

๐Ÿ“ฆ Installation

Install the package via Composer:

composer require rakshitbharat/pythoninphp

Laravel's package auto-discovery will automatically register the PythonServiceProvider and the Python facade.


โš™๏ธ Configuration

Publish the configuration file:

php artisan vendor:publish --tag="pythoninphp-config"

This will create a config/pythoninphp.php file:

return [
    // Define the path to your Python executable
    'executable' => env('PYTHON_EXECUTABLE', 'python3'),

    // Default execution timeout in seconds (null for no timeout)
    'timeout' => env('PYTHON_TIMEOUT', 60),
];

๐Ÿš€ Usage

Simple Run

Run a Python script relative to your Laravel application's root directory (base_path()):

use Rakshitbharat\Pythoninphp\Facades\Python;

$output = Python::run('app/Scripts/hello.py');
echo $output; // Prints standard output

Passing Arguments

Arguments passed as an array are securely escaped:

$output = Python::run('app/Scripts/process.py', [
    '--file=data.csv',
    '--verbose'
]);

Error Handling

Script failures (non-zero exit codes) or execution timeouts throw a PythonExecutionException:

use Rakshitbharat\Pythoninphp\Exceptions\PythonExecutionException;

try {
    $output = Python::run('app/Scripts/unreliable.py');
} catch (PythonExecutionException $e) {
    Log::error("Python script failed: " . $e->getMessage());
}

๐Ÿงช Local Testing

You can run the PHPUnit test suite locally within a clean, containerized PHP 8.2 environment using Docker:

# 1. Build and install dependencies
docker compose run --rm test-runner composer install

# 2. Run the tests
docker compose run --rm test-runner vendor/bin/phpunit

๐Ÿ“„ License

The MIT License (MIT). Please see LICENSE.md for more information.

About

PythonInPHP is a modern, lightweight Laravel integration wrapper that allows you to execute Python scripts securely and seamlessly from within your PHP applications.

Topics

laravephppythonpython-scriptrunnerserver-side

Resources

Readme
MIT license

Contributing

Contributing
Activity

Stars

24 stars

Watchers

1 watching

Forks

5 forks
Report repository

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

You are visitor 01402775 โ€” GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800ร—600. No cookies required.