Quick Start#

Once you decide to test out PySNMP library on your Linux/Windows/macOS system, you should start to prepare a test field folder and configure the Python environment.

Set Up Test Field Folder#

First, it is recommended that you use pyenv to manage different Python versions on this machine. If you are using Windows, you can use pyenv-win.

Next, we assume you are now on macOS/Linux, and the following commands initialize a folder for us,

$ cd ~
$ mkdir test-field
$ cd test-field
$ pyenv local 3.12
$ pip install pipenv
$ pipenv install pysnmp-lextudio
$ pipenv run pip list

Here we created a virtual environment using pipenv for this folder, and installed pysnmp-lextudio so that you can move on with the following sections.

The final command should print out the dependencies and you should be able to see pysnmp-lextudio version 5.0+ there.


If you haven’t installed Python 3.12 with pyenv, you should execute pyenv install 3.12.

To delete the virtual environment for this folder, you can use

$ pipenv --rm

It is common that you use another virtual environment tool, such as venv, poetry, or conda. Just make sure you use the equivalent commands to set up the virtual environment for testing.

It is highly recommended that you use a Python virtual environment, as it makes dependency management and troubleshooting much easier.

Fetch SNMP Variable#

Next, let’s write some test script and play with PySNMP manager side operations.

  1. Create a Python script in the test field folder, such as v1-get.py.

  2. Cut and paste the following contents below into this file,

    import asyncio
    from pysnmp.hlapi.asyncio.slim import Slim
    from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType
    async def run():
        with Slim(1) as slim:
            errorIndication, errorStatus, errorIndex, varBinds = await slim.get(
                ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)),
            if errorIndication:
            elif errorStatus:
                    "{} at {}".format(
                        errorIndex and varBinds[int(errorIndex) - 1][0] or "?",
                for varBind in varBinds:
                    print(" = ".join([x.prettyPrint() for x in varBind]))

    Download script.

  3. Execute this script. If everything works as it should you will get the following on your console:

    $ pipenv run python v1-get.py
    SNMPv2-MIB::sysDescr."0" = SunOS zeus.pysnmp.com 4.1.3_U1 1 sun4m

Here you can see SNMP v1 GET operation can be easily done with the Slim class. Other operations in SNMP v1 and v2c can be done in similar manner. To execute SNMP v3 operations, however, requires more complex code.

The test agent we use is hosted at demo.pysnmp.com.


Similarly we can perform agent side operations with PySNMP.

  1. Create a script file default-v1-trap.py.

  2. Cut and paste the following contents below into this file,

    import asyncio
    from pysnmp.hlapi.asyncio import *
    async def run():
        snmpEngine = SnmpEngine()
        errorIndication, errorStatus, errorIndex, varBinds = await sendNotification(
            CommunityData("public", mpModel=0),
            UdpTransportTarget(("demo.pysnmp.com", 162)),
                ("", ""),
                ("", OctetString("my system")),
        if errorIndication:

    Download script.

  3. Execute this script.

    $ pipenv run python default-v1-trap.py

Because this sends out an SNMP v1 TRAP message, we know that no response will be received.

The notification receiver the receives this message is hosted at demo.pysnmp.com.