Skip to main content

A clean, modern SMI/MIB compiler

Project description

trishul-smi

A clean, modern SNMP MIB compiler written in Python.

PyPI Python License: MIT GitHub Stars GitHub Forks GitHub Issues

trishul-smi fetches, parses, and compiles SNMP MIB definitions (SMIv1 and SMIv2) into structured JSON or pysnmp-compatible Python modules. It resolves transitive imports automatically, caches compiled modules on disk, and ships a CLI that works out-of-the-box with no SNMP toolchain required.


Features

  • Full import closure — resolves every transitive dependency automatically
  • Full OID resolution — all objects carry absolute numeric OID paths after compile
  • Two output formats — structured JSON and pysnmp-compatible Python
  • Atomic JSON modules + optional sidecars — each module JSON is usable on its own; manifest.json and oid_index.json are additive when enabled via CompilerConfig or the CLI flags --emit-manifest / --emit-oid-index
  • Versioned JSON IR metadata — module JSON and optional sidecars carry schema_version, producer_version, generated_by, and generated_at
  • Deterministic sidecars — optional manifest.json and oid_index.json describe the final emitted JSON file set, so overlapping alias inputs do not duplicate or self-poison bundle metadata
  • Real-world parser compatibility — wrapped inline comment continuations, SNMPv2-PDU compatibility forms, preserved-source SNMPv2-TC variants that import built-in ASN.1 symbols such as OCTET STRING and OBJECT IDENTIFIER, Juniper AGENT-CAPABILITIES clauses with ACCESS not-implemented, and vendor MIBs that use lowercase local type references now compile cleanly through the standard parser path
  • Tagged ASN.1 type support — explicit base MIBs such as SNMPv2-SMI compile correctly, including application-tagged types like IpAddress and Counter32
  • pysmi-parity pysnmp output — MibTableColumn detection, full TC subtypeSpec, setIndexNames, setOrganization, setRevisions, inline constraint wrappers
  • Reverse conversiontsmi convert FILE.py converts a compiled PySNMP module back to JSON
  • Directory compile modetsmi compile -d /path/to/mibs auto-discovers and compiles every MIB file
  • Concurrent fetching — parallel async HTTP with retry and timeout; parse waves stay deterministic on real MIB corpora
  • Pluggable readersFileReader, HttpReader, ZipReader, composable via ReaderChain
  • Disk cache — compiled modules cached with mtime-based TTL; atomic writes
  • Cycle detection — Kahn's algorithm with actionable error messages
  • SMIv1 + SMIv2 — separate Lark grammars, auto-detected per MIB

Installation

pip install trishul-smi

Requires Python ≥ 3.10.


Quick Start

# Compile from a local MIB directory
tsmi compile IF-MIB --mib-dir /usr/share/snmp/mibs

# Fetch from the internet and compile to JSON + pysnmp
tsmi compile IF-MIB IP-MIB -f json -f pysnmp --online -o ./out

# Emit optional bundle sidecars for downstream JSON consumers
tsmi compile IF-MIB --online --emit-manifest --emit-oid-index -o ./out

Python API:

import asyncio
from pathlib import Path
from trishul_smi.compiler import MibCompiler
from trishul_smi.config import CompilerConfig
from trishul_smi.reader import FileReader, HttpReader

async def main():
    config = CompilerConfig(output_dir=Path("./out"))
    compiler = MibCompiler(config).add_reader(FileReader("/usr/share/snmp/mibs"))
    # optionally add HTTP: async with HttpReader(*config.sources) as http: compiler.add_reader(http)
    results = await compiler.compile("IF-MIB", "IP-MIB")
    for r in results:
        print(r.name, r.status, r.output_paths)

asyncio.run(main())

Each emitted MODULE.json is a valid standalone artifact. For downstream bundle metadata, set emit_manifest=True and/or emit_oid_index=True on CompilerConfig, or use the CLI flags --emit-manifest and --emit-oid-index. When enabled, sidecars describe the final emitted JSON file set for that compile run.


Documentation

Repository


License

MIT — see LICENSE.

Project details


Download files

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

Source Distribution

trishul_smi-0.4.4.tar.gz (125.3 kB view details)

Uploaded Source

Built Distribution

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

trishul_smi-0.4.4-py3-none-any.whl (66.4 kB view details)

Uploaded Python 3

File details

Details for the file trishul_smi-0.4.4.tar.gz.

File metadata

  • Download URL: trishul_smi-0.4.4.tar.gz
  • Upload date:
  • Size: 125.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trishul_smi-0.4.4.tar.gz
Algorithm Hash digest
SHA256 43188d77909d042a3946c2b1497a6af884d0988f170c8f3ab545a4fba93ee7a7
MD5 80425b85215319bec44682b3f019e23b
BLAKE2b-256 8a4289078a87646b08552ff3354cf4dabf39d1d6e0d69651e36dbaeb196db72c

See more details on using hashes here.

Provenance

The following attestation bundles were made for trishul_smi-0.4.4.tar.gz:

Publisher: release.yml on tosumitdhaka/trishul-smi

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

File details

Details for the file trishul_smi-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: trishul_smi-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 66.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for trishul_smi-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2faba02e9ceea97d3613a62c1f1b477ce3183b61f80e09d126a9c2464ad07d68
MD5 2e8b05245e7102fdfd9907ddc909582f
BLAKE2b-256 b349e4f0fd1a016c5d6d72cb2ce66df5c050c6ab54ef6a216c0d0ce9ec3a4713

See more details on using hashes here.

Provenance

The following attestation bundles were made for trishul_smi-0.4.4-py3-none-any.whl:

Publisher: release.yml on tosumitdhaka/trishul-smi

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page