PHPackages                             raeen/phpy - 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. raeen/phpy

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

raeen/phpy
==========

Use python in php very easy

5.0.0(5y ago)261986MITPHPPHP &gt;=7.4

Since Jan 16Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Raeen123/phpy)[ Packagist](https://packagist.org/packages/raeen/phpy)[ RSS](/packages/raeen-phpy/feed)WikiDiscussions main Synced 5d ago

READMEChangelog (7)DependenciesVersions (8)Used By (0)

[![icon](favicon.ico)](favicon.ico)

**phpy is library for php**

You can use python in php with it

[![Latest Stable Version](https://camo.githubusercontent.com/51310b7dd49f20ed90178cef949532d9454c98aac5152cd8484fae411af66731/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f76)](//packagist.org/packages/raeen/phpy) [![Total Downloads](https://camo.githubusercontent.com/90e939609e77cde3e9c5c4ab5d1cff92fb6226c0456dd8870e0b036a75a5c863/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f646f776e6c6f616473)](//packagist.org/packages/raeen/phpy) [![Latest Unstable Version](https://camo.githubusercontent.com/79a78b84e86cc673ddba455b87a6cc0dbc3e6bb4a597db8f146f10143529c5ba/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f762f756e737461626c65)](//packagist.org/packages/raeen/phpy) [![License](https://camo.githubusercontent.com/96efdcbbcd7e2db3669787785bc95783a670239850069f18ea76317979819a82/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f6c6963656e7365)](//packagist.org/packages/raeen/phpy)[![Monthly Downloads](https://camo.githubusercontent.com/ed57787e69d3bc9c47141ab69d1192e1c2ba07bf7ca17cc78d161bea20b27f28/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f642f6d6f6e74686c79)](//packagist.org/packages/raeen/phpy) [![Daily Downloads](https://camo.githubusercontent.com/56d20e94f888f330e1ccce4c0b84e679cfd5249244114e3a81b824b7f5dcade8/68747470733a2f2f706f7365722e707567782e6f72672f726165656e2f706870792f642f6461696c79)](//packagist.org/packages/raeen/phpy)

---

Features
--------

[](#features)

- Show all output from python file
- Show last line output from python
- Send data to python file
- Get data from python file
- show image in php from python
- path Genrate
- write python line code
- mange python line code
- write python part
- require python part

---

**Install**

```
git clone https://github.com/Raeen123/phpy
```

```
composer require raeen/phpy
```

---

**Prerequisites**

This is mine config:

```
php = 8.0.1 (Your php version must be at least 7.4 )
python = 3.9.1
numpy = 1.19.3
python-opencv =  4.4.0.46

```

---

**Python**

You must if you don't add python in your path environment , add yor python path in `core/Python.php` in `const python_path `

We use these libraries for create phpy.py:

```
import sys
import json
import base64
import numpy as np
import cv2
```

Import phpy.py file in Python/include/library/php.py

---

**Get Data from php**

Get datas to python file For Get data you must

```
phpy.get_data( Number Of Send data )
```

For return data you must use print function

---

**Push data from python**

```
phpy.push_data(data)
```

It's just

```
json.dumps(data)
```

---

**Push image from python**

It function for pushing data from python to php

Example for reading image

```
cv2.imread()
```

```
videoCaptureObject = cv2.VideoCapture(0)
ret, frame = videoCaptureObject.read()
```

Pushing image

```
phpy.push_image(img,type)
```

---

**Send data from php**

Create and Send data from php to python

You can send infinite data

```
require_once "../vendor/autoload.php";

use app\core\App;

$app = new App();
$python = $app->python;

$data1 = [
    'name' => 'raeen',
    'library' => 'phpy'
];
$data2 = "test";
$output = $python->set("../Python/test2.py")->send($data1, $data2)->gen();
```

live output example:

```
$site = "google.com";
$python->set('../Python/test6.py')->send($data)->live()->gen();
```

---

**Show result**

```
$output = $python->set(path)->send(datas..)->gen()
```

---

**Show Img**

You can use this function to genrate what's return from phpy.push\_img()

```
$app->img($output,$type,$show,$style)
```

**$type must be same type in php.push\_img()**

If $show is true , show image in img tag

Also you can set style for this

Example

```
$app->img($output,$type,true,
[
    'border' => '1px solid red'
])
```

---

**Path**

For example , I have image file in this diractory but python file in Python/\*\*.py and I want to send path to it . for this in must to send this path ../my-img Or use this functiuon for send path file or directory

```
$app->path(__Dir__,path)
```

---

**Ini**

If you have loop in php file it's very good to add this function in top of file

```
$app->ini()
```

---

**Snippet**

**One Line**

If you want to run a python line , you should use this function

```
$Snippet->set($code,function(){
    // controller
})->gen();
```

For control varable , you should it's name in `|&name|`

For fill varable you should `return array` , it must be in order

You must use `"` in python code and use `;` in the end of each line

```
$Snippet = $app->snippet;
$Snippet->set("print(f'hello world {|&data|*7*|&test|}'); print('--Hello')",
function ($data,$test) {
    $data = 2;
    $test = 9;
    $data2 = $data*5;
    return [$data2 , $test];
})->gen();
```

**Lines**

**start**Before start writing codes you should use this

```
$Snippet->start(name);
```

For write your codes , you should use this

```
$Snippet->line(code)
.
.
.
```

For end of lines

```
$Snippet->end(name,save_last)
```

*name in start function must be same this name*

For get output anywhere you should use this

```
$Snippet->select(name)->gen()
```

**Example , index.php :**

```
$Snippet->start("test");
$Snippet->line("a = 'Hello world'");
$Snippet->line("print(a)");
$Snippet->end("test");
$Snippet->select("test")->gen();
```

```
Output : Hello world

```

**You can use this code in another file**

```
$Snippet->select("test")->gen();
```

```
Output : Hello world

```

---

**Live Output**Any where (Snippet and Python class) you can use this so easy

just before use `gen()` use `live()` then use ```gen(/\* you can write function here to control output \*/)

```
$python->set("../Python/test6.py")->send($site)->live()->gen(
    function ($res) {
        return "$res";
    }
);
```

you can also set time without each reading ouput (defult is 1)

```
$python->set("../Python/test6.py")->send($site)->live()->ini(3)->gen(
    function ($res) {
        return "$res";
    }
);
```

```
$Snippet->set(
    "import subprocess as sub; sub.call('ping |&site|') ",function($site){ $site = "google.com"; return [$site];}
)->live()->ini(3)->gen();
```

```
$Snippet->select('snippet-test8')->live()->gen(function($res){ return "$res";});
```

**License**

MIT License

Copyright (c) 2021 Raeen Ahani Azari

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

---

**Example**

There are examples in [phpy-examples](https://github.com/Raeen123/phpy-examples)

---

**BY RAEEN AHANI AZARI**

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~1 days

Total

7

Last Release

1936d ago

Major Versions

1.0.0 → 2.0.02021-01-20

2.0.5 → 5.0.02021-01-26

### Community

Maintainers

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

---

Top Contributors

[![Raeen123](https://avatars.githubusercontent.com/u/66183740?v=4)](https://github.com/Raeen123 "Raeen123 (38 commits)")

---

Tags

phpphp-libraryphp-pythonphp-shellphp7php74php8pythonpython-and-phppython-in-phppython-phppython3shelluse-python-in-php

### Embed Badge

![Health badge](/badges/raeen-phpy/health.svg)

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

###  Alternatives

[hgtan/symfony-pre-commit

A Symfony pre-commit hook

1633.6k](/packages/hgtan-symfony-pre-commit)

PHPackages © 2026

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