WXF (.wxf)

Background & Context

    • Wolfram exchange format.
    • Binary format.
    • Represents arbitrary Wolfram Language expressions in a serialized, platform-independent form.
    • Versioned format.
    • Developed in 2017 by Wolfram Research.

Import & Export

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Summary"summary of the file
    "Rules"list of rules for all available elements
  • Import elements:
  • "Expression"returns the serialized expression
    "HeldExpression"returns the expression wrapped in HoldComplete
    "ExprStruct"returns the expression as an "ExprStruct" data structure
  • Import by default uses the "Expression" element for Wolfram Language WXF files.

Options

Examples

open allclose all

Basic Examples  (4)

Export an expression to WXF:

Export a string to WXF:

Export a symbolic expression to WXF:

Import as an expression:

Export an arbitrary Wolfram Language expression to the WXF format:

Import as an expression:

Scope  (2)

Serialize an expression to a WXF byte array:

Deserialize the output using BinaryDeserialize:

Serialize an expression to a WXF byte array:

Import it using automatic format detection:

Import Elements  (4)

List available elements:

Serialize an unevaluated expression:

Import it using the default element "Expression":

Import it in a held form using the element "HeldExpression":

Get WXF data from an untrusted source:

Inspect the element "HeldExpression":

The code is safe; evaluate it:

Import bytes with the element "ExprStruct":

The expression is held in an unevaluated state:

Export Options  (5)

PerformanceGoal  (2)

Serialize an expression using BinarySerialize to produce a compressed output:

Import the resulting byte array:

Serialize a dataset:

Serialize the same dataset with PerformanceGoal set to "Size":

Compute the size of the outputs:

Both represent the same expression:

Method  (3)

By default, the WXF serialization of packed arrays of integers uses the smallest integer type that fits the data:

Export a packed array using a bigger integer type:

Create a packed array of real values:

By default, the WXF serialization of a packed array of real values uses machine doubles:

Export the array using machine floats:

Create a packed array of complex values:

By default, the WXF serialization of packed array of complex values uses two machine doubles to represent one complex value:

Export the array using lower precision:

Properties & Relations  (2)

ExportByteArray[expr,"WXF"] is effectively equivalent to BinarySerialize[expr]:

ImportByteArray[ba,"WXF"] is effectively equivalent to BinaryDeserialize[ba]: