WXF (.wxf)
- Import and Export fully support Wolfram Language WXF files.
- WXF byte arrays can be created with BinarySerialize and read with BinaryDeserialize.
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.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
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

- Export options:
-
PerformanceGoal Automatic specify a serialization strategy Method Automatic serialization method options
Examples
open allclose allBasic Examples (4)Summary of the most common use cases

https://wolfram.com/xid/0cb01mgko-1o6pyu


https://wolfram.com/xid/0cb01mgko-0qogd9

Export a symbolic expression to WXF:

https://wolfram.com/xid/0cb01mgko-436rwo


https://wolfram.com/xid/0cb01mgko-9kze26

Export an arbitrary Wolfram Language expression to the WXF format:

https://wolfram.com/xid/0cb01mgko-dant83

https://wolfram.com/xid/0cb01mgko-isyk46

Scope (2)Survey of the scope of standard use cases
Serialize an expression to a WXF byte array:

https://wolfram.com/xid/0cb01mgko-4wpm3s

Deserialize the output using BinaryDeserialize:

https://wolfram.com/xid/0cb01mgko-2borvf

Serialize an expression to a WXF byte array:

https://wolfram.com/xid/0cb01mgko-dq4atb

Import it using automatic format detection:

https://wolfram.com/xid/0cb01mgko-7xzxyk

Import Elements (4)

https://wolfram.com/xid/0cb01mgko-4x4i68

Serialize an unevaluated expression:

https://wolfram.com/xid/0cb01mgko-m6ocz7

Import it using the default element "Expression":

https://wolfram.com/xid/0cb01mgko-og06fn

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

https://wolfram.com/xid/0cb01mgko-3jhgzz

Get WXF data from an untrusted source:

https://wolfram.com/xid/0cb01mgko-qd5s5w
Inspect the element "HeldExpression":

https://wolfram.com/xid/0cb01mgko-pegcx7

The code is safe; evaluate it:

https://wolfram.com/xid/0cb01mgko-c3q1o0

Import bytes with the element "ExprStruct":

https://wolfram.com/xid/0cb01mgko-yh53zg

The expression is held in an unevaluated state:

https://wolfram.com/xid/0cb01mgko-mjo4wc

Export Options (5)
PerformanceGoal (2)
Serialize an expression using BinarySerialize to produce a compressed output:

https://wolfram.com/xid/0cb01mgko-j9ozpz

Import the resulting byte array:

https://wolfram.com/xid/0cb01mgko-3n5s4d


https://wolfram.com/xid/0cb01mgko-76lzw3
Serialize the same dataset with PerformanceGoal set to "Size":

https://wolfram.com/xid/0cb01mgko-enmxuq
Compute the size of the outputs:

https://wolfram.com/xid/0cb01mgko-okkb5v

Both represent the same expression:

https://wolfram.com/xid/0cb01mgko-hv3of5

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

https://wolfram.com/xid/0cb01mgko-h09z3y

Export a packed array using a bigger integer type:

https://wolfram.com/xid/0cb01mgko-kag7qn

Create a packed array of real values:

https://wolfram.com/xid/0cb01mgko-gh0c61

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

https://wolfram.com/xid/0cb01mgko-j7kzr8

Export the array using machine floats:

https://wolfram.com/xid/0cb01mgko-fn6i49

Create a packed array of complex values:

https://wolfram.com/xid/0cb01mgko-x9xo0o

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

https://wolfram.com/xid/0cb01mgko-4ky10q

Export the array using lower precision:

https://wolfram.com/xid/0cb01mgko-ju8coy

Properties & Relations (2)Properties of the function, and connections to other functions
ExportByteArray[expr,"WXF"] is effectively equivalent to BinarySerialize[expr]:

https://wolfram.com/xid/0cb01mgko-80fq1v

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

https://wolfram.com/xid/0cb01mgko-2oo7r8

https://wolfram.com/xid/0cb01mgko-54jrm7
