Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

SNMP library for Python

PyPI Python Versions CI GitHub license

This is a pure-Python, open source and free implementation of v1/v2c/v3 SNMP engine distributed under 2-clause BSD license.

The PySNMP project was initially sponsored by a PSF grant. Thank you!

This version is a fork of Ilya Etingof deceased's project etingof/pysnmp. Ilya sadly passed away on 10-Aug-2022. Announcement here. His work is still of great use to the Python community and he will be missed.

Features

  • Complete SNMPv1/v2c and SNMPv3 support
  • SMI framework for resolving MIB information and implementing SMI Managed Objects
  • Complete SNMP entity implementation
  • USM Extended Security Options support (3DES, 192/256-bit AES encryption)
  • Extensible network transports framework (UDP/IPv4, UDP/IPv6)
  • Asyncio integration
  • PySMI integration for dynamic MIB compilation
  • Built-in instrumentation exposing protocol engine operations
  • 100% Python, supports Python 3.10 and later
  • MT-safe (if SnmpEngine is thread-local)

Features, specific to SNMPv3 model include:

  • USM authentication (MD5/SHA-1/SHA-2) and privacy (DES/AES) protocols (RFC3414, RFC7860)
  • View-based access control to use with any SNMP model (RFC3415)
  • Built-in SNMP proxy PDU converter for building multi-lingual SNMP entities (RFC2576)
  • Remote SNMP engine configuration
  • Optional SNMP engine discovery
  • Shipped with standard SNMP applications (RC3413)

Download & Install

The PySNMP software is freely available for download from PyPI and GitHub.

Just run:

$ pip install pysnmplib

That pulls in what an SNMP engine needs to run:

  • PyASN1
  • PyCryptodomex (required for SNMPv3 encryption; imported lazily, so SNMPv1, SNMPv2c and the SNMPv3 noAuthNoPriv/authNoPriv security levels work without it)

PySMI is not pulled in. It compiles ASN.1 MIB sources at run time, which some deployments do and most do not, so it is an extra:

$ pip install 'pysnmplib[compile]'

Without it everything except run-time MIB compilation works — including SNMPv3, name resolution and the standard MIBs an engine needs, which PySNMP ships. Asking for a MIB compiler when the extra is not installed raises SmiError naming the missing import.

Besides the library, command-line SNMP utilities written in pure-Python could be installed via:

$ pip install snmpclitools

and used in the very similar manner as conventional Net-SNMP tools:

$ snmpget.py -v3 -l authPriv -u usr-md5-des -A authkey1 -X privkey1 localhost sysDescr.0
SNMPv2-MIB::sysDescr.0 = STRING: Linux localhost 5.15.0

Examples

PySNMP is designed in a layered fashion. Top-level and easiest to use API is known as hlapi. Here's a quick example on how to SNMP GET:

from pysnmp.hlapi import *

iterator = getCmd(
    SnmpEngine(),
    CommunityData("public"),
    UdpTransportTarget(("localhost", 161)),
    ContextData(),
    ObjectType(ObjectIdentity("SNMPv2-MIB", "sysDescr", 0)),
)

errorIndication, errorStatus, errorIndex, varBinds = next(iterator)

if errorIndication:  # SNMP engine errors
    print(errorIndication)
else:
    if errorStatus:  # SNMP agent errors
        print(
            "%s at %s"
            % (
                errorStatus.prettyPrint(),
                varBinds[int(errorIndex) - 1] if errorIndex else "?",
            )
        )
    else:
        for varBind in varBinds:  # SNMP response contents
            print(" = ".join([x.prettyPrint() for x in varBind]))

This is how to send SNMP TRAP:

from pysnmp.hlapi import *

errorIndication, errorStatus, errorIndex, varBinds = next(
    sendNotification(
        SnmpEngine(OctetString(hexValue="8000000001020304")),
        UsmUserData(
            "usr-sha-aes128",
            "authkey1",
            "privkey1",
            authProtocol=usmHMACSHAAuthProtocol,
            privProtocol=usmAesCfb128Protocol,
        ),
        UdpTransportTarget(("localhost", 162)),
        ContextData(),
        "trap",
        NotificationType(ObjectIdentity("SNMPv2-MIB", "authenticationFailure")),
    )
)

if errorIndication:
    print(errorIndication)
$ python3 examples/hlapi/asyncio/manager/cmdgen/v1-get.py
SNMPv2-MIB::sysDescr.0 = Linux localhost 5.15.0
$
$ python3 examples/hlapi/asyncio/agent/ntforg/default-v1-trap.py
SNMPv2-MIB::sysUpTime.0 = 0
SNMPv2-MIB::snmpTrapOID.0 = SNMPv2-MIB::warmStart
SNMPv2-MIB::sysName.0 = system name

Other than that, PySNMP is capable to automatically fetch and use required MIBs from HTTP, FTP sites or local directories. You could configure any MIB source available to you (including this one) for that purpose.

For more example scripts please refer to the examples/ directory in this repository.

Documentation

Library documentation and examples can be found in the docs/ directory in this repository.

If something does not work as expected, please open an issue at GitHub or post your question on Stack Overflow.

Bug reports and PRs are appreciated! ;-)

Copyright (c) 2005-2019, Ilya Etingof deceased. All rights reserved.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysnmplib-6.0.0rc11.tar.gz (615.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysnmplib-6.0.0rc11-py3-none-any.whl (340.4 kB view details)

Uploaded Python 3

File details

Details for the file pysnmplib-6.0.0rc11.tar.gz.

File metadata

  • Download URL: pysnmplib-6.0.0rc11.tar.gz
  • Upload date:
  • Size: 615.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pysnmplib-6.0.0rc11.tar.gz
Algorithm Hash digest
SHA256 83d18d938f902513b38d8f4e37e583f74794e192652be5d69544abb2606d677e
MD5 2cd621043386b099520c0abdb7081027
BLAKE2b-256 00ea0ef27928a67fea6a57a5312d3c8a68f43b36a6d58d0de09dc3f559e2511e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysnmplib-6.0.0rc11.tar.gz:

Publisher: publish-to-pypi.yml on pysnmp/pysnmp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pysnmplib-6.0.0rc11-py3-none-any.whl.

File metadata

  • Download URL: pysnmplib-6.0.0rc11-py3-none-any.whl
  • Upload date:
  • Size: 340.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pysnmplib-6.0.0rc11-py3-none-any.whl
Algorithm Hash digest
SHA256 0c437c1a1755bc0ae6e98bc50524ea756a8c69bb7a6c79fcb28ec113b1bf6b26
MD5 2615b86cb204b0e75b1bd7aabf4de0cb
BLAKE2b-256 ee7990062898fe5ac58ec26290ca62acbe0861cd4ab9747a6ec6ad35ce3d11d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pysnmplib-6.0.0rc11-py3-none-any.whl:

Publisher: publish-to-pypi.yml on pysnmp/pysnmp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

6.0.0rc11 This release

2 files

5.0.24

2 files

5.0.23

2 files

5.0.22

2 files

5.0.21

2 files

5.0.20

2 files

5.0.19

2 files

5.0.18

2 files

5.0.17

2 files

5.0.16

2 files

5.0.15

2 files

5.0.10

2 files

5.0.9

2 files

5.0.8

2 files

5.0.7

2 files

5.0.6

2 files

5.0.5

2 files

5.0.4

2 files

5.0.3

2 files

5.0.2

2 files

5.0.1

2 files

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