How exhuma/puresnmp works
Project Type & Purpose
• puresnmp is a pure Python library that implements SNMP (Simple Network Management Protocol) without relying on external dependencies like MIBs or libsnmp.
• Its purpose is to provide a simple, dependency-free API for interacting with SNMP. The focus is on defining protocol operations (like PDU handling, transports, and API calls) and offering extensibility via plugins for various authentication, privacy, and message processing models.
Analyzing the File Structure
• The core of the project is found in the “src/puresnmp” directory. Here you see a modular design with files split into logical areas:
• Core components (e.g., adt.py, const.py, pdu.py, varbind.py) which define the basic SNMP data types and protocol data units.
• API layers found in “src/puresnmp/api” which separate “pythonic” and “raw” interfaces. This shows that the library provides both a high-level and a low-level approach.
• Modules for supporting different aspects of SNMP like “transport.py”, “util.py”, “credentials.py”, and “compatibility.py”.
• There is also a “plugins” structure:
• “src/puresnmp/plugins” contains core plugin interface definitions (such as auth, mpm, priv, security) that extend the functionality.
• “src/puresnmp_plugins” provides concrete implementations for the plugin interfaces supporting various versions and algorithms (e.g., MD5, SHA1 for auth, and multiple implementations for mpm and security).
• Additional directories include:
• “tests”, with various test cases and sample SNMP messages to verify the implementation.
• “doc”, which contains documentation source files – including a design document that might have additional architecture insights.
• “.devcontainer” which includes Dockerfiles and scripts to set up a development environment and a tiny SNMP daemon used for integration testing.
• Configuration files for pre-commit, CI (GitHub workflows, GitLab CI), type checking (mypy.ini) and packaging (pyproject.toml).
a. Core Library Architecture:
• Core SNMP engine:
• Data Representation & Types: Files like types.py, const.py, and typevars.py.
• PDU Management: pdu.py, varbind.py, and related modules.
• Utility Functions: util.py.
• The API Layer:
• Pythonic high-level API (src/puresnmp/api/pythonic.py)
• Raw API for lower-level operations (src/puresnmp/api/raw.py)
• Transport & Communication:
• transport.py which handles the protocol transport.
b. Plugin Infrastructure:
• Central Plugin Interfaces (in src/puresnmp/plugins) and the separation of responsibilities among:
• Authentication (auth.py)
• Message Processing Models (mpm)
• Privacy (priv.py)
• Security (security.py)
• Concrete Plugin Implementations (in src/puresnmp_plugins/*) for various SNMP versions and cryptographic methods.
c. Development & Testing Environment:
• The Docker-based development container (.devcontainer) that encapsulates the build environment.
• The embedded SNMP daemon configuration within .devcontainer/snmpd as an external component used for testing.
d. Auxiliary Components:
• The documentation module (doc/) that explains design choices.
• The tests directory depicting extensive unit and integration testing.
• CI/CD integration containers (GitHub workflows in .github/workflows and GitLab CI YAML file).
Architectural Relationships & Interactions
• The core components (PDU handling, type management, transport) are the backbone that the API layers call to build and parse SNMP messages.
• The plugin architecture is an injection point where internal choices (authentication, security, privacy) are abstracted so that specific implementations (in puresnmp_plugins) can be swapped or extended.
• Development container as an encapsulated environment that hosts a tiny SNMP daemon service, used to simulate real SNMP interactions when running tests or during development.