Skip to main content

phpserialize-rs

Crates.io PyPI License CI

High-performance PHP serialize/unserialize parser written in Rust with Python bindings.

Features

  • Zero-copy parsing - Minimal memory allocations for maximum performance
  • Full PHP serialize support - All types including objects, references, and PHP 8.1 enums
  • UTF-8 aware - Proper handling of multi-byte characters (Korean, Chinese, etc.)
  • Auto-unescape - Automatic detection and handling of DB-escaped strings
  • Auto-fallback - Automatic recovery from encoding mismatches (e.g., EUC-KR to UTF-8)
  • Error recovery - Configurable error handling for malformed data
  • PySpark integration - Ready-to-use Arrow-optimized UDFs for Databricks/Spark workloads

Installation

Python

pip install phpserialize-rs

Rust

[dependencies]
php-deserialize-core = "0.1"

Quick Start

Python

from php_deserialize import loads, loads_json

# Basic usage
data = b'a:2:{s:4:"name";s:5:"Alice";s:3:"age";i:30;}'
result = loads(data)
print(result)  # {'name': 'Alice', 'age': 30}

# Direct JSON conversion (optimized for Databricks)
json_str = loads_json(data)
print(json_str)  # {"name":"Alice","age":30}

# Handle DB-escaped strings automatically
escaped = b'"a:1:{s:4:""key"";s:5:""value"";}"'
result = loads(escaped)  # Auto-unescapes
print(result)  # {'key': 'value'}

# Auto-fallback for encoding mismatches (no option needed!)
# Handles data serialized with EUC-KR but stored as UTF-8
mismatch = b's:4:"\xed\x95\x9c\xea\xb8\x80";'  # "한글" with wrong length
result = loads(mismatch)  # Automatically recovers
print(result)  # '한글'

# Strict mode (disable auto-fallback)
result = loads(data, strict=True)  # Fails on length mismatch

# Error handling options
result = loads(data, errors="replace")  # Replace invalid UTF-8
result = loads(data, errors="bytes")    # Return bytes for invalid UTF-8

PySpark / Databricks

from php_deserialize.spark import php_to_json
from pyspark.sql.functions import get_json_object

# Convert PHP serialize to JSON (Arrow-optimized UDF)
df = spark.table("bronze.my_table")
df = df.withColumn("data_json", php_to_json("serialized_column"))

# Extract fields from JSON
df = df.withColumn("name", get_json_object("data_json", "$.name"))
df = df.withColumn("age", get_json_object("data_json", "$.age"))

df.display()

For Databricks installation:

%pip install phpserialize-rs

Rust

use php_deserialize_core::{from_bytes, PhpValue};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let data = br#"a:2:{s:4:"name";s:5:"Alice";s:3:"age";i:30;}"#;
    let value = from_bytes(data)?;

    if let PhpValue::Array(items) = value {
        for (key, val) in items {
            println!("{:?} => {:?}", key, val);
        }
    }

    Ok(())
}

Supported PHP Types

Type PHP Format Example
Null N; N;
Boolean b:0; / b:1; b:1;
Integer i:<value>; i:42;
Float d:<value>; d:3.14;
String s:<len>:"<data>"; s:5:"hello";
Array a:<count>:{...} a:1:{i:0;s:3:"foo";}
Object O:<len>:"<class>":<count>:{...} Object with properties
Reference R:<index>; / r:<index>; Circular references
Enum (PHP 8.1+) E:<len>:"<Class:Case>"; E:10:"Status:Active";

Performance

Benchmarked on Apple M1 Pro:

Operation Throughput
Simple array ~1.5 GB/s
Nested structure ~800 MB/s
Large string ~2.0 GB/s

Compared to php2json (Python):

  • 10-50x faster for typical workloads
  • 100x faster for large arrays

Error Handling

The library provides detailed error messages for debugging:

from php_deserialize import loads, PhpDeserializeError

