FastWARC is a high-performance Python library for parsing WARC (Web ARChive) files, written in C++/Cython. It supports WARC/1.0 and WARC/1.1 streams with GZip and LZ4 compression, offering significant speed improvements over pure Python alternatives like WARCIO. FastWARC is part of the ChatNoir Resiliparse toolkit and is currently at version 0.16.0, with active development.
pip install fastwarcVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to iterate through records in a WARC file using `ArchiveIterator`. It shows how to access record metadata like `record_id` and `url`, and how to read the content. For HTTP response records, it also shows how to access parsed HTTP headers. A dummy WARC file is created for the example to be runnable.
Review FastWARC documentation for API differences when migrating from WARCIO.
Pass `strict_mode=False` to `ArchiveIterator` for more lenient parsing of non-compliant WARC files. Be aware this might affect how record boundaries are determined.
Set `parse_http=False` in the `ArchiveIterator` constructor. You can parse HTTP headers later on a per-record basis using `record.parse_http()` if needed.
For large records, ensure they fit into memory or set `consume=True` when calling digest verification methods if you do not need to preserve the stream contents for subsequent operations. This avoids creating a stream copy.
If you require ARC format compatibility, you will need to use a different library such as WARCIO.
For the best performance on Linux, it is recommended to build FastWARC from source by installing build dependencies (`build-essential`, `python3-dev`, `zlib1g-dev`, `liblz4-dev`) and then using `pip install --no-binary fastwarc fastwarc`.
Install fastwarc using pip. If pre-built binaries are not available or fail, ensure build dependencies are installed for your operating system (e.g., `sudo apt install build-essential python3-dev zlib1g-dev liblz4-dev` on Ubuntu) and then run `pip install --no-binary fastwarc fastwarc` to build from source.
Replace `WarcReader` with `ArchiveIterator`. The correct import is `from fastwarc.warc import ArchiveIterator`.
Access the record's payload stream using `record.reader` instead of `record.raw_stream`. For example, `payload_data = record.reader.read()` will read the body.
Implement robust error handling by wrapping WARC processing in a `try...except fastwarc.stream_io.FastWARCError` block. For problematic WARC files (e.g., ClueWeb), consider initializing `ArchiveIterator` with `strict_mode=False` or `parse_http=False` to handle non-standard formats.