{"library":"pysmi-lextudio","title":"PySMI (lextudio)","description":"PySMI (lextudio) is a pure-Python library for parsing and converting SNMP/SMI MIB definitions. It provides tools to work with MIB files, resolve dependencies, and generate various output formats, including PySNMP-compatible Python modules. The current version is 1.4.3 and it maintains an active, though not rapid, release cadence.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install pysmi-lextudio"],"cli":null},"imports":["from pysmi.parser import SmiStarParser","from pysmi.builder import SmiBuilder","from pysmi.codegen import PySnmpCodeGen","from pysmi.reader import FileReader"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport tempfile\nfrom pysmi.builder import SmiBuilder\nfrom pysmi.reader import FileReader\n\nmib_content = \"\"\"\nDUMMY-MIB DEFINITIONS ::= BEGIN\n    IMPORTS\n        MODULE-IDENTITY, OBJECT-TYPE, enterprises\n            FROM SNMPv2-SMI;\n\n    dummyMIB MODULE-IDENTITY\n        LAST-UPDATED \"202310260000Z\"\n        ORGANIZATION \"Example\"\n        CONTACT-INFO \"example@example.com\"\n        DESCRIPTION\n            \"A dummy MIB for testing purposes.\"\n        REVISION \"202310260000Z\"\n        DESCRIPTION\n            \"Initial revision.\"\n        ::= { enterprises 99999 }\n\n    dummyObject OBJECT-TYPE\n        SYNTAX      INTEGER\n        MAX-ACCESS  read-only\n        STATUS      current\n        DESCRIPTION\n            \"A dummy object.\"\n        ::= { dummyMIB 1 }\n\nEND\n\"\"\"\n\nwith tempfile.TemporaryDirectory() as temp_dir:\n    mib_path = os.path.join(temp_dir, \"DUMMY-MIB.mib\")\n    # PySMI often needs standard MIBs; for simplicity, we mock an empty SNMPv2-SMI\n    # In a real scenario, you'd point to a directory with actual standard MIBs\n    snmpv2_smi_path = os.path.join(temp_dir, \"SNMPv2-SMI.mib\")\n    with open(snmpv2_smi_path, \"w\") as f:\n        f.write(\"SNMPv2-SMI DEFINITIONS ::= BEGIN END\")\n\n    with open(mib_path, \"w\") as f:\n        f.write(mib_content)\n\n    mibBuilder = SmiBuilder()\n    mibBuilder.addMibSources(FileReader(temp_dir))\n\n    try:\n        mibBuilder.loadModules(\"DUMMY-MIB\")\n        # Retrieve the MIB node by name or OID to verify\n        if mibBuilder.getMibNode(('DUMMY-MIB', 1)):\n            print(\"Successfully loaded 'DUMMY-MIB' and found 'dummyObject'.\")\n        else:\n            print(\"Failed to find 'dummyObject' within 'DUMMY-MIB'.\")\n    except Exception as e:\n        print(f\"Error loading MIB: {e}\")\n\n","lang":"python","description":"This quickstart demonstrates how to parse a simple MIB file using PySMI. It creates a temporary MIB file and a dummy 'SNMPv2-SMI' for basic dependency resolution, then uses `SmiBuilder` and `FileReader` to load and verify the MIB module.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}