Metadata-Version: 2.1
Name: easiersnmp
Version: 0.2.0
Summary: easiersnmp is a wrapper around easysnmp to make it even easier to use
License: BSD 2-Clause License
Author: Markus Juenemann
Author-email: markus@juenemann.net
Requires-Python: >=3.7,<4.0
Classifier: License :: Other/Proprietary License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: easysnmp (>=0.2.6,<0.3.0)
Description-Content-Type: text/markdown

# easiersnmp

*easiersnmp* is a wrapper around [*easysnmp*](https://github.com/kamakazikamikaze/easysnmp) to make it even easier to use. 
It also includes an alternative implementation of [*easysnmptable*](https://github.com/wolcomm/easysnmptable).

## Python types

While I really like *easysnmp*, it returns instances of ``SNMPVariable`` instead of of the basic Python data types. 
In addition the actual value (``SNMPVariable.value``) will always be a string, even if the underlying SNMP type is numeric.

SNMP GET in *easysnmp*
```python
import easysnmp
session = easysnmp.Session(hostname='localhost', community='public', version=2)
result = session.get('ifIndex.1')

# result is an instance of easysnmp.SNMPVariable
print(result.oid, result.oid_index, result.snmp_type, result.value)
# ifIndex 1 INTEGER 1

# The result.value is a string even though the snmp_type is INTEGER
print(type(result.value)
# str
```

*easiersnmp* changes this behaviour by converting ``SNMPVariable.value`` into the correct data type.

SNMP GET in *easiersnmp*
```python
import easiersnmp
session = easiersnmp.Session(hostname='localhost', community='public', version=2)
result = session.get('ifIndex.1')

# result is an instance of easiersnmp.SNMPVariable
print(result.oid, result.oid_index, result.snmp_type, result.value)
# ifIndex 1 INTEGER 1

# The result.value is an integer matching the snmp_type
print(type(result.value)
# int
```

The table below shows how values are converted.

| ``SNMPVariable.snmp_type`` | Python type |
|---|---|
| ``INTEGER32`` | ``int`` |
| ``INTEGER`` | ``int`` |
| ``UNSIGNED32`` | ``int`` |
| ``GAUGE`` | ``int`` |
| ``IPADDR`` | ``ipaddress.IPv4Address``/``ipaddress.IPv6Address`` |
| ``OCTETSTR`` | (read note below) |
| ``TICKS`` | ``datetime.timedelta`` |
| ``OPAQUE`` | |
| ``OBJECTID`` | |
| ``NETADDR`` | ``ipaddress.IPv4Address``/``ipaddress.IPv6Address`` |
| ``COUNTER64`` | ``int`` |
| ``NULL`` | ``None`` |
| ``BITS`` | ``int`` |
| ``UINTEGER`` | ``int`` |

The ``OCTETSTR`` SNMP type is commonly used as a container for values that cannot be represented in any other
SNMP type. It is impossible to know the correct interpretation of an ``OCTETSTR`` without parsing the relevant
SNMP MIB. 

