Skip to main content

gosnmp-traps-python

Project description

gosnmp-traps-python

This library binds our fork of gosnmp for use in Python3 using gopy.

Versions

All versions 1.0.0 and up support Python 3 only! If you need Python 2 support, check out the following:

Concept

In the early days gopy was fairly limited in it's ability to track object allocation across the border of Go and Python.

As a result, our implementation is fairly naive- we only pass primitive types from Go to Python (nothing that comes by reference).

Session are managed entirely on the Go side and identified with an integer- here are a few function signatures to demonstrate:

  • NewRPCSession(hostname string, port, timeout int, paramsJSON string) (uint64, error)
  • RPCConnect(sessionID uint64) error
  • RPCGetNoWait(sessionID uint64) (string, error)
  • RPCClose(sessionID uint64)

The functions that return complex data do so in a special JSON-based format- at this point gopy does it's magic and those functions are made available to Python.

We then have RPCSession abstraction on the Python side that pulls things together in a class for convenience (saving you need the to keep track of the identifiers and handling deserialisation).

Weird gotchas

We're building for Python3 and we use a python-config script for Python3 however we're using a python.pc file from Python2.

I dunno why this has to be this way, but it's the only way I can get the C Python API GIL lock/unlock calls to be available to Go (C.PyEval_SaveThread() and C.PyEval_RestoreThread(tState)).

So if you're wondering why Python2 still comes into it here and there- that's why. Doesn't seem to cause any problems.

Prerequisites

  • MacOS
  • CPython3.8+
  • virtualenv
    • pip install virtualenv
  • pkgconfig
    • brew install pkg-config
  • Docker

Install (from PyPI)

python -m pip install gosnmp-traps-python

Setup

virtualenv -p $(which python3) venv
source venv/bin/activate
./fix_venv.sh
pip install -r requirements-dev.txt

Build

source venv/bin/activate
./native_build.sh

If you're deep in the grind and want to iterate faster, you can invoke:

./native_build.sh fast

This skips the setup (assuming you've already done that).

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

gosnmp-traps-python-1.0.0.tar.gz (11.5 kB view details)

Uploaded Source

File details

Details for the file gosnmp-traps-python-1.0.0.tar.gz.

File metadata

  • Download URL: gosnmp-traps-python-1.0.0.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for gosnmp-traps-python-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ce197becbfd90d3e019c7ee8c47371e2784f67fa9e0d08edd9d28b8906781ea3
MD5 ae51b3b85251f6c11a525d362588c1fe
BLAKE2b-256 28d3b7691644ad04e023e5e6d14782c5ac9c4f3bb795797b297f8393b971649c

See more details on using hashes here.

Supported by

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