puresnmp.api.pythonic module
This module provides the high-level wrapper PyWrapper
around
puresnmp.api.raw.Client
.
Care is taken to make this as pythonic as possible and hide as many of the gory implementations as possible.
This module provides “syntactic sugar” around the lower-level, but almost
identical, module puresnmp.api.raw
.
While this “pythonic” API returns native Python types, the “raw” module
returns the variable types unmodified which are all subclasses of
x690.types.X690Type
.
>>> import asyncio
>>> from puresnmp import Client, V2C, PyWrapper
>>>
>>> async def example():
... client = PyWrapper(Client("192.0.2.1", V2C("public")))
... output = await client.get("1.3.6.1.2.1.1.1.0")
... return output
- class puresnmp.api.pythonic.PyWrapper(client: Client)
Bases:
object
A wrapper around a
puresnmp.api.raw.Client
instance.The wrapper ensures conversion of internal API data-types to and from Python-native types.
Using Python native types shields from internal changes internally in
puresnmp
at the cost of flexibility. Most applications should mostly benefit from this.In cases internal data-types are still wanted, one can access the
.client
attribute of PyWrapper instances which exposes the same API but with internally used data-types.- async bulkget(scalar_oids: List[str], repeating_oids: List[str], max_list_size: int = 10) BulkResult
Delegates to
puresnmp.api.raw.Client.bulkget()
but converts internal types to simple Python types.
- async bulktable(oid: str, bulk_size: int = 10, _rowtype: TTableRow = typing.Dict[str, typing.Any]) List[TTableRow]
Delegates to
puresnmp.api.raw.Client.bulktable()
but converts internal types to simple Python types.
- async bulkwalk(oids: List[str], bulk_size: int = 10) AsyncGenerator[PyVarBind, None]
Delegates to
puresnmp.api.raw.Client.bulkwalk()
but converts internal types to simple Python types.
- async get(oid: str) Any
Delegates to
puresnmp.api.raw.Client.get()
but converts internal types to simple Python types.
- async getnext(oid: str) PyVarBind
Delegates to
puresnmp.api.raw.Client.getnext()
but converts internal types to simple Python types.
- async multiget(oids: List[str]) List[Any]
Delegates to
puresnmp.api.raw.Client.multiget()
but converts internal types to simple Python types.
- async multiset(mappings: Dict[str, X690Type[Any]]) Dict[str, Any]
Delegates to
puresnmp.api.raw.Client.multiset()
but converts internal types to simple Python types.
- async multiwalk(oids: List[str]) AsyncGenerator[PyVarBind, None]
Delegates to
puresnmp.api.raw.Client.multiwalk()
but converts internal types to simple Python types.
- async set(oid: str, value: X690Type[Any]) Dict[str, Any]
Delegates to
puresnmp.api.raw.Client.set()
but converts internal types to simple Python types.
- async table(oid: str, _rowtype: TTableRow = typing.Dict[str, typing.Any]) List[Dict[str, Any]]
Delegates to
puresnmp.api.raw.Client.table()
but converts internal types to simple Python types.
- async walk(oid: str, errors: str = 'strict') AsyncGenerator[PyVarBind, None]
Delegates to
puresnmp.api.raw.Client.walk()
but converts internal types to simple Python types.
- class puresnmp.api.pythonic.TrapInfo(raw_trap: Trap)
Bases:
object
This class wraps a
puresnmp.pdu.Trap
instance (accessible viaraw_trap
and makes values available as “pythonic” values.- property origin: str
Accesses the IP-Address from which the trap was sent
May be the empty string if the source is unknown
- raw_trap: Trap
The raw Trap PDU.
Warning
This will leak data-types which are used internally by
puresnmp
and may change even in minor updates. You should, if possible use the values from the properties on this object. This exist mainly to expose values which can be helpful in debugging. If something is missing from the properties, please open a corresponding support ticket!
- property values
Returns all the values contained in this trap as dictionary mapping OIDs to values.