Packet generation allows us to create artificial traffic that machines will treat as real. Applications of creating traffic include fuzzing, security auditing, bug reproduction, and throughput testing. Fuzzing will focus on the creation of packets that test boundary conditions while the latter three require sending packets out of your network interface. Which tool you use will largely depend on your use case.
If you want to use a programming language to script packets, there are resources in Packetcraft.
Test protocol dissectors or software with malformed packets.
Let somebody else build the packet generator