Python interface to etherparse (Rust-based packet parser)
Project description
pytherparse
pytherparse provides Python bindings for the etherparse Rust crate, enabling high-performance packet parsing in Python via Rust and pyo3. This library is designed for developers working with network packets who need a fast and reliable way to parse Ethernet, IP, and transport layer headers.
Note: Internally, the compiled Rust extension is named
pytherparse_native, but it is exposed to Python via thepytherparsepackage using an interface defined in__init__.py.
Features
- Parse Ethernet, IP, and transport layer headers.
- High performance using Rust's
etherparsecrate. - Easy-to-use Python interface.
Usage
You can use pytherparse directly in your Python code or test it using the provided test_parse.py script.
Example: Parsing raw packet bytes
import pytherparse
# Parse a packet from raw bytes
packet = bytes.fromhex("00005e0001ce6a05e395f3f9080045000028000040004006d99d8d52ac193424f3a2f53501bb626f575200000000500400009dfb0000")
parsed = pytherparse.parse(packet)
print(parsed.ip.source)
Example: Parsing packets from a PCAP file
# Or parse packets from a pcap file
packets = pytherparse.parse("example.pcap")
for pkt in packets:
if pkt.ip:
print(f"{pkt.ip.source} → {pkt.ip.destination}")
Installation Note
Make sure you have installed pytherparse using maturin develop. Due to PyO3 import conflicts, the compiled Rust extension module is named pytherparse_native, but you should always import from the pytherparse package as shown above.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Acknowledgments
- etherparse for the Rust packet parsing library.
- pyo3 for enabling seamless Rust-Python bindings.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pytherparse-0.1.1.tar.gz.
File metadata
- Download URL: pytherparse-0.1.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e274567b734741c7f30ee7a736b3c4c1b915d687dd1b99cf87ac5396070ec362
|
|
| MD5 |
fcb30cc2a833de47edaa210d9583dbed
|
|
| BLAKE2b-256 |
fc555aca8b0e8bd989a175b2f49b05b459384f46faa49ecc060adfbb5c45a3e5
|