Difference between revisions of "VPP/Python API"

From fd.io
< VPP
Jump to: navigation, search
Line 4: Line 4:
 
The vpp-papi.py module in vpp-api-test/papi provides a Python 3 binding to the VPP API.
 
The vpp-papi.py module in vpp-api-test/papi provides a Python 3 binding to the VPP API.
  
 +
=== Example ===
 +
<nowiki>
 +
#!/usr/bin/env python3
 +
 +
import vpp_papi
 +
r = vpp_papi.connect("test_papi")
 +
 +
t = vpp_papi.show_version()
 +
print('VPP version:', t.version.decode())
 +
 +
t = vpp_papi.sw_interface_dump(0, b'ignored')
 +
 +
if t:
 +
    print('List of interfaces')
 +
    for interface in t:
 +
        if interface.vlmsgid == vpp_papi.VL_API_SW_INTERFACE_DETAILS:
 +
            print(interface.interfacename.decode())
 +
r = vpp_papi.disconnect()
 +
</nowiki>
 +
 +
=== API generation ===
 
The Python binding is automatically generated from the API definition in vpp/api/vpe.api. See figure below.
 
The Python binding is automatically generated from the API definition in vpp/api/vpe.api. See figure below.
  
 
[[File:papi.png|600px]]
 
[[File:papi.png|600px]]

Revision as of 10:28, 30 March 2016

Python binding for the VPP API

The vpp-papi.py module in vpp-api-test/papi provides a Python 3 binding to the VPP API.

Example

#!/usr/bin/env python3

import vpp_papi
r = vpp_papi.connect("test_papi")

t = vpp_papi.show_version()
print('VPP version:', t.version.decode())

t = vpp_papi.sw_interface_dump(0, b'ignored')

if t:
    print('List of interfaces')
    for interface in t:
        if interface.vlmsgid == vpp_papi.VL_API_SW_INTERFACE_DETAILS:
            print(interface.interfacename.decode())
r = vpp_papi.disconnect()
 

API generation

The Python binding is automatically generated from the API definition in vpp/api/vpe.api. See figure below.

Papi.png