Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
P

phpy

> 编程语言
Open source

Connecting the Python and PHP ecosystems together

649 stars0 likes0 views
WebsiteGitHub

About

Connecting the Python and PHP ecosystems together

简体中文

phpy

A library for inter-calling Python and PHP. You can use Python functions and libraries in PHP, or use PHP packages in Python.

  • See documents: docs/en/README.md
  • Supports Linux/Windows/macOS
  • Not support Python threading or async-io features
  • Require PHP 8.1 or later version

py2php

py2php is online utility that will auto-translate python code into PHP code.

Calling Python from PHP

Compile and install phpy.so as an extension, and append extension=phpy.so to php.ini.

PHP Example:

$os = PyCore::import("os");
echo $os->uname();

Transformers

$transformers = PyCore::import('transformers');
$AutoTokenizer = $transformers->AutoTokenizer;
$AutoModelForSequenceClassification = $transformers->AutoModelForSequenceClassification;

$os = PyCore::import('os');
$os->environ['https_proxy'] = getenv('https_proxy');

$tokenizer = $AutoTokenizer->from_pretrained("lxyuan/distilbert-base-multilingual-cased-sentiments-student");
$model = $AutoModelForSequenceClassification->from_pretrained("lxyuan/distilbert-base-multilingual-cased-sentiments-student");

Calling PHP from Python

Simply import it as a C++ Mudule.

Python Example:

import phpy
content = phpy.call('file_get_contents', 'test.txt')

o = phpy.Object('redis')
assert o.call('connect', '127.0.0.1', 6379)
rdata = phpy.call('uniqid')
assert o.call('set', 'key', rdata)
assert o.call('get', 'key') == rdata

Implementation

It creates ZendVM and CPython VM in the process at the same time, and directly uses C functions to call each other in the process stack space.

The overhead is only the conversion of zval PyObject structures, so the performance is very high.

In the benchmark test, we created a PyDict and executed PHP code and Python code to read and write 10 million times respectively.

The performance of phpy writing PyDict with PHP code is 14% higher than the native Python, and the read performance is 25% higher.

More details: docs/en/benchmark.md

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHP

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言