PHPackages                             rakshitbharat/pythoninphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. rakshitbharat/pythoninphp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

rakshitbharat/pythoninphp
=========================

Execute Python scripts seamlessly from your Laravel PHP applications.

v2.1.2(1mo ago)2429551MITPHPPHP ^8.2CI passing

Since Feb 25Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/rakshitbharat/pythoninphp)[ Packagist](https://packagist.org/packages/rakshitbharat/pythoninphp)[ Docs](https://github.com/rakshitbharat/pythoninphp)[ RSS](/packages/rakshitbharat-pythoninphp/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (6)Dependencies (4)Versions (11)Used By (1)

 [![PythonInPHP Banner](docs/pythoninphp_banner.png)](docs/pythoninphp_banner.png)

 [![Latest Stable Version](https://camo.githubusercontent.com/9b1e89dcdc70bac7010988cbbad232d42b7eca065541a7597108ad4c8d0a29fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616b736869746268617261742f707974686f6e696e7068702e7376673f7374796c653d666c61742d73717561726526636f6c6f723d384235434636)](https://packagist.org/packages/rakshitbharat/pythoninphp) [![Total Downloads](https://camo.githubusercontent.com/d2e96b7c771fb69fc97fc876ec3dd0e94cb8c182e1943ed69e441047919f97cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616b736869746268617261742f707974686f6e696e7068702e7376673f7374796c653d666c61742d73717561726526636f6c6f723d334238324636)](https://packagist.org/packages/rakshitbharat/pythoninphp) [![Build Status](https://github.com/rakshitbharat/pythoninphp/actions/workflows/tests.yml/badge.svg)](https://github.com/rakshitbharat/pythoninphp/actions/workflows/tests.yml) [![License](https://camo.githubusercontent.com/0caa75f30456c48c8fff39ffa5c5a63b3511530ccf3e54e95948a7699dcceb00/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d4635394530422e7376673f7374796c653d666c61742d737175617265)](LICENSE.md) [![PHP Version](https://camo.githubusercontent.com/845fe01bb8448057f88d8b368f5c1f6c7998550f275bd32f5e7cf70717256580/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e322d3130423938312e7376673f7374796c653d666c61742d737175617265)](https://php.net) [![Laravel Version](https://camo.githubusercontent.com/7d9a5d6f217e81483ee63d7c24f9f28210cb404c041b5805ab049eeae26c691c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d313025323025374325323031312d4646324432302e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)

---

🌟 What is PythonInPHP?
----------------------

[](#-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
----------

[](#-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+ &amp; Laravel 10/11**: Fully built for modern PHP &amp; Laravel stacks.

---

📦 Installation
--------------

[](#-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
----------------

[](#️-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
-------

[](#-usage)

### Simple Run

[](#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

[](#passing-arguments)

Arguments passed as an array are securely escaped:

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

### Error Handling

[](#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
---------------

[](#-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
---------

[](#-license)

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

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance90

Actively maintained with recent releases

Popularity23

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 69.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~289 days

Recently: every ~392 days

Total

9

Last Release

52d ago

Major Versions

1.4 → v2.0.02026-06-27

PHP version history (2 changes)1.0PHP ^7.1

v2.0.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17176729?v=4)[GitHub ](/maintainers/rakshitbharat)[@rakshitbharat](https://github.com/rakshitbharat)

---

Top Contributors

[![rakshitbharat](https://avatars.githubusercontent.com/u/17176729?v=4)](https://github.com/rakshitbharat "rakshitbharat (16 commits)")[![rakshitbharatproject](https://avatars.githubusercontent.com/u/223161659?v=4)](https://github.com/rakshitbharatproject "rakshitbharatproject (7 commits)")

---

Tags

laravephppythonpython-scriptrunnerserver-sidephplaravelprocesspython

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rakshitbharat-pythoninphp/health.svg)

```
[![Health](https://phpackages.com/badges/rakshitbharat-pythoninphp/health.svg)](https://phpackages.com/packages/rakshitbharat-pythoninphp)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k99.8M355](/packages/laravel-horizon)[spatie/laravel-health

Monitor the health of a Laravel application

88212.7M188](/packages/spatie-laravel-health)[illuminate/process

The Illuminate Process package.

44926.6k129](/packages/illuminate-process)[spatie/laravel-export

Create a static site bundle from a Laravel app

679153.2k7](/packages/spatie-laravel-export)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
