Skip to main content

flatwire (Python)

Streaming JSON serialization that keeps memory flat and time linear — stream large collections element-by-element instead of materializing the whole payload.

pip install flatwire
import flatwire

# Whole-value convenience (byte-compatible with the standard library).
data = flatwire.encode({"hello": "world"})
value = flatwire.decode(data)

# Stream a large collection to a binary writer, one element at a time.
with open("out.json", "wb") as fp:
    flatwire.encode_array((row for row in huge_iterator), fp)

# Read it back lazily — peak memory is one element, not the whole array.
with open("out.json", "rb") as fp:
    for row in flatwire.decode_array(fp):
        handle(row)

Wire format is plain JSON, so nothing downstream changes.

Streaming XML (v0.3)

The same API streams a typed, fully round-trippable XML representation — for which the standard DOM parsers would otherwise build the whole tree in memory:

# Stream a large collection as XML.
with open("out.xml", "wb") as fp:
    flatwire.encode_array(rows, fp, format="xml")        # optional: root="items"

# Parse it back lazily, one element at a time (iterparse under the hood).
with open("out.xml", "rb") as fp:
    for row in flatwire.decode_array(fp, format="xml"):
        handle(row)

Measured (bench/xml_bench.py): parsing a 12 MB document with ElementTree.fromstring peaks at ~125 MB, while flatwire's streaming parse holds ~4 MB (~97% lower); streaming encode is flat at ~900 bytes.

See the monorepo README for the cross-language story and benchmarks.

Apache-2.0.

Metadata

Release files for flatwire 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 flatwire 0.4.0
File Size Uploaded
flatwire-0.4.0.tar.gz 11.4 kB Details

Built distribution (wheel)

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

Total release size: 21.4 kB

Release files / flatwire-0.4.0.tar.gz

Download URL flatwire-0.4.0.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
abb3bc7155a9f5fdf9750f7a764c2abed65250ebfbb40889922c35ad90605060
BLAKE2b-256 checksum
How to use checksums
c0bd1695aef1fa6ec01e9c0acf75d5ea6fa7793fded4db09d35dff306f7401d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL flatwire-0.4.0-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
58acaa9a0039608ca5bd23bfff7f58b435ac29656de96e60bd4aef1bd994ca3f
BLAKE2b-256 checksum
How to use checksums
5704d04952d9b93dbd9456cbc1b7ba4e67f8083e725e3605f5a1955172c2de5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

1.1.0

2 release files

1.0.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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