Skip to main content

phantom — Python bindings for Phantom

Idiomatic Python bindings for the Phantom compiler. Calls JIT-compiled Phantom shapes against numpy arrays in one function call — no ctypes, no manual buffer management, no dylib path juggling.

Install

pip install maturin
git clone https://github.com/menezzo/phantom
cd phantom/crates/phantom-pyo3
maturin develop --release

A pip install phantom wheel is the next ship; until then, maturin develop builds the extension module in-place against your active Python interpreter.

Quickstart

import numpy as np
import phantom

# Run a Phantom shape from a .ph file with a numpy float32 input.
out = phantom.run(
    "examples/two_host_pipeline.ph",
    np.array([1.0, 2.0, 3.0, 4.0], dtype=np.float32),
)
print(out)  # numpy array

# With pre-loaded weights from a directory of .npy files.
out = phantom.run(
    "examples/gpt2.ph",
    np.load("/tmp/phantom-gpt2-golden/input.npy"),
    weights_dir="/tmp/phantom-gpt2-golden",
)
print(out.shape)  # (32, 256)

# Or compile from a source string (for inline notebook use).
src = """
shape add_one =
  it ~> add 1.0
"""
out = phantom.run_source(src, np.array([1.0, 2.0, 3.0], dtype=np.float32))
print(out)  # [2., 3., 4.]

Contract

  • f32 only: numpy arrays must be dtype=np.float32. Other dtypes raise TypeError at the boundary. Cast explicitly with .astype(np.float32) if you need to.
  • C-contiguous only: non-contiguous arrays raise ValueError. Use np.ascontiguousarray(arr) to convert.
  • Errors are Python exceptions: parse/resolve/typecheck/lower failures raise RuntimeError with the rendered diagnostic; runtime errors do the same. No status codes, no thread-local error strings.

What this wraps

phantom.run and phantom.run_source are thin wrappers over phantom_driver::run_pipeline::compile_and_invoke. The same JIT pipeline that powers phantom-driver run from the CLI also powers these calls, so the numerical results match bit-identical (or within floating-point noise) between the Python API and the CLI.

The Phantom GPT-2 model that matches PyTorch within 1.79e-07 via the C FFI also matches PyTorch via this API — same JIT, same MLIR, same LLVM codegen, just a different ergonomic shell.

Metadata

Release files for phantom-lang 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for phantom-lang 0.2.0
File Interpreter ABI Platform
phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl CPython 3.9 abi3 Linux glibc 2.35+ x86-64 Details
phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 95.7 MB

Release files / phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl

Download URL phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl
Size 56.1 MB
Tags CPython 3.9 Linux glibc 2.35+ x86-64 abi3
SHA-256 checksum
How to use checksums
07d64f04035edda6b63695eec35cd7c2b6a4cccdb543d9090e743a3fb6ed91f1
BLAKE2b-256 checksum
How to use checksums
f03f8ac2786cf419301496b720c38174e5e419ed5711cf0fae8bdf17e1f26f5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Release files / phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL phantom_lang-0.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 39.6 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
498c11e84ea11eae95c9b07f8361ba8817dc1e817382495726e1dda433c4b4c2
BLAKE2b-256 checksum
How to use checksums
8d533212d242cfbcbcfef1c2db988bf8ac951b92954f6899b6854c34b6b8fc8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

Security for phantom-lang 0.2.0

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for phantom_lang-0.2.0-cp39-abi3-manylinux_2_35_x86_64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 13, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page