pcapmbo
Decode raw exchange packet captures (pcap / pcap.zst) into standard market-by-order (MBO) events, with both the exchange timestamp and the capture timestamp. Rust core, Python API.
pip install "pcapmbo[arrow]"
import pcapmbo
for batch in pcapmbo.read_pcap("capture.pcap.zst", symbols=["NVDA"]):
print(batch.num_rows) # a pyarrow.RecordBatch of MBO records
pcapmbo.to_dbn("capture.pcap.zst", "nvda.mbo.dbn.zst", symbols=["NVDA"])
Supported feed: Nasdaq TotalView-ITCH 5.0 over MoldUDP64, in classic pcap files (nanosecond or microsecond, plain or zstd-compressed), with Ethernet, up to two VLAN tags, IPv4 and UDP.
Status: alpha (0.1). Checked against an independent parser on real Nasdaq captures (below). The API may still change before 1.0.
Why
Fast ITCH parsers and order book tools already exist, but they read ITCH day files, not network captures. The tools that do read captures are C++ programs with in-memory books or their own CSV output. pcapmbo gives you, from a pip install:
- raw captures in: pcap / pcap.zst, with MoldUDP64 sequencing, gap reports, A/B duplicates dropped, and a session carried across rotated files
- standard events out: the MBO schema of the open DBN format, following Databento's own normalization of Nasdaq ITCH, so the output works with Databento's tools as well as pandas, polars and Parquet
- both clocks:
ts_event(exchange time) andts_recv(when the capture saw the packet)
| reads raw captures | standard event output | Python API | licence | |
|---|---|---|---|---|
| pcapmbo | yes | DBN MBO, Arrow | yes | Apache-2.0 |
| itch-book | no (ITCH day files) | its own | yes | MIT |
| MeatPy | IEX DEEP only | its own | yes (pure Python) | BSD-3 |
| pcap_feed_decoder | yes | in-memory books | no | AGPL-3.0 |
| Databento DBN | no (Databento's own data) | DBN | yes | Apache-2.0 |
Output
read_pcap(paths, symbols=None, date=None, batch_size=1_000_000) yields Arrow
record batches with pcapmbo.schema():
| column | type | |
|---|---|---|
ts_recv |
timestamp[ns, UTC] | capture time |
ts_event |
timestamp[ns, UTC] | exchange time (ITCH timestamp on the Eastern trading date) |
publisher_id |
uint16 | 2, DBN's id for Nasdaq TotalView-ITCH |
instrument_id |
uint32 | the day's stock locate code |
action |
string | Add, Cancel, Trade, Fill |
side |
string | Ask, Bid, None |
price |
int64 | units of 1e-9 (divide by pcapmbo.PRICE_SCALE); null if unknown |
size |
uint32 | shares |
channel_id |
uint8 | 0 |
order_id |
uint64 | Nasdaq order reference; 0 on Trades |
flags |
uint8 | F_LAST, F_MAYBE_BAD_BOOK, ... |
ts_in_delta |
int32 | ts_recv - ts_event |
sequence |
uint32 | MoldUDP64 sequence number (low 32 bits) |
symbol |
string | ticker |
to_dbn(paths, out, symbols=None, date=None) writes the same records as a DBN
file (zstd if out ends in .zst), with dataset XNAS.ITCH, schema mbo
and per-day symbol mappings. Databento's databento-dbn reads it back.
How ITCH becomes MBO
| ITCH message | MBO records |
|---|---|
| Add (A), Add with MPID (F) | Add |
| Order Executed (E) | Trade, Fill, Cancel |
| Order Executed with Price (C) | Trade, Fill, Cancel (no Trade if non-printable) |
| Order Cancel (X) | Cancel (the shares removed) |
| Order Delete (D) | Cancel (the shares left) |
| Order Replace (U) | Cancel (old order), Add (new order, same side) |
| Trade, non-cross (P) | Trade, side None |
| Cross Trade (Q) | Trade, side None, if shares matched |
| everything else | nothing |
Trade and Fill records carry the aggressor's side and the execution price;
the Cancel after an execution carries the resting order's side and price and
is the only one that changes the book. Records from one ITCH message share
sequence; the last has F_LAST. A capture that starts mid-session can't
know orders added before it began: their executions and cancels get side
None, a null price and F_MAYBE_BAD_BOOK.
Not yet: filling gaps from a second line (A/B arbitration), IEX DEEP, CME MDP 3.0, pcapng.
Checked on real data
scripts/compare_with_course_parser.py decodes the same captures with
pcapmbo and with an independent Python ITCH parser (from the UIUC FIN 556
course project that pcapmbo grew out of) and compares every row.
One 10-minute Nasdaq file at the open (3 Feb 2025, 1.1 GB compressed, 45,088,399 messages), filtered to NVDA, AAPL and TSLA, on an Apple M4 Pro. The course parsers keep an order book, as pcapmbo's MBO output does:
| wall time | peak memory | |
|---|---|---|
| Python reference parser | 53.4 s | 4.55 GB |
| C++ build of the same parser | 3.5 s | 77 MB |
| pcapmbo, ITCH decoding | 3.3 s | 17 MB |
| pcapmbo, MBO records | 3.4 s | 365 MB |
The MBO run collects all 2.1 million records (about 115 MB) in one buffer and
copies it into Python; read_pcap streams them in batches instead.
All 1,618,385 rows for the three stocks matched the reference on every field, including the side and price it takes from its order book on executions, cancels and deletes. 0 gaps, 0 duplicates, 0 malformed messages.
Market data
This repository contains code only. Never commit market data, licensed
or otherwise: tests use synthetic captures. The .gitignore blocks common
capture and data file types as a safety net.
Development
Needs Rust 1.88 or newer and Python 3.9 or newer.
python -m venv .venv && source .venv/bin/activate
pip install maturin -e ".[test]"
cargo test # Rust tests
maturin develop --release # build the extension into the venv
pytest # Python tests
Test captures
Tests never use real market data. tests/capgen.py builds synthetic ITCH 5.0
captures byte by byte (pcap, Ethernet with optional VLAN tag, IPv4, UDP,
MoldUDP64), together with the list of messages a correct decoder should
produce. It covers every ITCH 5.0 message type and the cases decoders tend to
get wrong: heartbeats, non-market frames, A/B duplicates, sequence gaps,
session changes, microsecond pcaps, truncated frames and files split across a
session. The MBO output is checked byte for byte against a reference mapper
written separately in Python, and the DBN files against Databento's decoder.
python tests/capgen.py OUT_DIR # write the standard fixture files
Counting messages
cargo run --release --example count -- capture.pcap.zst
prints the messages per ITCH type, the gaps and duplicates found, and the throughput.
Licence
Metadata
Release files for pcapmbo 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pcapmbo-0.1.0.tar.gz | 50.0 kB | Without provenance | Details for pcapmbo-0.1.0.tar.gz |
Built distributions (wheels)
Total release size: 5.4 MB
Release files / pcapmbo-0.1.0.tar.gz
| Download URL | pcapmbo-0.1.0.tar.gz |
|---|---|
| Size | 50.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
39f98209da7d531c6bce57cb785a7bd42cbc88f794d67af81fb9dc5d59eaf6d2
|
|
BLAKE2b-256 checksum How to use checksums |
c352b12744a88cf23c49f7cf2b421b7cb1adce65fb0b4df2c44b292369f0a8a3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-win_amd64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 512.0 kB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f028a42b84d2656cf115af2860861efb0f1ef2758b86e0f9353715168c7fc9d4
|
|
BLAKE2b-256 checksum How to use checksums |
fab9927d62fb04bf94220265007c150b148bd092f1970848264ab3504d699b1f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 991.7 kB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
831ee6a04e2b558d7f30d15580d584e23a0c8b9109e5169251aed0f41831337e
|
|
BLAKE2b-256 checksum How to use checksums |
3f42d76f30b494d9f6e18ed7bd8aa1ce071eae899a57aff00ff087910be1cdc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 932.3 kB |
| Tags | CPython 3.9 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
0a4898719895b78f5d8ce422809b5d36d78c5d5726f290416b0aa75b33d577c5
|
|
BLAKE2b-256 checksum How to use checksums |
4901d47924b032c89874fef9a521e11d2fa91dad9673f60ed46a0562a31fa54a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 778.1 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
40099f1e94f7fd7cae651a78bdbeb9720876b672750d49e47bbe326360c06750
|
|
BLAKE2b-256 checksum How to use checksums |
773e9407f21ff019f22e4967758cd4314ba8659676ac8a3c53845885cafd7605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 769.5 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
5e3dfe753f3e061fde1a792159e4faa96470d177fd8b25d00bed8c1afb3c492b
|
|
BLAKE2b-256 checksum How to use checksums |
b53e5a259b61f9ade8330a569be3ece31d13bf2493a58ecd7f9ca0decefbde92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 626.5 kB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f12b2ffea08f5114aeb4d15014aed52c4d3cca40d32f7c2da11b021e9a10da1c
|
|
BLAKE2b-256 checksum How to use checksums |
8d8d9623eb814ef973680767e8548bca722d7353a8b224e9d6d7c13d540e6915
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pcapmbo-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | pcapmbo-0.1.0-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 701.6 kB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
1f14b91658cac752e08ac4bd9d1203b871339cd3d4c01b83d9543f8488c50b4e
|
|
BLAKE2b-256 checksum How to use checksums |
341f0f3da34e690fb47be003c830d77f4a9e46ffa743605eab990f78aeccf267
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pcapmbo 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.