Skip to content

module/ipinfo.py

module.ipinfo

IPInfo

IPInfo

Bases: Session

IPInfo

Parameters:

Name Type Description Default
token str

IPInfo's API token.

required

Attributes:

Name Type Description
url str

https://ipinfo.io/

token str

API token.

Note

The headers will update the Authorization in Bearer {self.token}.

Source code in module/ipinfo.py
class IPInfo(Session):
    ''' IPInfo

    Args:
        token (str): IPInfo's API token.

    Attributes:
        url (str): `https://ipinfo.io/`
        token (str): API token.

    Note:
        The `headers` will update the `Authorization` in `Bearer {self.token}`.

    '''

    def __init__(self, token: str):
        super().__init__()
        self.url = 'https://ipinfo.io/'
        self.token = token
        self.headers.update({'Authorization': f'Bearer {self.token}'})

    def get_info(self, ip_address: str) -> Response:
        ''' Get info

        Args:
            ip_address (str): IP address.

        Returns:
            Return the [requests.Response][] object.

        '''
        return super().get(f'{self.url}{ip_address}')

get_info

get_info(ip_address: str) -> Response

Get info

Parameters:

Name Type Description Default
ip_address str

IP address.

required

Returns:

Type Description
Response

Return the requests.Response object.

Source code in module/ipinfo.py
def get_info(self, ip_address: str) -> Response:
    ''' Get info

    Args:
        ip_address (str): IP address.

    Returns:
        Return the [requests.Response][] object.

    '''
    return super().get(f'{self.url}{ip_address}')