static-php-py
"static PHP for Python" — a single PHP binary wrapped behind one Python class.
Run PHP scripts from Python without a system PHP install, binding one binary from a companion, a path, or a URL.
Install
pip install static-php-py # code-only, bring your own binary
pip install "static-php-py[bundled]" # also pulls the companion PHP binary
The [bundled] extra pulls the companion distribution static-php-py-binary (internal, exact-pinned — never install it directly), supplying a pre-built PHP 8.4 binary for the host platform.
Usage
from static_php_py import PHP
php = PHP.bundled() # companion binary (needs [bundled] extra)
php = PHP.local("/usr/bin/php") # explicit path or system PATH
php = PHP.remote("https://example.com/php-8.4.tar.gz") # download + cache
result = php.run("script.php", args=["--verbose"])
if result.success:
print(result.stdout)
else:
print(f"Error (code {result.return_code}): {result.stderr}")
print(php.eval("echo phpversion();").stdout)
print(php.version())
report = php.check_extensions(["tokenizer", "mbstring"])
if not report.satisfied:
print(f"Missing: {report.missing}")
Required version and extensions
Declare the PHP version and extension set your package needs once, as a static_php_py.requirements entry point in your own pyproject.toml:
[project.entry-points."static_php_py.requirements"]
manifest = "your_lib._php_requirements"
# your_lib/_php_requirements.py
version = ">=8.4" # PEP 440 specifier, or None for any
extensions = ["tokenizer", "mbstring"]
Every PHP factory reads this manifest once per process and checks the bound binary against it automatically — no version or extension arguments at any call site. A missing extension raises ExtensionUnsatisfiedError, naming the static-php-build tool that produces a satisfying binary; a violated version constraint raises VersionUnsatisfiedError. The same manifest drives static-php-build when you omit --extensions, so both tools stay in sync from one declaration.
Self-managed binary
A library that needs a fixed extension set ships its own binary as package data and loads it with PHP.local, so its end users install nothing and never compile. Build the binary per OS with static-php-build, place it under the package (your_lib/_bin/php), and resolve it at runtime relative to the package — never the system PATH or a user-supplied path:
from importlib.resources import as_file, files
from static_php_py import PHP
def php() -> PHP:
with as_file(files("your_lib._bin") / "php") as binary:
return PHP.local(binary)
Full CI-to-wheel flow: ../../docs/llms/bundling-pipeline.md.
API
Classes
PHP— wrapper bound to one binary.PHP.bundled() -> PHP— companion binary; raisesBinaryNotFoundErrornaming the[bundled]extra when the companion is absent.PHP.local(path: Path | str) -> PHP— explicit path or system PATH.PHP.remote(url: str, force: bool = False, timeout: float = 300.0) -> PHP— download, extract (.tar.gz/.tgz/.zip), and cache.PHP.cache_dir() -> Path— platform-specific download cache directory.run(script, args=None, timeout=None) -> ExecutionResulteval(code, timeout=None) -> ExecutionResultversion() -> strextensions() -> frozenset[str]— loaded extensions viaphp -m, lowercased.check_extensions(required) -> ExtensionReport— pure inspection; no download or build.path(property)-> Path
ExecutionResult— frozen data holder:return_code,stdout,stderr,success.ExtensionReport— frozen data holder:required,loaded,missing,satisfied.
Exceptions
PHPError— base.BinaryNotFoundError,ExecutionError,DownloadError,InvalidArchiveError,ExtensionUnsatisfiedError,VersionUnsatisfiedError.
Full design: docs/design-api.md. Concepts: docs/concept.md. Doc index: docs/index.md.
For Agents
Agent-consumable documentation index at ../../docs/llms.txt (llmstxt.org format).
Citation
If you use this project in academic work, cite our paper. BibTeX (placeholder until the paper is released):
@misc{static_php_py_placeholder,
title = {{TODO: paper title — not yet released}},
author = {{TODO: authors}},
year = {{TODO}},
note = {Paper not yet released. Citation entry will be updated on publication.}
}
License
GPL-2.0 — see LICENSE. Pre-built binaries originate from static-php-cli.
Metadata
Release files for static-php-py 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| static_php_py-0.1.4.tar.gz | 41.8 kB | Without provenance | Details for static_php_py-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| static_php_py-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for static_php_py-0.1.4-py3-none-any.whl |
Total release size: 70.3 kB
Release files / static_php_py-0.1.4.tar.gz
| Download URL | static_php_py-0.1.4.tar.gz |
|---|---|
| Size | 41.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
953e266c2e361a030cadeacdbb275d07129d6cdd4e1948cf6183c30ae417ab9b
|
|
BLAKE2b-256 checksum How to use checksums |
14ca774b8e66ae3fafe0b3e0459b28a8163813e9c3a577921063c804c7a385ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / static_php_py-0.1.4-py3-none-any.whl
| Download URL | static_php_py-0.1.4-py3-none-any.whl |
|---|---|
| Size | 28.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a538178450784660fae70a8ae365188cca54382bd95d742038ecf178933ac2c
|
|
BLAKE2b-256 checksum How to use checksums |
8cf16063b3b98fa208083f39207ab8c6d0dcf6796aa465693797b02af174e86a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for static-php-py 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.