Skip to main content

LightPacket

A Python library for building, dissecting, capturing, and replaying network packets.

LightPacket brings packet crafting and network capture into one Python library. Its layered packet model covers traffic from Ethernet and VLAN through IPv4, IPv6, TCP, and UDP, as well as protocols such as ARP, PPPoE, and 802.11. Use it to inspect existing traffic, create packets for testing, capture traffic on a live interface, or work with packet-capture files, all through a consistent API.

LightPacket is designed for network engineers, security researchers, developers, and students who need to work with packets directly from Python. It combines a Scapy-style layering syntax with a built-in packet dissector, a Python cBPF engine, and pure-Python PCAP and PCAPNG file handling.

Why LightPacket?

  • Build and inspect layered packets. Compose protocol layers and parse raw frames into structured packet objects.
  • Work with a broad range of protocols. Supported layers span Ethernet, VLAN, ARP, IPv4, IPv6, TCP, UDP, PPP, and IEEE 802.11.
  • Filter without an external BPF compiler. The built-in LightBPF engine compiles and evaluates classic BPF filters in Python.
  • Read and write capture files in Python. PCAP and PCAPNG operations do not require a C compiler or native capture library.
  • Choose a live-capture backend. Use the cross-platform libpcap/Npcap-backed socket or Linux’s AF_PACKET socket, depending on your platform and needs.
  • Capture and replay traffic. Stream packets from an interface, apply filters, and replay saved captures with configurable timing.

Capabilities

Packet construction and dissection

Construct packets by stacking protocol layers with /, serialize them to wire-format bytes, and inspect incoming bytes with DetectLayer. Packet objects expose their layers and fields for further analysis or processing.

Protocol coverage

LightPacket supports common Layer 2, Layer 3, and Layer 4 protocols, including Ethernet II, VLAN and QinQ, ARP, LLC, STP, PPP, PPPoE, EAPOL, Linux cooked capture, IPv4, IPv6, TCP, and UDP. IEEE 802.11 layers are available for working with Wi-Fi frames.

Filtering

LightBPF includes a pure-Python lexer, parser, compiler, disassembler, and virtual machine for classic Berkeley Packet Filter expressions. Filters can be compiled and evaluated offline, or attached to supported Linux sockets using SO_ATTACH_FILTER.

Live capture and sockets

The high-level Sniffer supports streaming, callbacks, packet limits, timeouts, and filtering. For sending and receiving Layer 2 frames, LightPacket offers a libpcap/Npcap-backed L2Socket and a Linux-specific AF_PACKET implementation called L2Packet.

Live capture has platform-specific system requirements. On Linux, raw packet access may require elevated privileges; on Windows, Npcap is required for the libpcap-compatible backend. See Installation.

Capture files and replay

The pure-Python capture-file modules support classic PCAP and PCAPNG reading and writing. The replay utility can send packets from PCAP, PCAPNG, and LBN files through a socket, with options for pacing, loops, and jitter.

Installation

LightPacket supports Python 3.8 and later.

Install from PyPI

pip install lightpacket

Install from source

git clone https://github.com/Light-Projects/LightPacket.git
cd LightPacket
pip install .

Live-capture prerequisites

Capture-file reading and writing are implemented in pure Python and do not require libpcap. Live capture uses native platform facilities:

  • Linux: The libpcap-backed socket requires libpcap. The Linux L2Packet backend uses AF_PACKET. Raw socket operations may require root or appropriate capabilities.
  • macOS: Install libpcap, for example with brew install libpcap.
  • Windows: Install Npcap and select WinPcap API-compatible mode.

Quick start

Create a packet by stacking layers, then serialize it to bytes:

from LightPacket.l2 import Ethernet
from LightPacket.l3 import IPv4, TCP
from LightPacket.Raw import Raw

packet = (
    Ethernet(dst="aa:bb:cc:dd:ee:ff")
    / IPv4(dst="192.168.1.1")
    / TCP(dport=80, flags=0x02)
    / Raw(b"example payload")
)

wire_bytes = packet.build()
print(f"Built {len(wire_bytes)} bytes")

This example constructs a packet; sending raw traffic requires a suitable socket, interface, and permissions.

Documentation

The README introduces the project rather than documenting every class and field. See the following guides for detailed usage:

  • LightBPF guide — filter syntax, compilation, disassembly, and execution.
  • API reference — package modules and protocol definitions.

Project status

LightPacket is an open-source project. The repository README identifies version 1.0.3 .

The project’s capabilities and platform support continue to evolve. Check the documentation and issue tracker before relying on a particular protocol layer or live-capture backend in a production environment.

Contributing

Bug reports, feature requests, and contributions are welcome. Please open an issue or pull request in the LightPacket repository.

License

LightPacket is released under the Mozilla Public License 2.0.

Author

Adam Boulaaz — GitHub

Metadata

Release files for LightPacket 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for LightPacket 1.0.3
File Size Uploaded Provenance Actions
lightpacket-1.0.3.tar.gz 623.8 kB Without provenance Details for lightpacket-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for LightPacket 1.0.3
File Interpreter ABI Platform Actions
lightpacket-1.0.3-py3-none-any.whl Python 3 none any Details for lightpacket-1.0.3-py3-none-any.whl

Total release size: 1.3 MB

Release files / lightpacket-1.0.3.tar.gz

Download URL lightpacket-1.0.3.tar.gz
Size 623.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5119094757d7bc22ad40871070f09d202a339f8aa92b77a9f148943b56be57d4
BLAKE2b-256 checksum
How to use checksums
daa74d7adda6ddffd42eaf8f709af4b2616c4b4bbd5881b997a95ff85ac50b10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / lightpacket-1.0.3-py3-none-any.whl

Download URL lightpacket-1.0.3-py3-none-any.whl
Size 703.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa8342f46af32611f826123a1088d29ef4d4322e2faa443375b0995f5a785370
BLAKE2b-256 checksum
How to use checksums
1e119aefc4ceb50de71e53d0309426a5250c836377bb50130de04338e0a3ee09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for LightPacket 1.0.3

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.

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