aioipinfo package

Module contents

IPInfo CLient.

class aioipinfo.IPInfoClient(token: str)

Bases: object

A very simple client for the free ipinfo.io API.

Parameters

tokenstr

The ipinfo.io API token to use with requests.

async close()

Close the underlying session.

async ipinfo(address: int | str | bytes | IPv4Address | IPv6Address) IPInfoResponse

Return ipinfo.io Geolocation Data information on the given IP address.

Parameters

addressIPAddress

The IP Address to query.

Returns

IPInfoResponse

The parsed API response.

Raises

IPInfoError

If any of the following exceptions occurred during the request - (json.JSONDecodeError, aiohttp.ClientError, TypeError, ValueError).

exception aioipinfo.IPInfoError

Bases: Exception

An error in the aioipinfo library.

class aioipinfo.IPInfoResponse(ip: str, hostname: str | None = None, city: str | None = None, region: str | None = None, country: str | None = None, loc: str | None = None, lat: str | None = None, long: str | None = None, org: str | None = None, asn_num: str | None = None, asn_name: str | None = None, postal: str | None = None, timezone: str | None = None)

Bases: object

The response object from an free ipinfo.io GeoLocation Data query.

See ipinfo.io docs for property info.

Exposes a pprint method that dumps the object to stdout.

asn_name: str | None = None
asn_num: str | None = None
city: str | None = None
country: str | None = None
hostname: str | None = None
ip: str
lat: str | None = None
loc: str | None = None
long: str | None = None
org: str | None = None
postal: str | None = None
pprint()

Pretty print this object.

region: str | None = None
timezone: str | None = None
aioipinfo.parse_loc(loc: str) tuple[str, str]

Split a lat,long pair str into a tuple.

Parameters

locstr

The IPInfoResponse.loc to parse.

Returns

tuple[str, str]

The lattitude and longitude respectively parsed from loc.

aioipinfo.parse_org(org: str) tuple[str, str]

Split an “org” in an IPInfoResponse into an ASN and Name.

Parameters

orgstr

The IPInfoResponse.org to parse.

Returns

tuple[str, str]

The ASN Number and ASN Name respectively parsed from org.