Skip to main content

The v8serialize logo. Monochome. Large "V8" and smaller "serialize" in a handwritten style, with the 8 stylized to look like a snake.

Imagine having postMessage() between JavaScript and Python.

pip install v8serialize

Documentation


v8serialize

A Python library to read & write JavaScript values in V8 serialization format with Python.

Examples

These examples demonstrate serializing and deserializing the same selection of JavaScript values in Python and JavaScript. JavaScript types supported by JavaScript's structuredClone() algorithm can be serialized.

Serialize with Python

from base64 import b64encode
from datetime import datetime, UTC
import re

from v8serialize import dumps
from v8serialize.jstypes import JSObject, JSArray, JSUndefined

serialized = dumps(
    [
        "strings 🧵🧶🪡",
        123,
        None,
        JSUndefined,
        JSArray({0: 'a', 1: 'b', 123456789: 'sparse'}),
        JSObject({"msg": "Hi"}),
        b"\xc0\xff\xee",
        2**128,
        {"maps": True},
        {"sets", "yes"},
        re.compile(r"^\w+$"),
        datetime(2024, 1, 1, tzinfo=UTC),
    ]
)

print(b64encode(serialized).decode())

Output

/w9BDFMUc3RyaW5ncyDwn6e18J+ntvCfqqFVezBfYZaa7zpVAFMBYVUBUwFiVZWa7zpTBnNwYXJzZUADlprvOm9TA21zZ1MCSGl7AUIDwP/uWiIAAAAAAAAAAAAAAAAAAAAAATtTBG1hcHNUOgInUwRzZXRzUwN5ZXMsAlJTBV5cdyskgAJEAABAHyXMeEIkAAw=

Deserialize with Python

from base64 import b64decode
from v8serialize import loads

# The output of the JavaScript example
serialized = b64decode(
    "/w9BDGMccwB0AHIAaQBuAGcAcwAgAD7Y9d0+2PbdPtih3kn2ATBfYZaa7zpJACIBYUkCIgFiSaq03nUiBnNwYXJzZUADlprvOm8iA21zZyICSGl7AUIDwP/uWjAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA7IgRtYXBzVDoCJyIDeWVzIgRzZXRzLAJSIgVeXHcrJIACRAAAQB8lzHhCJAAM"
)
print(loads(serialized))

Output

JSArray([
  'strings 🧵🧶🪡',
  123,
  None,
  JSUndefined,
  JSArray({
    0: 'a',
    1: 'b',
    123456789: 'sparse',
  }),
  JSObject(msg='Hi'),
  JSArrayBuffer(b'\xc0\xff\xee'),
  340282366920938463463374607431768211456,
  JSMap({
    'maps': True,
  }),
  JSSet([
    'yes',
    'sets',
  ]),
  JSRegExp(source='^\\w+$', flags=<JSRegExpFlag.UnicodeSets: 256>),
  datetime.datetime(2024, 1, 1, 0, 0),
])

Serialize with Node.js / Deno

import * as v8 from "node:v8";

const sparseArray = ["a", "b"];
sparseArray[123456789] = "sparse";

const buffer = v8.serialize([
  "strings 🧵🧶🪡",
  123,
  null,
  undefined,
  sparseArray,
  { msg: "Hi" },
  Uint8Array.from([0xc0, 0xff, 0xee]).buffer,
  2n ** 128n,
  new Map([["maps", true]]),
  new Set(["yes", "sets"]),
  /^\w+$/v,
  new Date(Date.UTC(2024, 0, 1)),
]);

console.log(buffer.toString("base64"));

Output

/w9BDGMccwB0AHIAaQBuAGcAcwAgAD7Y9d0+2PbdPtih3kn2ATBfYZaa7zpJACIBYUkCIgFiSaq03nUiBnNwYXJzZUADlprvOm8iA21zZyICSGl7AUIDwP/uWjAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAA7IgRtYXBzVDoCJyIDeWVzIgRzZXRzLAJSIgVeXHcrJIACRAAAQB8lzHhCJAAM

Deserialize with Node.js / Deno

import * as v8 from "node:v8";

// The output of the Python example
const buffer = Buffer.from(
  "/w9BDFMUc3RyaW5ncyDwn6e18J+ntvCfqqFVezBfYZaa7zpVAFMBYVUBUwFiVZWa7zpTBnNwYXJzZUADlprvOm9TA21zZ1MCSGl7AUIDwP/uWiIAAAAAAAAAAAAAAAAAAAAAATtTBG1hcHNUOgInUwN5ZXNTBHNldHMsAlJTBV5cdyskgAJEAABAHyXMeEIkAAw=",
  "base64"
);
console.log(v8.deserialize(buffer));

Output

[
  'strings 🧵🧶🪡',
  123,
  null,
  undefined,
  [ 'a', 'b', <123456787 empty items>, 'sparse' ],
  { msg: 'Hi' },
  ArrayBuffer { [Uint8Contents]: <c0 ff ee>, byteLength: 3 },
  340282366920938463463374607431768211456n,
  Map(1) { 'maps' => true },
  Set(2) { 'yes', 'sets' },
  /^\w+$/v,
  2024-01-01T00:00:00.000Z
]

Metadata

Release files for v8serialize 0.4.0

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

Source distribution (sdist)

Source distribution for v8serialize 0.4.0
File Size Uploaded Provenance
v8serialize-0.4.0.tar.gz 85.6 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for v8serialize 0.4.0
File Interpreter ABI Platform
v8serialize-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 187.2 kB

Release files / v8serialize-0.4.0.tar.gz

Download URL v8serialize-0.4.0.tar.gz
Size 85.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d7fc3894762813cf76c3da0333f3e2d785b195ce6d54b8a6761c45916de775c0
BLAKE2b-256 checksum
How to use checksums
7b01ad3ab51fec166f80ed063ea885ef4c7057fa5324bc449f2fd92cb9fa13e7
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 Sep 30, 2025.

Transparency log

Release files / v8serialize-0.4.0-py3-none-any.whl

Download URL v8serialize-0.4.0-py3-none-any.whl
Size 101.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22abf94c2a7261605c24bba4aa9371f91af785c83c5adf8cce2088dbe24fd1ec
BLAKE2b-256 checksum
How to use checksums
112f08eb32fb6db13017e55a2a5d2f89951dd683eb2daa27dd14357c8e3b25ec
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 Sep 30, 2025.

Transparency log

Security for v8serialize 0.4.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 v8serialize-0.4.0.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 Sep 30, 2025.

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.

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