Registry / serialization / pysmi-lextudio

pysmi-lextudio

JSON →
library1.4.3pypypi✓ verified 88d ago

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.

pip install pysmi-lextudio
INSTALL
IMPORT
SIG · PYSMI-LEXTUDIO
P
pysmi-lextudio
serializationpythonv1.4.3
Install
2.4s avg
Import
56ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.4.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.058s · 23.5MB
glibc
py 3.10–3.910 runs
installs and imports cleanly · install 2.4s · import 0.054s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SmiStarParser
✓ from pysmi.parser import SmiStarParser
SmiBuilder
✓ from pysmi.builder import SmiBuilder
PySnmpCodeGen
✓ from pysmi.codegen import PySnmpCodeGen
FileReader
✓ from pysmi.reader import FileReader

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.

import os import tempfile from pysmi.builder import SmiBuilder from pysmi.reader import FileReader mib_content = """ DUMMY-MIB DEFINITIONS ::= BEGIN IMPORTS MODULE-IDENTITY, OBJECT-TYPE, enterprises FROM SNMPv2-SMI; dummyMIB MODULE-IDENTITY LAST-UPDATED "202310260000Z" ORGANIZATION "Example" CONTACT-INFO "example@example.com" DESCRIPTION "A dummy MIB for testing purposes." REVISION "202310260000Z" DESCRIPTION "Initial revision." ::= { enterprises 99999 } dummyObject OBJECT-TYPE SYNTAX INTEGER MAX-ACCESS read-only STATUS current DESCRIPTION "A dummy object." ::= { dummyMIB 1 } END """ with tempfile.TemporaryDirectory() as temp_dir: mib_path = os.path.join(temp_dir, "DUMMY-MIB.mib") # PySMI often needs standard MIBs; for simplicity, we mock an empty SNMPv2-SMI # In a real scenario, you'd point to a directory with actual standard MIBs snmpv2_smi_path = os.path.join(temp_dir, "SNMPv2-SMI.mib") with open(snmpv2_smi_path, "w") as f: f.write("SNMPv2-SMI DEFINITIONS ::= BEGIN END") with open(mib_path, "w") as f: f.write(mib_content) mibBuilder = SmiBuilder() mibBuilder.addMibSources(FileReader(temp_dir)) try: mibBuilder.loadModules("DUMMY-MIB") # Retrieve the MIB node by name or OID to verify if mibBuilder.getMibNode(('DUMMY-MIB', 1)): print("Successfully loaded 'DUMMY-MIB' and found 'dummyObject'.") else: print("Failed to find 'dummyObject' within 'DUMMY-MIB'.") except Exception as e: print(f"Error loading MIB: {e}")
Debug
Known issues
breakingUsers 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.
fix
Refer to the `pysmi-lextudio` 1.x documentation and examples for updated API usage, particularly around `SmiStarParser`, `SmiBuilder`, and `CodeGen` classes.
affects: <1.0.0
gotchaPySMI 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`.
fix
Ensure all necessary MIB files, including standard RFCs, are present in the directories added via `mibBuilder.addMibSources(FileReader('/path/to/mib/directory'))`.
affects: >=1.0.0
gotchaThere 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.
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`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pysmi'
The `pysmi-lextudio` package was not installed, or an outdated `pysmi` package (the old one) was installed, leading to incorrect import paths.
fix
Ensure you have installed the correct package: `pip install pysmi-lextudio`. If you previously installed `pysmi`, uninstall it first: `pip uninstall pysmi`.
pysmi.error.SmiError: MIB module "SOME-DEPENDENT-MIB" not found
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.
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'))`.
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x... in position ...: invalid start byte
A MIB file is not encoded in UTF-8, but PySMI attempts to read it as such by default, leading to a decoding failure.
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).
Upgrade
Version history
1.4.3latest on PyPI · released Apr 3, 2024
Audit
Dependencies
PythonrequiredRequired runtime environment
Agent activity
16 hits · last 30 days
node
14
OpenAI (training)
1
Resources
pysmi-lextudio — pip install pysmi-lextudio · libregistry