承接 syncfly/python-in-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

syncfly/python-in-php

最新稳定版本:0.8.1

Composer 安装命令:

composer require syncfly/python-in-php

包简介

"Python-In-PHP" allows you to use any Python packages directly in PHP, as if they were native PHP classes. This PHP-Python bridge comes with built-in package manager, which is integrated directly into Composer

README 文档

README

⏳ The project is currently under active development. It is still in the alpha stage, but it is already working.
⭐️ Star the repository to support the project and follow us

Python-in-PHP

The Python-in-PHP library allows you to easily use any Python packages as if they were native PHP packages 🐘

🔥 Fully use artificial intelligence frameworks for AI models inference or training directly in PHP!
You can run AI models with libraries like transformers, torch, vllm, numpy, etc. in your PHP project with PHP syntax.

✅ Environment with Python is installed automatically with Composer.

✅ Any Python packages are installed via Composer with a built-in package manager.

✅ Automatic PHPDoc generation for code completion in IDEs for any Python packages.

Python-in-PHP

Installation

composer require syncfly/python-in-php

You need to answer "yes" when prompted to activate the plugin.

Documentation

You can find the documentation here: (coming soon)

Package manager

The Python-in-PHP Package Manager is a built-in package manager based on uv that allows you to install and manage Python packages.

Intsall a package

composer pip install <package-name>

Uninstall a package

composer pip uninstall <package-name>

Upgrade a package

composer pip install --upgrade <package-name>

Examples

Look at an example of using transformers and torch in PHP for running an AI model:

<?php

use py\transformers;
use py\torch;

$model_name = 'google/gemma-3-4b-it';

$tokenizer = transformers\AutoTokenizer::from_pretrained($model_name);

$model = transformers\AutoModelForCausalLM::from_pretrained(
    $model_name,
    torch_dtype: torch::$bfloat16,
    device_map: "auto"
);

$messages = [
    ['role' => 'user', 'content' => 'Why PHP is great?']
];

$input_ids = $tokenizer->apply_chat_template(
    $messages,
    return_tensors: 'pt',
    add_generation_prompt: true
);

$outputs = $model->generate(
    $input_ids,
    max_new_tokens: 2048
);

$result = $tokenizer->decode($outputs[0], skip_special_tokens: true);

Or simplier with transformers pipeline:

<?php

use py\transformers;

$pipe = transformers\pipeline(
    'text-generation',
    model: 'google/gemma-3-4b-it',
    torch_dtype: torch::$bfloat16,
    device_map: 'auto'
);

$messages = [
    ['role' => 'user', 'content' => 'Why PHP is great?']
];

$output = $pipe($messages, max_new_tokens: 2048);
$generated = $output[0]['generated_text'];
$result = end($generated)['content'];

License

This project is distributed under a source-available license.

Allowed:

  • Using the package in your projects, including commercial ones ✅
  • Making changes and submitting pull requests to this repository

Prohibited:

  • Creating public forks or distributing the project under your own name
  • Uploading the code (modified or original) anywhere else

✅ All contributions are accepted through pull requests to the official repository

Attribution:

  • Attribution notice is required for software with publicly available source code

See LICENSE.md for full details.

统计信息

  • 总下载量: 44
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固