Call your Python scripts from Php
You can install the package via composer:
composer require nikaia/php-python-bridge
The bridge work by executing a python script that accept piped json arbitary data, and returns json response.
check tests/_fixtures/ok.script.py for a working example.
use Nikaia\PythonBridge\Bridge;
try {
$response = Bridge::create()
->setPython('/usr/local/bin/python') // the path to the node (You can omit if in system path)
->setScript('/path/to/your/script.py') // the path to your script
->pipe(['foo' => 'bar']) // the data to pipe to the script
->run();
}
catch (BridgeException $e) {
echo $e->getMessage();
}
var_dump($response->json()); // ['foo' => 'bar']
var_dump($response->output()); // the raw output of the script {"foo":"bar"}
Please see CHANGELOG for more information on what has changed recently.
This package use semver releases. Releases are managed using standard-version node package, and requires adhering to conventionalcommit commit styles.
- Implement a feature or a fix etc.
- Use commit message like
fix: Fix an issue
orfeat: Implement a feature ...
- Or rewrite the commit message while squashing/closing the PR!!
- Update your local project, checkout
main
branch - Run :
composer release
to generate changelog, and to tag to new release. - Check everything is okay.
- Push the tag using
git push --follow-tags origin main
This repository is using Semantic Pull Request bot to enforce conventional commit message and PR titles
The MIT License (MIT). Please see License File for more information.