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

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

swoole/phpy
===========

Connecting the Python and PHP ecosystems together

1.0.11(1y ago)6508.6k↓55%53[4 issues](https://github.com/swoole/phpy/issues)[1 PRs](https://github.com/swoole/phpy/pulls)1Apache-2.0PHPPHP &gt;=8.1CI passing

Since Dec 12Pushed 4mo ago16 watchersCompare

[ Source](https://github.com/swoole/phpy)[ Packagist](https://packagist.org/packages/swoole/phpy)[ RSS](/packages/swoole-phpy/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (5)Dependencies (3)Versions (11)Used By (1)

[简体中文](README-CN.md)

phpy
====

[](#phpy)

[![PHP Tests](https://github.com/swoole/phpy/actions/workflows/phpunit.yml/badge.svg)](https://github.com/swoole/phpy/actions/workflows/phpunit.yml)[![Python Tests](https://github.com/swoole/phpy/actions/workflows/pytest.yml/badge.svg)](https://github.com/swoole/phpy/actions/workflows/pytest.yml)[![Codecov](https://camo.githubusercontent.com/307c2bf0fdc15801ff361bf673d341bae27025388d3080dd7c8e27b030829bed/68747470733a2f2f636f6465636f762e696f2f67682f73776f6f6c652f706870792f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/swoole/phpy)

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

[![phpy ecosystems](docs/images/ecosystems.svg)](docs/images/ecosystems.svg)

- See documents: [docs/en/README.md](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)

[py2php](https://swoole.com/py2php/) is online utility that will auto-translate python code into PHP code.

Calling Python from PHP
-----------------------

[](#calling-python-from-php)

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

### PHP Example:

[](#php-example)

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

### Transformers

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

[](#calling-php-from-python)

Simply import it as a C++ Mudule.

### Python Example:

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

[](#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](docs/en/benchmark.md)

###  Health Score

50

—

FairBetter than 95% of packages

Maintenance58

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community28

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 90.5% 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 ~49 days

Total

10

Last Release

532d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/e1dea9261ba377a13a16e7e0f3883e73bda4094551ddea280e852f23a5d248c0?d=identicon)[Tianfeng.Han](/maintainers/Tianfeng.Han)

---

Top Contributors

[![matyhtf](https://avatars.githubusercontent.com/u/2017766?v=4)](https://github.com/matyhtf "matyhtf (248 commits)")[![he426100](https://avatars.githubusercontent.com/u/9689137?v=4)](https://github.com/he426100 "he426100 (10 commits)")[![chaz6chez](https://avatars.githubusercontent.com/u/22535862?v=4)](https://github.com/chaz6chez "chaz6chez (4 commits)")[![remicollet](https://avatars.githubusercontent.com/u/270445?v=4)](https://github.com/remicollet "remicollet (3 commits)")[![Heelie](https://avatars.githubusercontent.com/u/27876556?v=4)](https://github.com/Heelie "Heelie (2 commits)")[![Tinywan](https://avatars.githubusercontent.com/u/14959876?v=4)](https://github.com/Tinywan "Tinywan (2 commits)")[![Yurunsoft](https://avatars.githubusercontent.com/u/20104656?v=4)](https://github.com/Yurunsoft "Yurunsoft (1 commits)")[![macintoshplus](https://avatars.githubusercontent.com/u/814683?v=4)](https://github.com/macintoshplus "macintoshplus (1 commits)")[![netyum](https://avatars.githubusercontent.com/u/195082?v=4)](https://github.com/netyum "netyum (1 commits)")[![SQSora](https://avatars.githubusercontent.com/u/87071734?v=4)](https://github.com/SQSora "SQSora (1 commits)")[![baicaiit](https://avatars.githubusercontent.com/u/42630572?v=4)](https://github.com/baicaiit "baicaiit (1 commits)")

---

Tags

phpaipython

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

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

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

###  Alternatives

[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

103574.3k69](/packages/friendsoftypo3-content-blocks)[phel-lang/phel-lang

Phel is a functional programming language that compiles to PHP

5196.5k22](/packages/phel-lang-phel-lang)[dagger/dagger

Dagger PHP SDK

271.4k](/packages/dagger-dagger)

PHPackages © 2026

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