peeringdb

PeeringDB module.

exception spicerack.peeringdb.CacheMiss[source]

Bases: SpicerackError

Custom exception class for cache management.

exception spicerack.peeringdb.PeeringDBError[source]

Bases: SpicerackError

Custom exception class for errors of the PeeringDB class.

class spicerack.peeringdb.PeeringDB(*, ttl: int = 86400, cachedir: pathlib.Path | None = None, proxies: collections.abc.MutableMapping[str, str] | None = None, token: str = '')[source]

Bases: object

Basic dumb wrapper over the PeeringDB API.

Implements the beta/v0 PeeringDB API. Tries to be smart by:

  1. keeping a persistent keep-alived session for multiple requests

  2. operating a local filesystem cache, if so desired.

Initiliaze the module.

Parameters:
fetch(resource: str, resource_id: int | None = None, filters: dict | None = None) dict[source]

Get a PeeringDB resource.

Parameters:
  • resource (str) -- The PeeringDB resource requested.

  • resource_id (typing.Optional[int], default: None) -- Optional resource number.

  • filters (typing.Optional[dict], default: None) -- A dictionary of addtional filter parameters.

Return type:

dict

fetch_asn(asn: int) dict[source]

Fetch a specific asn data.

Parameters:

asn (int) -- The Autonomous system number.

Return type:

dict

baseurl: str = 'https://www.peeringdb.com/api/'

The PeeringDB base API URL.