Skip to main content

The openvswitch package provides the official Python language bindings for Open vSwitch. They are developed in-tree as part of the Open vSwitch Package.

Installation

You can install the package using pip:

$ pip install ovs

The package include an optional flow parsing library. To use this package, you must install its required dependencies. The flow extra is provided for this purpose:

$ pip install ovs[flow]

Examples

Inspecting the database schema

The OVSDB schema is described in a JSON file, typically called vswitch.ovsschema. It can be inspected via schema provided locally on the host or remotely via the JSON-RPC API. For example, to view it from the local file:

import json
import ovs.dirs

schema_path = f'{ovs.dirs.PKGDATADIR}/vswitch.ovsschema'

with open(schema_path) as fh:
    schema = json.load(fh)

print(schema)

To do the same via the JSON-RPC, using TCP:

import json
import sys
import ovs.jsonrpc

remote = 'tcp:127.0.0.1:6640'

error, stream = ovs.stream.Stream.open_block(ovs.stream.Stream.open(remote))
if error:
    print(error)
    sys.exit(1)

rpc = ovs.jsonrpc.Connection(stream)
request = ovs.jsonrpc.Message.create_request('get_schema', ['Open_vSwitch'])
error, reply = rpc.transact_block(request)
rpc.close()
if error:
    print(error)
    sys.exit(1)

schema = reply.result
print(schema)

Dumping tables, ports and interfaces

The Open vSwitch Database (OVSDB) Interface Definition Language (IDL) maintains an in-memory replica of a database. It issues RPC requests to an OVSDB database server and parses the responses, converting raw JSON into data structures that are easier for clients to digest. You can use the IDL for database transactions along with simpler operations such as dumping information about the schema. The Python implementation of the OVSDB IDL is provided in ovs.db.idl via the Idl class. To initialise this, you need a schema helper and a “remote” or interface through which to communicate with the OVSDB. We can re-use and build upon the schema example from above to create an instance of ovs.db.idl.SchemaHelper. Once done, you can create an instance of ovs.db.idl.IDL and use this to iterate over the bridges, ports and interfaces available:

import ovs.db.idl
import ovs.dirs

# Create the schema helper.
schema_path = f'{ovs.dirs.PKGDATADIR}/vswitch.ovsschema'
schema_helper = ovs.db.idl.SchemaHelper(schema_path)
schema_helper.register_all()  # Register all tables for monitoring.

# Connect over TCP.
remote = 'tcp:127.0.0.1:6640'

idl = ovs.db.idl.Idl(remote, schema_helper)

# Wait until we have all information retrieved from the database.
while not idl.has_ever_connected():
    poller = ovs.poller.Poller()
    idl.wait(poller)
    poller.block()
    idl.run()

# Print bridges, ports and interfaces, à la 'ovs-vsctl show'.
for bridge in idl.tables['Bridge'].rows.values():
    print(f'Bridge {bridge.name}')
    for port in bridge.ports:
        print(f'\tPort {port.name}')
        for interface in port.interfaces:
            print(f'\t\tInterface {interface.name}')
            print(f'\t\t\ttype: {interface.type}')

Documentation

Documentation is included in the Python source. To view this, you can install the package and use pydoc. For example:

$ python -m pydoc ovs

Alternatively, you can use the help function from the Python REPL:

>>> import ovs
>>> help(ovs)

Release files for ovs 4.0.0

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

Source distribution (sdist)

Source distribution for ovs 4.0.0
File Size Uploaded
ovs-4.0.0.tar.gz 155.1 kB Details

Release files / ovs-4.0.0.tar.gz

Download URL ovs-4.0.0.tar.gz
Size 155.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c5fcb3f59383bf055368df6739db9f38c61c94c24086b7936a6b78668b9693cf
BLAKE2b-256 checksum
How to use checksums
dd45145eefde089bb3e9e7211e4705053f2e572c73255e059a9c7180f1fd73ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.6

Release history Release notifications | RSS feed

This release

4.0.0 This release

1 release file

3.7.1

1 release file

3.7.0

1 release file

3.6.3

1 release file

3.6.2

1 release file

3.6.1

1 release file

3.6.0

1 release file

3.5.4

1 release file

3.5.3

1 release file

3.5.2

1 release file

3.5.1

1 release file

3.5.0

1 release file

3.4.6

1 release file

3.4.5

1 release file

3.4.4

1 release file

3.4.3

1 release file

3.4.2

1 release file

3.4.1

1 release file

3.4.0

1 release file

3.3.9

1 release file

3.3.8

1 release file

3.3.7

1 release file

3.3.6

1 release file

3.3.5

1 release file

3.3.4

1 release file

3.3.3

1 release file

3.3.2

1 release file

3.3.1

1 release file

3.3.0

1 release file

3.2.6

1 release file

3.2.5

1 release file

3.2.4

1 release file

3.2.3

1 release file

3.2.2

1 release file

3.1.7

1 release file

3.1.6

1 release file

3.1.5

1 release file

3.1.4

1 release file

3.1.2

1 release file

3.0.8

1 release file

3.0.7

1 release file

3.0.6

1 release file

3.0.4

1 release file

3.0.0

1 release file

2.17.12

1 release file

2.17.11

1 release file

2.17.9

1 release file

2.17.7

1 release file

2.17.1

3 release files

2.16.0

1 release file

2.15.1

1 release file

2.14.2

1 release file

2.13.3

1 release file

2.13.0

1 release file

2.12.0

1 release file

2.11.8

1 release file

2.11.2

1 release file

2.11.0

1 release file

2.10.0

1 release file

2.9.4

1 release file

2.9.2

1 release file

2.9.0

1 release file

2.8.2

1 release file

2.8.1

1 release file

2.8.0

1 release file

2.7.2

1 release file

2.7.0

1 release file

2.6.1

1 release file

2.6.0

1 release file

2.5.0

1 release file

2.4.0

1 release file

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