{"id":10133,"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.","status":"active","version":"1.4.3","language":"en","source_language":"en","source_url":"https://github.com/lextudio/pysmi","tags":["SNMP","MIB","SMI","network","parser","pyasn1"],"install":[{"cmd":"pip install pysmi-lextudio","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required runtime environment","package":"Python","version":">=3.8, <4.0"}],"imports":[{"symbol":"SmiStarParser","correct":"from pysmi.parser import SmiStarParser"},{"symbol":"SmiBuilder","correct":"from pysmi.builder import SmiBuilder"},{"symbol":"PySnmpCodeGen","correct":"from pysmi.codegen import PySnmpCodeGen"},{"symbol":"FileReader","correct":"from pysmi.reader import FileReader"}],"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."},"warnings":[{"fix":"Refer to the `pysmi-lextudio` 1.x documentation and examples for updated API usage, particularly around `SmiStarParser`, `SmiBuilder`, and `CodeGen` classes.","message":"Users upgrading from `pysmi` 0.x to 1.x (or `pysmi-lextudio` 1.x) will encounter significant API changes due to a complete refactoring. Code written for 0.x versions is incompatible with 1.x.","severity":"breaking","affected_versions":"<1.0.0"},{"fix":"Ensure all necessary MIB files, including standard RFCs, are present in the directories added via `mibBuilder.addMibSources(FileReader('/path/to/mib/directory'))`.","message":"PySMI requires all dependent MIB modules to be available in the provided MIB sources. If a MIB imports symbols from another MIB not found in the search paths, a `SmiError: MIB module '...' not found` will be raised. This includes common base MIBs like `SNMPv2-SMI` or `RFC1213-MIB`.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Verify your installation command is `pip install pysmi-lextudio`. If you encounter issues, uninstall `pysmi` if present (`pip uninstall pysmi`) and then install `pysmi-lextudio`.","message":"There is an older, unmaintained `pysmi` package on PyPI. Always use `pysmi-lextudio` for the actively developed and supported version. Installing the wrong package will result in `ModuleNotFoundError` or outdated functionality.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure you have installed the correct package: `pip install pysmi-lextudio`. If you previously installed `pysmi`, uninstall it first: `pip uninstall pysmi`.","cause":"The `pysmi-lextudio` package was not installed, or an outdated `pysmi` package (the old one) was installed, leading to incorrect import paths.","error":"ModuleNotFoundError: No module named 'pysmi'"},{"fix":"Add the directory containing `SOME-DEPENDENT-MIB.mib` (and any other dependencies) to your MIB builder's sources using `mibBuilder.addMibSources(FileReader('/path/to/mib/directory'))`.","cause":"The parser could not locate a required MIB module that the MIB being processed imports from. This usually means the dependent MIB file is missing from the configured search paths.","error":"pysmi.error.SmiError: MIB module \"SOME-DEPENDENT-MIB\" not found"},{"fix":"When adding `FileReader` sources, specify the correct encoding if known: `FileReader('/path/to/mib/directory', encoding='iso-8859-1')` (replace `iso-8859-1` with the actual encoding if different).","cause":"A MIB file is not encoded in UTF-8, but PySMI attempts to read it as such by default, leading to a decoding failure.","error":"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte"}]}