or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication.mddata-types.mdhigh-level-api.mdindex.md
tile.json

tessl/pypi-pysnmp

A comprehensive Python SNMP library supporting v1/v2c/v3 with authentication and privacy protocols

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/pysnmp@7.1.x

To install, run

npx @tessl/cli install tessl/pypi-pysnmp@7.1.0

index.mddocs/

PySNMP

A comprehensive Pure Python SNMP library supporting SNMP v1, v2c, and v3 protocols with complete authentication and privacy capabilities. PySNMP provides both high-level and low-level APIs for building SNMP agents, managers, and network monitoring applications, with full compliance to IETF RFC standards.

Package Information

  • Package Name: pysnmp
  • Language: Python
  • Installation: pip install pysnmp
  • Version: 7.1.21
  • License: BSD-2-Clause

Core Imports

import pysnmp

For high-level async operations (recommended):

from pysnmp.hlapi.v3arch.asyncio import *

For legacy imports:

from pysnmp.hlapi.asyncio import *

For specific components:

from pysnmp.hlapi.v3arch.asyncio import (
    SnmpEngine, CommunityData, UsmUserData,
    UdpTransportTarget, ContextData,
    get_cmd, set_cmd, walk_cmd, is_end_of_mib
)

For data types and SMI objects:

from pysnmp.proto.rfc1902 import (
    Integer32, OctetString, ObjectIdentifier, Counter32, 
    Gauge32, TimeTicks, Counter64, Bits, IpAddress
)
from pysnmp.smi.rfc1902 import ObjectIdentity, ObjectType, NotificationType
from pysnmp.proto.rfc1905 import EndOfMibView, NoSuchObject, NoSuchInstance

Basic Usage

Simple SNMP GET Operation

import asyncio
from pysnmp.hlapi.v3arch.asyncio import *

async def snmp_get():
    errorIndication, errorStatus, errorIndex, varBinds = await get_cmd(
        SnmpEngine(),
        CommunityData('public'),
        await UdpTransportTarget.create(('demo.pysnmp.com', 161)),
        ContextData(),
        ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
    )
    
    if errorIndication:
        print(f"Error: {errorIndication}")
    elif errorStatus:
        print(f"Error: {errorStatus.prettyPrint()}")
    else:
        for varBind in varBinds:
            print(f"{varBind[0]} = {varBind[1]}")

# Run the async function
asyncio.run(snmp_get())

SNMPv3 with Authentication

import asyncio
from pysnmp.hlapi.v3arch.asyncio import *

async def snmpv3_get():
    errorIndication, errorStatus, errorIndex, varBinds = await get_cmd(
        SnmpEngine(),
        UsmUserData('testuser', 
                   authKey='authenticationkey',
                   authProtocol=USM_AUTH_HMAC96_SHA),
        await UdpTransportTarget.create(('demo.pysnmp.com', 161)),
        ContextData(),
        ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'))
    )
    
    if not errorIndication and not errorStatus:
        for varBind in varBinds:
            print(f"{varBind[0]} = {varBind[1]}")

asyncio.run(snmpv3_get())

SNMP Walk Operation

import asyncio
from pysnmp.hlapi.v3arch.asyncio import *

async def snmp_walk():
    async for (errorIndication, errorStatus, errorIndex, varBinds) in walk_cmd(
        SnmpEngine(),
        CommunityData('public'),
        await UdpTransportTarget.create(('demo.pysnmp.com', 161)),
        ContextData(),
        ObjectType(ObjectIdentity('1.3.6.1.2.1.1')),  # Walk system subtree
        lexicographicMode=False
    ):
        if errorIndication:
            print(f"Error: {errorIndication}")
            break
        elif errorStatus:
            print(f"Error: {errorStatus.prettyPrint()}")
            break
        else:
            for varBind in varBinds:
                print(f"{varBind[0]} = {varBind[1]}")

asyncio.run(snmp_walk())

Architecture

PySNMP is built around a layered architecture that provides flexibility from high-level convenience functions to low-level protocol control:

  • High-Level API (hlapi): User-friendly async/await interface for common SNMP operations
  • SNMP Engine: Central coordinator managing authentication, transport, and message processing
  • Protocol Layer: RFC-compliant implementation of SNMP v1/v2c/v3 protocols
  • Transport Layer: Network communication over UDP/IPv4 and IPv6
  • SMI Framework: Structure of Management Information for MIB object handling
  • Security: Complete USM (User-based Security Model) with authentication and privacy

The library supports both SNMPv3 architecture (recommended) and legacy v1 architecture, with full backward compatibility and seamless integration with asyncio for modern Python applications.

Capabilities

High-Level API Operations

The primary interface for SNMP operations, providing async functions for GET, SET, WALK, and notification operations with built-in error handling and transport management.

async def get_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def set_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def next_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def bulk_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def walk_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def bulk_walk_cmd(snmpEngine, authData, transportTarget, contextData, *varBinds, **options): ...
async def send_notification(snmpEngine, authData, transportTarget, contextData, notifyType, *varBinds, **options): ...
def is_end_of_mib(varBinds): ...

High-Level API Operations

Authentication and Security

Comprehensive authentication and privacy protocols for SNMP v1/v2c community strings and SNMPv3 User-based Security Model (USM) with multiple authentication and encryption algorithms.

class CommunityData: ...
class UsmUserData: ...

# Authentication Protocols  
USM_AUTH_NONE: int
USM_AUTH_HMAC96_MD5: int
USM_AUTH_HMAC96_SHA: int
USM_AUTH_HMAC128_SHA224: int
USM_AUTH_HMAC192_SHA256: int
USM_AUTH_HMAC256_SHA384: int
USM_AUTH_HMAC384_SHA512: int

# Privacy Protocols
USM_PRIV_NONE: int
USM_PRIV_CBC56_DES: int
USM_PRIV_CBC168_3DES: int
USM_PRIV_CFB128_AES: int
USM_PRIV_CFB192_AES: int
USM_PRIV_CFB256_AES: int
USM_PRIV_CFB192_AES_BLUMENTHAL: int
USM_PRIV_CFB256_AES_BLUMENTHAL: int

Authentication and Security

SNMP Data Types and Exceptions

Complete implementation of SNMP data types from RFC 1902 and RFC 1905, including integers, strings, object identifiers, counters, gauges, and specialized exception values.

class Integer32: ...
class OctetString: ...
class ObjectIdentifier: ...
class Counter32: ...
class Counter64: ...
class Gauge32: ...
class TimeTicks: ...
class IpAddress: ...
class Opaque: ...
class Bits: ...

# Exception Values
class NoSuchObject: ...
class NoSuchInstance: ...
class EndOfMibView: ...
class UnSpecified: ...

SNMP Data Types and Exceptions

Core Engine and Transport

SNMP engine management, transport targets for UDP/IPv4 and IPv6 communication, and context data for SNMP operations.

class SnmpEngine: ...
class UdpTransportTarget: ...
class Udp6TransportTarget: ...
class ContextData: ...

SMI Objects

Structure of Management Information objects for working with MIB variables, object identities, and SNMP notifications with automatic OID resolution.

class ObjectIdentity: ...
class ObjectType: ...
class NotificationType: ...