Skip to content
Python API for Linux Traffic Control
Branch: master
Clone or download
Latest commit 7fa5512 Mar 18, 2013
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc doc: figure describing attribute structure of filter with redir action May 23, 2011
examples Add jitter support Mar 18, 2013
LICENCE ShaPy is released under MIT licence. Sep 14, 2011
README.markdown shapy VERSION May 24, 2011


ShaPy can be used to easily create an emulated network. ShaPy consists from two main parts: ShaPy Framework and ShaPy Emulation. ShaPy Framework allows accessing traffic control capabilities of the Linux kernel using the Netlink interface. ShaPy Emulation builds on the framework and focuses on building emulated network.


Standard distutils installation is supported. Since ShaPy is also in PyPI you can use:

pip install shapy

or if you prefer development version from the repo:

pip install -e git://

or download/clone and install the package manually:

python install


ShaPy Emulation

The following snippet gives you a virtual network of three IP addresses with exactly the declared speeds and delays.

from shapy.emulation.shaper import Shaper

ps = {("",) : {'upload': 1024, 'download': 1024, 'delay': 56},
      ("",) : {'upload': 256, 'download': 512, 'delay': 30},
      ("",) : {'upload': 256, 'download': 512, 'delay': 30},

sh = Shaper()

ShaPy Framework

The following snippet is an example of ShaPy Framework. It creates a HTB qdisc as a root qdisc on interface lo, creates a HTB class with maximum throughput 500 kbit (units are set in settings, see below) and a filter that will redirect all traffic with source IP to the HTB class to be shaped.

lo = Interface('lo')
h1 = HTBQdisc('1:', default_class='1ff')
h1.add( FlowFilter('src', '1:1', prio=2) )
h1.add( HTBClass('1:1', rate=500, ceil=500) )
lo.add( h1 )

ShaPy Settings

Shapy framework provides a simple facility for managing settings. User creates a regular Python file accessible as a module. In his main program he subsequently registers this module as shown below. The module name is not important but the convention is to call it The custom settings file can override or add values specified in the default ShaPy settings module shapy.framework.settings.default.

import shapy

Settings file for ShaPy Emulation might look like this:

COMMANDS = 'shapy.emulation.commands'
UNITS = 'kbit'

### CWC settings ###

# it's advisable to set MTU of the interfaces to something real, for example 1500

# ports excluded from shaping and delaying (holds for in and out)
# usually used for control ports
You can’t perform that action at this time.