PHPackages                             blyxxyz/python-server - 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. blyxxyz/python-server

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

blyxxyz/python-server
=====================

A way to call PHP code from Python

8112Python

Since Apr 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/blyxxyz/Python-PHP-Bridge)[ Packagist](https://packagist.org/packages/blyxxyz/python-server)[ RSS](/packages/blyxxyz-python-server/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

This is a Python module for running PHP programs. It lets you import PHP functions, classes, objects, constants and variables to work just like regular Python versions.

Examples
========

[](#examples)

You can call functions:

```
>>> from phpbridge import php
>>> php.array_reverse(['foo', 'bar', 'baz'])
Array.list(['baz', 'bar', 'foo'])
>>> php.echo("foo\n")
foo
>>> php.getimagesize("http://php.net/images/logos/new-php-logo.png")
Array([('0', 200), ('1', 106), ('2', 3), ('3', 'width="200" height="106"'), ('bits', 8), ('mime', 'image/png')])
```

You can create and use objects:

```
>>> php.DateTime

>>> date = php.DateTime()
>>> print(date)

>>> date.getOffset()
7200
>>> php.ArrayAccess

>>> issubclass(php.ArrayObject, php.ArrayAccess)
True
```

You can use keyword arguments, even though PHP doesn't support them:

```
>>> date.setDate(year=1900, day=20, month=10)

```

You can loop over iterators and traversables:

```
>>> for path, file in php.RecursiveIteratorIterator(php.RecursiveDirectoryIterator('.git/logs')):
...     print("{}: {}".format(path, file.getSize()))
...
.git/logs/.: 16
.git/logs/..: 144
.git/logs/HEAD: 2461
[...]
```

You can get help:

```
>>> help(php.echo)
Help on function echo:

echo(arg1, *rest)
    Output one or more strings.

    @param mixed $arg1
    @param mixed ...$rest

    @return void
```

You can import namespaces as modules:

```
>>> from phpbridge.php.blyxxyz.PythonServer import NonFunctionProxy
>>> help(NonFunctionProxy)
Help on class blyxxyz\PythonServer\NonFunctionProxy in module phpbridge.php.blyxxyz.PythonServer:

class blyxxyz\PythonServer\NonFunctionProxy(phpbridge.objects.PHPObject)
 |  Provide function-like language constructs as static methods.
 |
 |  `isset` and `empty` are not provided because it's impossible for a real
 |  function to check whether its argument is defined.
 |
 |  Method resolution order:
 |      blyxxyz\PythonServer\NonFunctionProxy
 |      phpbridge.objects.PHPObject
 |      builtins.object
 |
 |  Class methods defined here:
 |
 |  array(val) -> dict from phpbridge.objects.PHPClass
 |      Cast a value to an array.
 |
 |      @param mixed $val
 |
 |      @return array
[...]
```

You can index, and get lengths:

```
>>> arr = php.ArrayObject(['foo', 'bar', 'baz'])
>>> arr[10] = 'foobar'
>>> len(arr)
4
```

You can work with PHP's exceptions:

```
>>> try:
...     php.get_resource_type(3)
... except php.TypeError as e:
...     print(e.getMessage())
...
get_resource_type() expects parameter 1 to be resource, integer given
```

Features
========

[](#features)

- Using PHP functions
    - Keyword arguments are supported and translated based on the signature
    - Docblocks are also converted, so `help` is informative
- Using PHP classes like Python classes
    - Methods and constants are defined right away based on the PHP class
    - Docblocks are treated like docstrings, so `help` works and is informative
    - The original inheritance structure is copied
    - Default properties become Python properties with documentation
    - Other properties are accessed on the fly as a fallback for attribute access
- Creating and using objects
- Importing namespaces as modules
- Getting and setting constants
- Getting and setting global variables
- Translating exceptions so they can be treated as both Python exceptions and PHP objects
- Tab completion in the interpreter
- Python-like reprs for PHP objects, with information like var\_dump in a more compact form

Caveats
=======

[](#caveats)

- On Windows, stdin and stderr are used to communicate, so PHP can't read input and if it writes to stderr the connection is lost
- You can only pass basic Python objects into PHP
- Namespaces can shadow names in an unintuitive way
- Because PHP only has one kind of array, its arrays are translated to a special kind of ordered dictionary

Name conflicts
==============

[](#name-conflicts)

Some PHP packages use the same name both for a class and a namespace. As an example, take `nikic/PHP-Parser`.

`PhpParser\Node` is a class, but `PhpParser\Node\Param` is also a class. This means `phpbridge.php.PhpParser.Node` becomes ambiguous - it could either refer to the `Node` class, or the namespace of the `Param` class.

In case of such a conflict, the class is preferred over the namespace. To get `Param`, a `from` import has to be used:

```
>>> php.require('vendor/autoload.php')

>>> import phpbridge.php.PhpParser.Node as Node           # Not the namespace!
>>> Node

>>> from phpbridge.php.PhpParser.Node import Param        # The class we want
>>> Param

>>> import phpbridge.php.PhpParser.Node.Param as Param    # Doesn't work
Traceback (most recent call last):
  File "", line 1, in
AttributeError: type object 'PhpParser\Node' has no attribute 'Param'
```

If there are no conflicts, things work as expected:

```
>>> from phpbridge.php.blyxxyz.PythonServer import Commands
>>> Commands

>>> import phpbridge.php.blyxxyz.PythonServer as PythonServer
>>> PythonServer

>>> PythonServer.Commands

```

Installing
==========

[](#installing)

```
pip3 install phpbridge

```

The only dependencies are PHP 7.0+, Python 3.5+, ext-json, ext-reflection and ext-mbstring. Composer can be used to install development tools and set up autoloading, but it's not required.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 98.6% 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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15526524?v=4)[Jan Verbeek](/maintainers/blyxxyz)[@blyxxyz](https://github.com/blyxxyz)

---

Top Contributors

[![blyxxyz](https://avatars.githubusercontent.com/u/15526524?v=4)](https://github.com/blyxxyz "blyxxyz (68 commits)")[![Louzet](https://avatars.githubusercontent.com/u/39524830?v=4)](https://github.com/Louzet "Louzet (1 commits)")

---

Tags

bridgephppython

### Embed Badge

![Health badge](/badges/blyxxyz-python-server/health.svg)

```
[![Health](https://phpackages.com/badges/blyxxyz-python-server/health.svg)](https://phpackages.com/packages/blyxxyz-python-server)
```

PHPackages © 2026

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