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
php = PHP.system() # first php on the system PATH
php = PHP.remote("https://example.com/php-8.4.tar.gz", # download + cache
checksum="sha256:9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08")
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 typed Requirements constant, and check any bound binary against it with require:
from static_php_py import PHP, Requirements
REQUIREMENTS = Requirements(
version=">=8.4", # PEP 440 specifier, or None for any
extensions=frozenset({"tokenizer", "mbstring"}),
)
php = PHP.bundled().require(REQUIREMENTS)
require probes only what the declaration states — no version subprocess without a version constraint, no php -m without extensions — and returns the same PHP for chaining. A violated version constraint raises VersionUnsatisfiedError; a missing extension raises ExtensionUnsatisfiedError, naming the static-php-build tool that produces a satisfying binary. The same constant drives static-php-build --manifest your_lib:REQUIREMENTS, so both tools stay in sync from one declaration.
Self-managed binary
A library that needs a fixed extension set ships its own binaries as package data and loads the host's one with PHP.local, so its end users install nothing and never compile. Build one archive per OS with static-php-build, declare the archives (.tar.gz/.tgz/.zip, default directory your_lib/_resources/) as package data, and resolve at runtime with PackagedBinary — never the system PATH or a user-supplied path. Selection is by name heuristics — the archive whose name carries the host's OS and architecture tokens (and the series, when given) is chosen — so official static-php-cli release names work unrenamed:
from static_php_py import PHP, PackagedBinary
_BINARY = PackagedBinary(package="your_lib", series="8.4")
def php() -> PHP:
return PHP.local(_BINARY.resolve())
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.PHP.system() -> PHP— firstphpexecutable on the system PATH.PHP.remote(url: str, *, force: bool = False, timeout: float = 300.0, checksum: str | None = None) -> PHP— download, extract (.tar.gz/.tgz/.zip), and cache;checksum("sha256:<hexdigest>", also sha384/sha512) verifies the download before use.PHP.cache_dir() -> Path— platform-specific download cache directory.require(requirements: Requirements) -> PHP— check the binary against a declaration; probes only declared parts; returns self.run(script, args=None, *, input=None, ini=None, timeout=None) -> ExecutionResult—inputfeeds stdin;inimaps to-d key=valueoptions.eval(code, *, input=None, ini=None, timeout=None) -> ExecutionResult— sameinput/inisemantics asrun.version() -> strextensions() -> frozenset[str]— loaded extensions viaphp -m, lowercased.check_extensions(required) -> ExtensionReport— pure inspection; no download or build.path(property)-> Path
Requirements(version: str | None = None, extensions: frozenset[str] = frozenset())— frozen declaration of the needed PHP version (PEP 440 specifier) and extension set.PackagedBinary(package: str, series: str | None = None, *, directory: str = "_resources")— resolver for a consumer-carried platform archive set;seriesnarrows selection (None selects across all series),directorynames the package-relative archive directory.resolve() -> Path— select the host's archive by name heuristics (macos≈darwin,windows≈win,x86_64≈amd64,aarch64≈arm64; a name with no architecture token matches any), extract its PHP binary beside it (once), and return the path; pass the result toPHP.local.
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.5
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.5.tar.gz | 70.1 kB | Without provenance | Details for static_php_py-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| static_php_py-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for static_php_py-0.1.5-py3-none-any.whl |
Total release size: 112.5 kB
Release files / static_php_py-0.1.5.tar.gz
| Download URL | static_php_py-0.1.5.tar.gz |
|---|---|
| Size | 70.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61d874c4b1920d26c298d5b464faaa1f4738a3ebfd6c405bf0ce78c17fe83aa0
|
|
BLAKE2b-256 checksum How to use checksums |
ec37d67c339a5bf95efcb5042d92a4cfa6a11943f337ef032ffd1c31b5c19289
|
| 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.5-py3-none-any.whl
| Download URL | static_php_py-0.1.5-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
41dcb23939d97a89ad81536d451a99bdfe62dd6c957a0693e40c7fddb9fedd25
|
|
BLAKE2b-256 checksum How to use checksums |
3aa8dd272d84a177f05f9038037168b7af08bf20ca5f9f4855755f13a5daca42
|
| 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.5
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.