Skip to main content

Python wrapper for Netdot Web API.

Project description

A python wrapper for UO-NetDot's RESTful API.

⚠ Disclaimer: From 0.2.0 onward, this API wrapper does not ensure support for the de facto Open Source version of NetDot (GitHub).

PyPI version

Install

This package is deployed to pypi.org. Download it with pip:

pip install netdot

Interactive Usage (Python interpreter)

ℹ Many methods of netdot.Repository and netdot.dataclasses are actually runtime-generated code. So, using the Repository interactively at the interpreter allows using features like tab completion and 'help()' to learn more.

Before getting into building a massive integration/tool, you might jump in and get some experience. Thankfully, we have the Python interpreter where we can jump in and do some testing!

# Enter the Python interpreter by running just "python" in your shell
$ python
Python 3.6.15 (default, Sep 10 2021, 00:26:58) 
... omitted for brevity...
>>> import netdot
>>>

ℹ The Python interpreter is often referred to as 'a REPL' (Read-Eval-Print-Loop). If you are unfamiliar with the Python interpreter, aka 'REPL', you might want to get started by reading "Using the REPL (in VSCode)" documentation.

With the netdot package imported, you can proceed with setting up a connecting and downloading some data!

Connecting in the interpreter

We have enabled interpreter-usage as a first-class feature. In particular, you will want to use the connect function like the following.

netdot.connect() returns a netdot.Repository instance.

>>> import netdot
>>> repo = netdot.connect()
What is the URL of the NetDot server? [https://nsdb.uoregon.edu]: ('enter' to use default)
NetDot username: myusername
NetDot password: ********** (using getpass module, to securely collect password)

That repo can be used for some interactive viewing of NetDot's data.

Example: Lookup IP Address in interpreter

As an example, you can use this API to lookup an IP Address.

>>> ipaddr = repo.get_ipblock_by_address('128.223.61.69')

Lets assume we want to determine who all may depend on this IP Address. We'll see if we can discover useful information from the used_by field of this IP Address, or its Subnet...

>>> ipaddr.used_by
None
>>> subnet = ipaddr.get_parent()
>>> subnet.used_by
'Network & Telecom Services'
>>> ip_container = subnet.get_parent()
>>> ip_container.used_by
'University of Oregon (3582)'

This demonstrates programatic read-access to the Address Space in NetDot.

ℹ Similar to get_parent, you'll notice you can get_children if you would like to!

Appendix: Using help() in interpreter

When in the interpreter session, it can be very useful to run help(netdot.Repository) to learn more about the Repository's capabilities.

ℹ If you've already established a connection via repo = netdot.connect(), then you can run help(repo) instead!

>>> help(netdot.Repository)
class Repository(builtins.object)
|  Work with Netdot API using Python objects.
|  
|  Methods defined here:
|  
|  __init__(self, netdot_url, user, password, parallelization_factor=11, **kwargs)
|      Initialize self.  See help(type(self)) for accurate signature.
|  
|  get_asset(repo:netdot_sites_manager.netdot.repository.Repository, id:int) -> ~T
|      Get info about a Asset from Netdot.
|      
|      Args: ... trimmed for brevity...

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

netdot-0.2.0.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

netdot-0.2.0-py2.py3-none-any.whl (29.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file netdot-0.2.0.tar.gz.

File metadata

  • Download URL: netdot-0.2.0.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

File hashes

Hashes for netdot-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8efe73deca09226bfd3873c4d928cff9f7ce4c3b3bae18e9d16c614454c71132
MD5 3c9f47e11bd835de3badb31ba880165e
BLAKE2b-256 aa02551d2c80138b0458a5c5da2fccbfb4131fe408912a0386ff0337bd96633a

See more details on using hashes here.

File details

Details for the file netdot-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: netdot-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 29.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

File hashes

Hashes for netdot-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c111199ae8986ec08dffac4bc3f54b21a74992253d94c39957eaa4bfd4c9826f
MD5 7efd248b58d2e50e84a5d1c66ed51d05
BLAKE2b-256 4d2b29400e83d3658613486f3b098a59ea0499ee5662a3605e6aaf050c7b03e8

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