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["file.wxf"] imports a WXF file as a Wolfram Language expression.
  • ImportString["string","WXF"] imports a WXF string of bytes.
  • ImportByteArray[bytearray, "WXF"] imports a WXF array of bytes.
  • Export["file.wxf",expr] exports the binary representation of an expr to a WXF file.
  • ExportString[expr,"WXF"] exports to a WXF string of bytes.
  • ExportByteArray[expr, "WXF"] exports an expr as a WXF byte array.

Import Elements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties and settings
  • Import elements:
  • "Expression"returns the serialized expression
    "HeldExpression"returns the expression wrapped in HoldComplete
  • Import by default uses the "Expression" element for Wolfram Language WXF files.



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  (3)

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:

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]:

Introduced in 2018