try:
    loads(b"invalid data")
except PhpDeserializeError as e:
    print(f"Parse error at position {e.position}: {e.message}")

DB Escape Handling

When data is exported from databases (MySQL, PostgreSQL), strings may be double-quoted and escaped:

Original: a:1:{s:4:"key";s:5:"value";}
DB Export: "a:1:{s:4:""key"";s:5:""value"";}"

The library automatically detects and handles this format:

# Both work identically
loads(b'a:1:{s:4:"key";s:5:"value";}')
loads(b'"a:1:{s:4:""key"";s:5:""value"";}"')

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

Licensed under either of:

at your option.

Metadata

Release files for phpserialize-rs 0.1.2

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

Source distribution (sdist)

Source distribution for phpserialize-rs 0.1.2
File Size Uploaded Provenance Actions
phpserialize_rs-0.1.2.tar.gz 36.5 kB With provenance Details for phpserialize_rs-0.1.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for phpserialize-rs 0.1.2
File Actions
phpserialize_rs-0.1.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for phpserialize_rs-0.1.2-cp311-cp311-win_amd64.whl
phpserialize_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for phpserialize_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
phpserialize_rs-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.12+ x86-64 Details for phpserialize_rs-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl
phpserialize_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.17+ x86-64 Details for phpserialize_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Total release size: 960.5 kB

Release files / phpserialize_rs-0.1.2.tar.gz

Download URL phpserialize_rs-0.1.2.tar.gz
Size 36.5 kB
Tags Source
SHA-256 checksum
How to use checksums
24421e0cd6403c565410010aefd43de064698121c91a52c5a6f9fb62c4745ed7
BLAKE2b-256 checksum
How to use checksums
9a64d357c117bb7f64333fe46bc495890e0db03f268e93a8827c713005ec1201
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 4, 2026.

Transparency log

Release files / phpserialize_rs-0.1.2-cp311-cp311-win_amd64.whl

Download URL phpserialize_rs-0.1.2-cp311-cp311-win_amd64.whl
Size 154.3 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
3af41ff90083647b5762659b275bd029c6861e9163ecbfe7957df8e3b8a7637b
BLAKE2b-256 checksum
How to use checksums
abb7efda319fabfbc995c1852615895598b8e2786833ebbfe49b2c99470b9bef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 4, 2026.

Transparency log

Release files / phpserialize_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl

Download URL phpserialize_rs-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Size 247.7 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43ddb52e71d6fe0e9f04ea30cf37638c5beebf84efc4160d01e10e6188765726
BLAKE2b-256 checksum
How to use checksums
dd708e07fc9cca3a5afa13750c7bb50e48ba35d11adaf642330054ca67dbff30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 4, 2026.

Transparency log

Release files / phpserialize_rs-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl

Download URL phpserialize_rs-0.1.2-cp311-cp311-macosx_10_12_x86_64.whl
Size 255.8 kB
Tags CPython 3.11 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
3dec7e9aa5830c76a9ff7738b4e6cda02edf388757eae3e90a06e0c0d6ebe9fd
BLAKE2b-256 checksum
How to use checksums
eda283f4fa98ef18aff4bea4debcb6b8d31f637feefb8cefd6caa720e3ed4647
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 4, 2026.

Transparency log

Release files / phpserialize_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL phpserialize_rs-0.1.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 266.3 kB
Tags CPython 3.8 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
81e6955c0802bfb09214515d32d03f5eb712a07aafc5cf3b4edbd14a896a86c5
BLAKE2b-256 checksum
How to use checksums
930612cc171facad63f76888304b8ec85da91e873ed786e88d6ca83a46a129f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Feb 4, 2026.

Transparency log

Security for phpserialize-rs 0.1.2

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 5 files in this release have been uploaded with provenance metadata.

Select from 5 files

Attestation for phpserialize_rs-0.1.2.tar.gz

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 Feb 4, 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.1.2 This release

5 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